@@ -11,19 +11,46 @@ const sample = {
1111 userName : 'Ricky' ,
1212}
1313
14- const tickets = {
15- '1' : {
16- assignee : null ,
17- closed : null ,
18- content : 'content' ,
19- id : 1 ,
20- requester : 'Ricky' ,
21- roomName : 'MyRoom' ,
22- status : 'open' ,
23- } ,
24- lastId : 1 ,
14+ function oneTicket ( ) {
15+ return {
16+ '1' : {
17+ assignee : null ,
18+ closed : null ,
19+ content : 'content' ,
20+ id : '1' ,
21+ requester : 'Ricky' ,
22+ roomName : 'MyRoom' ,
23+ status : 'open' ,
24+ } ,
25+ lastId : 1 ,
26+ }
2527}
2628
29+ function twoTickets ( ) {
30+ return {
31+ '1' : {
32+ assignee : null ,
33+ closed : null ,
34+ content : 'content' ,
35+ id : '1' ,
36+ requester : 'Ricky' ,
37+ roomName : 'MyRoom' ,
38+ status : 'open' ,
39+ } ,
40+ '2' : {
41+ assignee : null ,
42+ closed : null ,
43+ content : 'content' ,
44+ id : '2' ,
45+ requester : 'Dmitry' ,
46+ roomName : 'MyRoom' ,
47+ status : 'open' ,
48+ } ,
49+ lastId : 2 ,
50+ }
51+ }
52+
53+
2754function copy ( sampleObject ) {
2855 return JSON . parse ( JSON . stringify ( sampleObject ) )
2956}
@@ -34,52 +61,72 @@ function message(content) {
3461 return msg
3562}
3663
64+ /* eslint-disable no-sync */
3765const TEST_FILE = tmp . fileSync ( ) . name
3866
3967describe ( 'support' , function ( ) {
4068 it ( 'ping' , function ( ) {
41- const reply = support . process ( tickets , message ( '' ) )
69+ const reply = support . process ( oneTicket ( ) , message ( '' ) )
4270 assert . equal ( reply , '#candra: Yes Ricky?' )
4371 } )
4472
4573 it ( 'close' , function ( ) {
46- const reply = support . process ( tickets , message ( 'close #1' ) )
74+ const reply = support . process ( oneTicket ( ) , message ( 'close #1' ) )
4775 assert . equal ( reply , '#candra: ticket #1 is closed' )
4876 } )
4977
5078 it ( 'debug' , function ( ) {
79+ const tickets = oneTicket ( )
5180 const reply = support . process ( tickets , message ( 'debug' ) )
5281 assert . deepEqual ( JSON . parse ( reply . slice ( '#candra: ' . length ) ) , tickets )
5382 } )
5483
5584 it ( 'invalid' , function ( ) {
56- const reply = support . process ( tickets , message ( 'handsome' ) )
85+ const reply = support . process ( oneTicket ( ) , message ( 'handsome' ) )
5786 assert . equal ( reply , '#candra: I don\'t understand: handsome, can you try again?' )
5887 } )
5988
6089 it ( 'help' , function ( ) {
61- const reply = support . process ( tickets , message ( 'help' ) )
90+ const reply = support . process ( oneTicket ( ) , message ( 'help' ) )
6291 assert . isTrue ( reply . indexOf ( 'please' ) != - 1 )
6392 } )
6493
6594 it ( 'forget it' , function ( ) {
95+ const tickets = oneTicket ( )
6696 const reply = support . process ( tickets , message ( 'forget it' ) )
6797 assert . equal ( reply , '#candra: deleted 1 tickets' )
6898 assert . equal ( tickets . lastId , 0 )
6999 } )
70100
71101 it ( 'gimme a compliment' , function ( ) {
72- const reply = support . process ( tickets , message ( 'gimme a compliment' ) )
73- assert . match ( reply , / [ \. ! \? ] $ / )
102+ const reply = support . process ( { } , message ( 'gimme a compliment' ) )
103+ assert . match ( reply , / [ \. ! ? ) ] $ / )
74104 } )
75105
76106 it ( 'gimme something that does not exist' , function ( ) {
77- const reply = support . process ( tickets , message ( 'gimme a unknown' ) )
107+ const reply = support . process ( { } , message ( 'gimme a unknown' ) )
78108 assert . equal ( reply , "I don't know how to give you unknown!" )
79109 } )
80110
81111 it ( 'load and store working' , function ( ) {
82112 support . store ( TEST_FILE , { var : 4 } )
83113 assert . equal ( support . load ( TEST_FILE ) . var , 4 )
84114 } )
115+
116+ it ( 'TODO empty' , function ( ) {
117+ const reply = support . process ( { } , message ( 'todo' ) )
118+ assert . equal ( reply , '#candra: nothing TODO!' )
119+ } )
120+
121+ it ( 'TODO with ticket specific mine' , function ( ) {
122+ const reply = support . process ( twoTickets ( ) , message ( 'mine' ) )
123+ assert . match ( reply , / t i c k e t # 1 / )
124+ assert . notMatch ( reply , / t i c k e t # 2 / )
125+ } )
126+
127+ it ( 'TODO with ticket specific other user' , function ( ) {
128+ const reply = support . process ( twoTickets ( ) , message ( 'TODO dmitry' ) )
129+ assert . notMatch ( reply , / t i c k e t # 1 / )
130+ assert . match ( reply , / t i c k e t # 2 / )
131+ } )
85132} )
0 commit comments