@@ -139,11 +139,11 @@ func TestSlack_GetReactions(t *testing.T) {
139139 once .Do (startServer )
140140 api := New ("testing-token" , OptionAPIURL ("http://" + serverAddr + "/" ))
141141 tests := []struct {
142- ref ItemRef
143- params GetReactionsParameters
144- wantParams map [string ]string
145- json string
146- wantReactions [] ItemReaction
142+ ref ItemRef
143+ params GetReactionsParameters
144+ wantParams map [string ]string
145+ json string
146+ wantReactedItem ReactedItem
147147 }{
148148 {
149149 NewRefToMessage ("ChannelID" , "123" ),
@@ -153,24 +153,40 @@ func TestSlack_GetReactions(t *testing.T) {
153153 "timestamp" : "123" ,
154154 },
155155 `{"ok": true,
156- "type": "message",
157- "message": {
158- "reactions": [
159- {
160- "name": "astonished",
161- "count": 3,
162- "users": [ "U1", "U2", "U3" ]
163- },
164- {
165- "name": "clock1",
166- "count": 3,
167- "users": [ "U1", "U2" ]
168- }
169- ]
170- }}` ,
171- []ItemReaction {
172- {Name : "astonished" , Count : 3 , Users : []string {"U1" , "U2" , "U3" }},
173- {Name : "clock1" , Count : 3 , Users : []string {"U1" , "U2" }},
156+ "type": "message",
157+ "message": {
158+ "channel": "ChannelID",
159+ "text": "lorem ipsum dolor sit amet",
160+ "ts": "123",
161+ "user": "U2147483828",
162+ "reactions": [
163+ {
164+ "name": "astonished",
165+ "count": 3,
166+ "users": [ "U1", "U2", "U3" ]
167+ },
168+ {
169+ "name": "clock1",
170+ "count": 3,
171+ "users": [ "U1", "U2" ]
172+ }
173+ ]
174+ }}` ,
175+ ReactedItem {
176+ Item : Item {
177+ Type : "message" , Message : & Message {
178+ Msg : Msg {
179+ Text : "lorem ipsum dolor sit amet" ,
180+ Channel : "ChannelID" ,
181+ User : "U2147483828" ,
182+ Timestamp : "123" ,
183+ },
184+ },
185+ },
186+ Reactions : []ItemReaction {
187+ {Name : "astonished" , Count : 3 , Users : []string {"U1" , "U2" , "U3" }},
188+ {Name : "clock1" , Count : 3 , Users : []string {"U1" , "U2" }},
189+ },
174190 },
175191 },
176192 {
@@ -183,6 +199,19 @@ func TestSlack_GetReactions(t *testing.T) {
183199 `{"ok": true,
184200 "type": "file",
185201 "file": {
202+ "id": "F0A12BCDE",
203+ "created": 1531763342,
204+ "timestamp": 1531763342,
205+ "name": "tedair.gif",
206+ "title": "tedair.gif",
207+ "mimetype": "image/gif",
208+ "filetype": "gif",
209+ "pretty_type": "GIF",
210+ "user": "U012A3BCD",
211+ "editable": false,
212+ "size": 137531,
213+ "mode": "hosted",
214+ "is_external": false,
186215 "reactions": [
187216 {
188217 "name": "astonished",
@@ -196,22 +225,48 @@ func TestSlack_GetReactions(t *testing.T) {
196225 }
197226 ]
198227 }}` ,
199- []ItemReaction {
200- {Name : "astonished" , Count : 3 , Users : []string {"U1" , "U2" , "U3" }},
201- {Name : "clock1" , Count : 3 , Users : []string {"U1" , "U2" }},
228+ ReactedItem {
229+ Item : Item {
230+ Type : "file" , File : & File {
231+ Name : "tedair.gif" ,
232+ ID : "F0A12BCDE" ,
233+ Created : 1531763342 ,
234+ Timestamp : 1531763342 ,
235+ User : "U012A3BCD" ,
236+ Editable : false ,
237+ Size : 137531 ,
238+ },
239+ },
240+ Reactions : []ItemReaction {
241+ {Name : "astonished" , Count : 3 , Users : []string {"U1" , "U2" , "U3" }},
242+ {Name : "clock1" , Count : 3 , Users : []string {"U1" , "U2" }},
243+ },
202244 },
203245 },
204246 {
205-
206247 NewRefToComment ("FileCommentID" ),
207248 GetReactionsParameters {},
208249 map [string ]string {
209250 "file_comment" : "FileCommentID" ,
210251 },
211252 `{"ok": true,
212253 "type": "file_comment",
213- "file": {},
254+ "file": {
255+ "id": "F0A12BCDE",
256+ "created": 1531763342,
257+ "timestamp": 1531763342,
258+ "name": "tedair.gif",
259+ "title": "tedair.gif",
260+ "mimetype": "image/gif",
261+ "filetype": "gif",
262+ "pretty_type": "GIF",
263+ "user": "U012A3BCD",
264+ "editable": false,
265+ "size": 137531,
266+ "is_external": false
267+ },
214268 "comment": {
269+ "comment": "lorem ipsum dolor sit amet comment",
215270 "reactions": [
216271 {
217272 "name": "astonished",
@@ -225,9 +280,19 @@ func TestSlack_GetReactions(t *testing.T) {
225280 }
226281 ]
227282 }}` ,
228- []ItemReaction {
229- {Name : "astonished" , Count : 3 , Users : []string {"U1" , "U2" , "U3" }},
230- {Name : "clock1" , Count : 3 , Users : []string {"U1" , "U2" }},
283+ ReactedItem {
284+ Item : Item {
285+ Type : "file_comment" , File : & File {
286+ Name : "tedair.gif" ,
287+ },
288+ Comment : & Comment {
289+ Comment : "lorem ipsum dolor sit amet comment" ,
290+ },
291+ },
292+ Reactions : []ItemReaction {
293+ {Name : "astonished" , Count : 3 , Users : []string {"U1" , "U2" , "U3" }},
294+ {Name : "clock1" , Count : 3 , Users : []string {"U1" , "U2" }},
295+ },
231296 },
232297 },
233298 }
@@ -240,12 +305,70 @@ func TestSlack_GetReactions(t *testing.T) {
240305 if err != nil {
241306 t .Fatalf ("%d: Unexpected error: %s" , i , err )
242307 }
243- if ! reflect .DeepEqual (got , test .wantReactions ) {
244- t .Errorf ("%d: Got reaction %#v, want %#v" , i , got , test .wantReactions )
308+ if ! reflect .DeepEqual (got . Reactions , test .wantReactedItem . Reactions ) {
309+ t .Errorf ("%d: Got reaction %#v, want %#v" , i , got . Reactions , test .wantReactedItem . Reactions )
245310 }
246311 if ! reflect .DeepEqual (rh .gotParams , test .wantParams ) {
247312 t .Errorf ("%d: Got params %#v, want %#v" , i , rh .gotParams , test .wantParams )
248313 }
314+
315+ switch got .Type {
316+ case "message" :
317+ if got .Message == nil {
318+ t .Fatalf ("%d: Got message %#v, want %#v" , i , got .Message , test .wantReactedItem .Message )
319+ }
320+
321+ if got .Message .Text != test .wantReactedItem .Message .Text {
322+ t .Errorf ("%d: Got message text %#v, want %#v" , i , got .Message .Text , test .wantReactedItem .Message .Text )
323+ }
324+ if got .Message .Channel != test .wantReactedItem .Message .Channel {
325+ t .Errorf ("%d: Got message channel %#v, want %#v" , i , got .Message .Channel , test .wantReactedItem .Message .Channel )
326+ }
327+ if got .Message .User != test .wantReactedItem .Message .User {
328+ t .Errorf ("%d: Got message user %#v, want %#v" , i , got .Message .User , test .wantReactedItem .Message .User )
329+ }
330+ if got .Message .Timestamp != test .wantReactedItem .Message .Timestamp {
331+ t .Errorf ("%d: Got message timestamp %#v, want %#v" , i , got .Message .Timestamp , test .wantReactedItem .Message .Timestamp )
332+ }
333+ case "file" :
334+ if got .File == nil {
335+ t .Fatalf ("%d: Got file %#v, want %#v" , i , got .File , test .wantReactedItem .File )
336+ }
337+ if got .File .Name != test .wantReactedItem .File .Name {
338+ t .Errorf ("%d: Got file name %#v, want %#v" , i , got .File .Name , test .wantReactedItem .File .Name )
339+ }
340+ if got .File .ID != test .wantReactedItem .File .ID {
341+ t .Errorf ("%d: Got file ID %#v, want %#v" , i , got .File .ID , test .wantReactedItem .File .ID )
342+ }
343+ if got .File .Created != test .wantReactedItem .File .Created {
344+ t .Errorf ("%d: Got file created %#v, want %#v" , i , got .File .Created , test .wantReactedItem .File .Created )
345+ }
346+ if got .File .Timestamp != test .wantReactedItem .File .Timestamp {
347+ t .Errorf ("%d: Got file timestamp %#v, want %#v" , i , got .File .Timestamp , test .wantReactedItem .File .Timestamp )
348+ }
349+ if got .File .User != test .wantReactedItem .File .User {
350+ t .Errorf ("%d: Got file user %#v, want %#v" , i , got .File .User , test .wantReactedItem .File .User )
351+ }
352+ if got .File .Editable != test .wantReactedItem .File .Editable {
353+ t .Errorf ("%d: Got file editable %#v, want %#v" , i , got .File .Editable , test .wantReactedItem .File .Editable )
354+ }
355+ if got .File .Size != test .wantReactedItem .File .Size {
356+ t .Errorf ("%d: Got file size %#v, want %#v" , i , got .File .Size , test .wantReactedItem .File .Size )
357+ }
358+ case "file_comment" :
359+ if got .Comment == nil {
360+ t .Fatalf ("%d: Got comment %#v, want %#v" , i , got .Comment , test .wantReactedItem .Comment )
361+ }
362+ if got .File == nil {
363+ t .Fatalf ("%d: Got file %#v, want %#v" , i , got .File , test .wantReactedItem .File )
364+ }
365+ if got .File .Name != test .wantReactedItem .File .Name {
366+ t .Errorf ("%d: Got file name %#v, want %#v" , i , got .File .Name , test .wantReactedItem .File .Name )
367+ }
368+ if got .Comment .Comment != test .wantReactedItem .Comment .Comment {
369+ t .Errorf ("%d: Got comment comment %#v, want %#v" , i , got .Comment .Comment , test .wantReactedItem .Comment .Comment )
370+ }
371+ }
249372 }
250373}
251374
0 commit comments