@@ -37,18 +37,38 @@ 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 = [
55
+ {
56
+ item : user ,
57
+ operation : '+'
58
+ }
59
+ ] ;
60
+ events . handlePlusMinus ( mentions , user , channel ) ;
47
61
expect ( console . log ) . toHaveBeenCalledTimes ( 1 ) ;
48
62
} ) ;
49
63
50
64
it ( 'gets a message from the \'self plus\' collection' , ( ) => {
51
- events . handleSelfPlus ( user , channel ) ;
65
+ const mentions = [
66
+ {
67
+ item : user ,
68
+ operation : '+'
69
+ }
70
+ ] ;
71
+ events . handlePlusMinus ( mentions , user , channel ) ;
52
72
53
73
expect ( messages . getRandomMessage )
54
74
. toHaveBeenCalledTimes ( 1 )
@@ -62,26 +82,19 @@ describe( 'handleSelfPlus', () => {
62
82
slack . sendMessage = jest . fn ( ) ;
63
83
slack . setSlackClient ( slackClientMock ) ;
64
84
65
- events . handleSelfPlus ( user , channel ) ;
85
+ const mentions = [
86
+ {
87
+ item : user ,
88
+ operation : '+'
89
+ }
90
+ ] ;
91
+ events . handlePlusMinus ( mentions , user , channel ) ;
66
92
67
93
expect ( slack . sendMessage )
68
94
. toHaveBeenCalledTimes ( 1 )
69
95
. toHaveBeenCalledWith ( expect . stringContaining ( user ) , channel ) ;
70
96
} ) ;
71
97
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
98
it ( 'calls the score updater to update an item\'s score' , ( ) => {
86
99
const slack = require ( '../src/slack' ) ,
87
100
points = require ( '../src/points' ) ,
@@ -90,11 +103,24 @@ describe( 'handlePlusMinus', () => {
90
103
slack . setSlackClient ( slackClientMock ) ;
91
104
points . updateScore = jest . fn ( ) ;
92
105
93
- events . handlePlusMinus ( item , '+' , channel ) ;
106
+ const operation = '+' ;
107
+ const mentions = [
108
+ {
109
+ item,
110
+ operation
111
+ } ,
112
+ {
113
+ item : item2 ,
114
+ operation
115
+ }
116
+ ] ;
117
+ events . handlePlusMinus ( mentions , user , channel ) . then ( ( ) => {
118
+ expect ( points . updateScore )
119
+ . toHaveBeenCalledTimes ( 2 )
120
+ . toHaveBeenNthCalledWith ( 1 , item , '+' )
121
+ . toHaveBeenNthCalledWith ( 2 , item2 , '+' ) ;
122
+ } ) ;
94
123
95
- expect ( points . updateScore )
96
- . toHaveBeenCalledTimes ( 1 )
97
- . toHaveBeenCalledWith ( item , '+' ) ;
98
124
} ) ;
99
125
100
126
it . each ( [ [ 'plus' , '+' ] , [ 'minus' , '-' ] ] ) (
@@ -111,10 +137,21 @@ describe( 'handlePlusMinus', () => {
111
137
points . updateScore = jest . fn ( updateScoreMock ) ;
112
138
messages . getRandomMessage = jest . fn ( ) ;
113
139
114
- return events . handlePlusMinus ( item , operation , channel ) . then ( ( ) => {
140
+ const mentions = [
141
+ {
142
+ item,
143
+ operation
144
+ } ,
145
+ {
146
+ item : item2 ,
147
+ operation
148
+ }
149
+ ] ;
150
+ return events . handlePlusMinus ( mentions , user , channel ) . then ( ( ) => {
115
151
expect ( messages . getRandomMessage )
116
- . toHaveBeenCalledTimes ( 1 )
117
- . toHaveBeenCalledWith ( operationName , item , score ) ;
152
+ . toHaveBeenCalledTimes ( 2 )
153
+ . toHaveBeenNthCalledWith ( 1 , operationName , item , score )
154
+ . toHaveBeenNthCalledWith ( 2 , operationName , item2 , score ) ;
118
155
} ) ;
119
156
}
120
157
) ;
@@ -130,7 +167,17 @@ describe( 'handlePlusMinus', () => {
130
167
points . updateScore = jest . fn ( ) ;
131
168
slack . sendMessage = jest . fn ( ) ;
132
169
133
- return events . handlePlusMinus ( item , '+' , channel ) . then ( ( ) => {
170
+ const mentions = [
171
+ {
172
+ item,
173
+ operation : '+'
174
+ } ,
175
+ {
176
+ item : item2 ,
177
+ operation : '+'
178
+ }
179
+ ] ;
180
+ return events . handlePlusMinus ( mentions , user , channel ) . then ( ( ) => {
134
181
expect ( slack . sendMessage )
135
182
. toHaveBeenCalledTimes ( 1 )
136
183
. toHaveBeenCalledWith ( expect . stringContaining ( item ) , channel ) ;
@@ -161,16 +208,6 @@ describe( 'handlers.message', () => {
161
208
expect ( handlers . message ( event ) ) . toBeFalse ( ) ;
162
209
} ) ;
163
210
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
211
} ) ; // HandleMessageEvent.
175
212
176
213
describe ( 'handlers.appMention' , ( ) => {
0 commit comments