forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactions_test.go
85 lines (79 loc) · 2.26 KB
/
interactions_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package slack
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
const (
dialogSubmissionCallback = `{
"type": "dialog_submission",
"submission": {
"name": "Sigourney Dreamweaver",
"email": "[email protected]",
"phone": "+1 800-555-1212",
"meal": "burrito",
"comment": "No sour cream please",
"team_channel": "C0LFFBKPB",
"who_should_sing": "U0MJRG1AL"
},
"callback_id": "employee_offsite_1138b",
"team": {
"id": "T1ABCD2E12",
"domain": "coverbands"
},
"user": {
"id": "W12A3BCDEF",
"name": "dreamweaver"
},
"channel": {
"id": "C1AB2C3DE",
"name": "coverthon-1999"
},
"action_ts": "936893340.702759",
"token": "M1AqUUw3FqayAbqNtsGMch72",
"response_url": "https://hooks.slack.com/app/T012AB0A1/123456789/JpmK0yzoZDeRiqfeduTBYXWQ"
}`
actionCallback = `{}`
)
func assertInteractionCallback(t *testing.T, callback InteractionCallback, encoded string) {
var decoded InteractionCallback
assert.Nil(t, json.Unmarshal([]byte(encoded), &decoded))
assert.Equal(t, decoded, callback)
}
func TestDialogCallback(t *testing.T) {
expected := InteractionCallback{
Type: InteractionTypeDialogSubmission,
Token: "M1AqUUw3FqayAbqNtsGMch72",
CallbackID: "employee_offsite_1138b",
ResponseURL: "https://hooks.slack.com/app/T012AB0A1/123456789/JpmK0yzoZDeRiqfeduTBYXWQ",
ActionTs: "936893340.702759",
Team: Team{ID: "T1ABCD2E12", Name: "", Domain: "coverbands"},
Channel: Channel{
groupConversation: groupConversation{
conversation: conversation{
ID: "C1AB2C3DE",
},
Name: "coverthon-1999",
},
},
User: User{
ID: "W12A3BCDEF",
Name: "dreamweaver",
},
DialogSubmissionCallback: DialogSubmissionCallback{
Submission: map[string]string{
"team_channel": "C0LFFBKPB",
"who_should_sing": "U0MJRG1AL",
"name": "Sigourney Dreamweaver",
"email": "[email protected]",
"phone": "+1 800-555-1212",
"meal": "burrito",
"comment": "No sour cream please",
},
},
}
assertInteractionCallback(t, expected, dialogSubmissionCallback)
}
func TestActionCallback(t *testing.T) {
assertInteractionCallback(t, InteractionCallback{}, actionCallback)
}