@@ -37,18 +37,28 @@ beforeEach( () => {
37
37
slack . sendMessage . mockClear ( ) ;
38
38
} ) ;
39
39
40
- describe ( 'handleSelfPlus ' , ( ) => {
40
+ describe ( 'handlePlusMinus ' , ( ) => {
41
41
42
42
const user = 'U12345678' ,
43
- channel = 'C12345678' ;
43
+ item = 'SomeRandomThing' ,
44
+ item2 = 'SomeOtherThing' ,
45
+ channel = 'C12345678' ,
46
+ score = 5 ;
47
+
48
+ /** @returns {integer } Returns a fake score. */
49
+ const updateScoreMock = ( ) => {
50
+ return score ;
51
+ } ;
44
52
45
53
it ( 'logs an attempt by a user to increment their own score' , ( ) => {
46
- events . handleSelfPlus ( user , channel ) ;
54
+ const mentions = [ { item : user , operation : '+' } ] ;
55
+ events . handlePlusMinus ( mentions , user , channel ) ;
47
56
expect ( console . log ) . toHaveBeenCalledTimes ( 1 ) ;
48
57
} ) ;
49
58
50
59
it ( 'gets a message from the \'self plus\' collection' , ( ) => {
51
- events . handleSelfPlus ( user , channel ) ;
60
+ const mentions = [ { item : user , operation : '+' } ] ;
61
+ events . handlePlusMinus ( mentions , user , channel ) ;
52
62
53
63
expect ( messages . getRandomMessage )
54
64
. toHaveBeenCalledTimes ( 1 )
@@ -62,26 +72,14 @@ describe( 'handleSelfPlus', () => {
62
72
slack . sendMessage = jest . fn ( ) ;
63
73
slack . setSlackClient ( slackClientMock ) ;
64
74
65
- events . handleSelfPlus ( user , channel ) ;
75
+ const mentions = [ { item : user , operation : '+' } ] ;
76
+ events . handlePlusMinus ( mentions , user , channel ) ;
66
77
67
78
expect ( slack . sendMessage )
68
79
. toHaveBeenCalledTimes ( 1 )
69
80
. toHaveBeenCalledWith ( expect . stringContaining ( user ) , channel ) ;
70
81
} ) ;
71
82
72
- } ) ;
73
-
74
- describe ( 'handlePlusMinus' , ( ) => {
75
-
76
- const item = 'SomeRandomThing' ,
77
- channel = 'C12345678' ,
78
- score = 5 ;
79
-
80
- /** @returns {integer } Returns a fake score. */
81
- const updateScoreMock = ( ) => {
82
- return score ;
83
- } ;
84
-
85
83
it ( 'calls the score updater to update an item\'s score' , ( ) => {
86
84
const slack = require ( '../src/slack' ) ,
87
85
points = require ( '../src/points' ) ,
@@ -90,11 +88,14 @@ describe( 'handlePlusMinus', () => {
90
88
slack . setSlackClient ( slackClientMock ) ;
91
89
points . updateScore = jest . fn ( ) ;
92
90
93
- events . handlePlusMinus ( item , '+' , channel ) ;
91
+ const mentions = [ { item : item , operation : '+' } , { item : item2 , operation : '+' } ] ;
92
+ events . handlePlusMinus ( mentions , user , channel ) . then ( ( ) => {
93
+ expect ( points . updateScore )
94
+ . toHaveBeenCalledTimes ( 2 )
95
+ . toHaveBeenNthCalledWith ( 1 , item , '+' )
96
+ . toHaveBeenNthCalledWith ( 2 , item2 , '+' ) ;
97
+ } ) ;
94
98
95
- expect ( points . updateScore )
96
- . toHaveBeenCalledTimes ( 1 )
97
- . toHaveBeenCalledWith ( item , '+' ) ;
98
99
} ) ;
99
100
100
101
it . each ( [ [ 'plus' , '+' ] , [ 'minus' , '-' ] ] ) (
@@ -111,10 +112,12 @@ describe( 'handlePlusMinus', () => {
111
112
points . updateScore = jest . fn ( updateScoreMock ) ;
112
113
messages . getRandomMessage = jest . fn ( ) ;
113
114
114
- return events . handlePlusMinus ( item , operation , channel ) . then ( ( ) => {
115
+ const mentions = [ { item : item , operation : operation } , { item : item2 , operation : operation } ] ;
116
+ return events . handlePlusMinus ( mentions , user , channel ) . then ( ( ) => {
115
117
expect ( messages . getRandomMessage )
116
- . toHaveBeenCalledTimes ( 1 )
117
- . toHaveBeenCalledWith ( operationName , item , score ) ;
118
+ . toHaveBeenCalledTimes ( 2 )
119
+ . toHaveBeenNthCalledWith ( 1 , operationName , item , score )
120
+ . toHaveBeenNthCalledWith ( 2 , operationName , item2 , score ) ;
118
121
} ) ;
119
122
}
120
123
) ;
@@ -130,7 +133,8 @@ describe( 'handlePlusMinus', () => {
130
133
points . updateScore = jest . fn ( ) ;
131
134
slack . sendMessage = jest . fn ( ) ;
132
135
133
- return events . handlePlusMinus ( item , '+' , channel ) . then ( ( ) => {
136
+ const mentions = [ { item : item , operation : '+' } , { item : item2 , operation : '+' } ]
137
+ return events . handlePlusMinus ( mentions , user , channel ) . then ( ( ) => {
134
138
expect ( slack . sendMessage )
135
139
. toHaveBeenCalledTimes ( 1 )
136
140
. toHaveBeenCalledWith ( expect . stringContaining ( item ) , channel ) ;
@@ -161,16 +165,6 @@ describe( 'handlers.message', () => {
161
165
expect ( handlers . message ( event ) ) . toBeFalse ( ) ;
162
166
} ) ;
163
167
164
- it ( 'returns false if a user trying to ++ themselves' , ( ) => {
165
- const event = {
166
- type : eventType ,
167
- text : '<@U12345678>++' ,
168
- user : 'U12345678'
169
- } ;
170
-
171
- expect ( handlers . message ( event ) ) . toBeFalse ( ) ;
172
- } ) ;
173
-
174
168
} ) ; // HandleMessageEvent.
175
169
176
170
describe ( 'handlers.appMention' , ( ) => {
0 commit comments