This repository was archived by the owner on Jun 28, 2025. It is now read-only.
forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinteractions_test.go
More file actions
150 lines (140 loc) · 4.88 KB
/
interactions_test.go
File metadata and controls
150 lines (140 loc) · 4.88 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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)
}
func TestInteractionCallbackJSONMarshalAndUnmarshal(t *testing.T) {
cb := &InteractionCallback{
Type: InteractionTypeBlockActions,
Token: "token",
CallbackID: "",
ResponseURL: "responseURL",
TriggerID: "triggerID",
ActionTs: "actionTS",
Team: Team{ID: "teamid", Name: "teamname"},
Channel: Channel{GroupConversation: GroupConversation{
Name: "channelname", Conversation: Conversation{ID: "channelid"}}},
User: User{ID: "userid", Name: "username",
Profile: UserProfile{RealName: "userrealname"}},
OriginalMessage: Message{Msg: Msg{Text: "ogmsg text",
Timestamp: "ogmsg ts"}},
Message: Message{Msg: Msg{Text: "text", Timestamp: "ts"}},
Name: "name",
Value: "value",
MessageTs: "messageTs",
AttachmentID: "attachmentID",
ActionCallback: ActionCallbacks{
AttachmentActions: []*AttachmentAction{{Value: "value"}},
BlockActions: []*BlockAction{{ActionID: "id123"}},
},
DialogSubmissionCallback: DialogSubmissionCallback{State: "dsstate"},
}
cbJSONBytes, err := json.Marshal(cb)
assert.NoError(t, err)
jsonCB := new(InteractionCallback)
err = json.Unmarshal(cbJSONBytes, jsonCB)
assert.NoError(t, err)
assert.Equal(t, cb.Type, jsonCB.Type)
assert.Equal(t, cb.Token, jsonCB.Token)
assert.Equal(t, cb.CallbackID, jsonCB.CallbackID)
assert.Equal(t, cb.ResponseURL, jsonCB.ResponseURL)
assert.Equal(t, cb.TriggerID, jsonCB.TriggerID)
assert.Equal(t, cb.ActionTs, jsonCB.ActionTs)
assert.Equal(t, cb.Team.ID, jsonCB.Team.ID)
assert.Equal(t, cb.Team.Name, jsonCB.Team.Name)
assert.Equal(t, cb.Channel.ID, jsonCB.Channel.ID)
assert.Equal(t, cb.Channel.Name, jsonCB.Channel.Name)
assert.Equal(t, cb.Channel.Created, jsonCB.Channel.Created)
assert.Equal(t, cb.User.ID, jsonCB.User.ID)
assert.Equal(t, cb.User.Name, jsonCB.User.Name)
assert.Equal(t, cb.User.Profile.RealName, jsonCB.User.Profile.RealName)
assert.Equal(t, cb.OriginalMessage.Text, jsonCB.OriginalMessage.Text)
assert.Equal(t, cb.OriginalMessage.Timestamp,
jsonCB.OriginalMessage.Timestamp)
assert.Equal(t, cb.Message.Text, jsonCB.Message.Text)
assert.Equal(t, cb.Message.Timestamp, jsonCB.Message.Timestamp)
assert.Equal(t, cb.Name, jsonCB.Name)
assert.Equal(t, cb.Value, jsonCB.Value)
assert.Equal(t, cb.MessageTs, jsonCB.MessageTs)
assert.Equal(t, cb.AttachmentID, jsonCB.AttachmentID)
assert.Equal(t, len(cb.ActionCallback.AttachmentActions),
len(jsonCB.ActionCallback.AttachmentActions))
assert.Equal(t, len(cb.ActionCallback.BlockActions),
len(jsonCB.ActionCallback.BlockActions))
assert.Equal(t, cb.DialogSubmissionCallback.State,
jsonCB.DialogSubmissionCallback.State)
}