7 | 7 |
)
|
8 | 8 |
|
9 | 9 |
func init() {
|
10 | |
http.HandleFunc("/reactions.add", addReactionHandler)
|
|
10 |
http.HandleFunc("/reactions.add", reactionHandler)
|
|
11 |
http.HandleFunc("/reactions.remove", reactionHandler)
|
11 | 12 |
http.HandleFunc("/reactions.get", getReactionHandler)
|
12 | 13 |
http.HandleFunc("/reactions.list", listReactionHandler)
|
13 | 14 |
}
|
|
24 | 25 |
}
|
25 | 26 |
}
|
26 | 27 |
|
27 | |
func addReactionHandler(w http.ResponseWriter, r *http.Request) {
|
|
28 |
func reactionHandler(w http.ResponseWriter, r *http.Request) {
|
28 | 29 |
accumulateFormValue("name", r)
|
|
30 |
accumulateFormValue("channel", r)
|
|
31 |
accumulateFormValue("timestamp", r)
|
29 | 32 |
accumulateFormValue("file", r)
|
30 | 33 |
accumulateFormValue("file_comment", r)
|
|
34 |
w.Header().Set("Content-Type", "application/json")
|
|
35 |
w.Write([]byte(`{ "ok": true }`))
|
|
36 |
}
|
|
37 |
|
|
38 |
func getReactionHandler(w http.ResponseWriter, r *http.Request) {
|
31 | 39 |
accumulateFormValue("channel", r)
|
32 | 40 |
accumulateFormValue("timestamp", r)
|
33 | |
w.Header().Set("Content-Type", "application/json")
|
34 | |
w.Write([]byte(`{ "ok": true }`))
|
35 | |
}
|
36 | |
|
37 | |
func getReactionHandler(w http.ResponseWriter, r *http.Request) {
|
38 | 41 |
accumulateFormValue("file", r)
|
39 | 42 |
accumulateFormValue("file_comment", r)
|
40 | |
accumulateFormValue("channel", r)
|
41 | |
accumulateFormValue("timestamp", r)
|
42 | 43 |
accumulateFormValue("full", r)
|
43 | 44 |
w.Header().Set("Content-Type", "application/json")
|
44 | 45 |
w.Write([]byte(getReactionRes))
|
|
53 | 54 |
w.Write([]byte(listReactionRes))
|
54 | 55 |
}
|
55 | 56 |
|
56 | |
func TestSlack_AddReaction_ToMessage(t *testing.T) {
|
57 | |
once.Do(startServer)
|
58 | |
SLACK_API = "http://" + serverAddr + "/"
|
59 | |
api := New("testing-token")
|
60 | |
wantParams := map[string]string{
|
61 | |
"name": "thumbsup",
|
62 | |
"channel": "ChannelID",
|
63 | |
"timestamp": "123",
|
64 | |
}
|
65 | |
gotParams = map[string]string{}
|
66 | |
params := NewAddReactionParameters("thumbsup", NewRefToMessage("ChannelID", "123"))
|
67 | |
err := api.AddReaction(params)
|
68 | |
if err != nil {
|
69 | |
t.Fatalf("Unexpected error: %s", err)
|
70 | |
}
|
71 | |
if !reflect.DeepEqual(gotParams, wantParams) {
|
72 | |
t.Errorf("Got params %#v, want %#v", gotParams, wantParams)
|
73 | |
}
|
74 | |
}
|
75 | |
|
76 | |
func TestSlack_AddReaction_ToFile(t *testing.T) {
|
77 | |
once.Do(startServer)
|
78 | |
SLACK_API = "http://" + serverAddr + "/"
|
79 | |
api := New("testing-token")
|
80 | |
wantParams := map[string]string{
|
81 | |
"name": "thumbsup",
|
82 | |
"file": "FileID",
|
83 | |
}
|
84 | |
gotParams = map[string]string{}
|
85 | |
params := NewAddReactionParameters("thumbsup", NewRefToFile("FileID"))
|
86 | |
err := api.AddReaction(params)
|
87 | |
if err != nil {
|
88 | |
t.Fatalf("Unexpected error: %s", err)
|
89 | |
}
|
90 | |
if !reflect.DeepEqual(gotParams, wantParams) {
|
91 | |
t.Errorf("Got params %#v, want %#v", gotParams, wantParams)
|
92 | |
}
|
93 | |
}
|
94 | |
|
95 | |
func TestSlack_AddReaction_ToFileComment(t *testing.T) {
|
96 | |
once.Do(startServer)
|
97 | |
SLACK_API = "http://" + serverAddr + "/"
|
98 | |
api := New("testing-token")
|
99 | |
wantParams := map[string]string{
|
100 | |
"name": "thumbsup",
|
101 | |
"file_comment": "FileCommentID",
|
102 | |
}
|
103 | |
gotParams = map[string]string{}
|
104 | |
params := NewAddReactionParameters("thumbsup", NewRefToFileComment("FileCommentID"))
|
105 | |
err := api.AddReaction(params)
|
106 | |
if err != nil {
|
107 | |
t.Fatalf("Unexpected error: %s", err)
|
108 | |
}
|
109 | |
if !reflect.DeepEqual(gotParams, wantParams) {
|
110 | |
t.Errorf("Got params %#v, want %#v", gotParams, wantParams)
|
|
57 |
func TestSlack_AddReaction(t *testing.T) {
|
|
58 |
once.Do(startServer)
|
|
59 |
SLACK_API = "http://" + serverAddr + "/"
|
|
60 |
api := New("testing-token")
|
|
61 |
tests := []struct {
|
|
62 |
params AddReactionParameters
|
|
63 |
wantParams map[string]string
|
|
64 |
}{
|
|
65 |
{
|
|
66 |
NewAddReactionParameters("thumbsup", NewRefToMessage("ChannelID", "123")),
|
|
67 |
map[string]string{
|
|
68 |
"name": "thumbsup",
|
|
69 |
"channel": "ChannelID",
|
|
70 |
"timestamp": "123",
|
|
71 |
},
|
|
72 |
},
|
|
73 |
{
|
|
74 |
NewAddReactionParameters("thumbsup", NewRefToFile("FileID")),
|
|
75 |
map[string]string{
|
|
76 |
"name": "thumbsup",
|
|
77 |
"file": "FileID",
|
|
78 |
},
|
|
79 |
},
|
|
80 |
{
|
|
81 |
NewAddReactionParameters("thumbsup", NewRefToFileComment("FileCommentID")),
|
|
82 |
map[string]string{
|
|
83 |
"name": "thumbsup",
|
|
84 |
"file_comment": "FileCommentID",
|
|
85 |
},
|
|
86 |
},
|
|
87 |
}
|
|
88 |
for i, test := range tests {
|
|
89 |
gotParams = map[string]string{}
|
|
90 |
err := api.AddReaction(test.params)
|
|
91 |
if err != nil {
|
|
92 |
t.Fatalf("%d: Unexpected error: %s", i, err)
|
|
93 |
}
|
|
94 |
if !reflect.DeepEqual(gotParams, test.wantParams) {
|
|
95 |
t.Errorf("%d: Got params %#v, want %#v", i, gotParams, test.wantParams)
|
|
96 |
}
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
func TestSlack_RemoveReaction(t *testing.T) {
|
|
101 |
once.Do(startServer)
|
|
102 |
SLACK_API = "http://" + serverAddr + "/"
|
|
103 |
api := New("testing-token")
|
|
104 |
tests := []struct {
|
|
105 |
params RemoveReactionParameters
|
|
106 |
wantParams map[string]string
|
|
107 |
}{
|
|
108 |
{
|
|
109 |
NewRemoveReactionParameters("thumbsup", NewRefToMessage("ChannelID", "123")),
|
|
110 |
map[string]string{
|
|
111 |
"name": "thumbsup",
|
|
112 |
"channel": "ChannelID",
|
|
113 |
"timestamp": "123",
|
|
114 |
},
|
|
115 |
},
|
|
116 |
{
|
|
117 |
NewRemoveReactionParameters("thumbsup", NewRefToFile("FileID")),
|
|
118 |
map[string]string{
|
|
119 |
"name": "thumbsup",
|
|
120 |
"file": "FileID",
|
|
121 |
},
|
|
122 |
},
|
|
123 |
{
|
|
124 |
NewRemoveReactionParameters("thumbsup", NewRefToFileComment("FileCommentID")),
|
|
125 |
map[string]string{
|
|
126 |
"name": "thumbsup",
|
|
127 |
"file_comment": "FileCommentID",
|
|
128 |
},
|
|
129 |
},
|
|
130 |
}
|
|
131 |
for i, test := range tests {
|
|
132 |
gotParams = map[string]string{}
|
|
133 |
err := api.RemoveReaction(test.params)
|
|
134 |
if err != nil {
|
|
135 |
t.Fatalf("%d: Unexpected error: %s", i, err)
|
|
136 |
}
|
|
137 |
if !reflect.DeepEqual(gotParams, test.wantParams) {
|
|
138 |
t.Errorf("%d: Got params %#v, want %#v", i, gotParams, test.wantParams)
|
|
139 |
}
|
111 | 140 |
}
|
112 | 141 |
}
|
113 | 142 |
|