forked from winston-stripe/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnd_test.go
154 lines (148 loc) · 4.35 KB
/
dnd_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
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
151
152
153
154
package slack
import (
"net/http"
"reflect"
"testing"
)
func TestSlack_EndDND(t *testing.T) {
http.HandleFunc("/dnd.endDnd", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{ "ok": true }`))
})
once.Do(startServer)
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))
err := api.EndDND()
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
}
func TestSlack_EndSnooze(t *testing.T) {
http.HandleFunc("/dnd.endSnooze", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{ "ok": true,
"dnd_enabled": true,
"next_dnd_start_ts": 1450418400,
"next_dnd_end_ts": 1450454400,
"snooze_enabled": false }`))
})
state := DNDStatus{
Enabled: true,
NextStartTimestamp: 1450418400,
NextEndTimestamp: 1450454400,
SnoozeInfo: SnoozeInfo{SnoozeEnabled: false},
}
once.Do(startServer)
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))
snoozeState, err := api.EndSnooze()
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
eq := reflect.DeepEqual(snoozeState, &state)
if !eq {
t.Errorf("got %v; want %v", snoozeState, &state)
}
}
func TestSlack_GetDNDInfo(t *testing.T) {
http.HandleFunc("/dnd.info", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{
"ok": true,
"dnd_enabled": true,
"next_dnd_start_ts": 1450416600,
"next_dnd_end_ts": 1450452600,
"snooze_enabled": true,
"snooze_endtime": 1450416600,
"snooze_remaining": 1196
}`))
})
userDNDInfo := DNDStatus{
Enabled: true,
NextStartTimestamp: 1450416600,
NextEndTimestamp: 1450452600,
SnoozeInfo: SnoozeInfo{
SnoozeEnabled: true,
SnoozeEndTime: 1450416600,
SnoozeRemaining: 1196,
},
}
once.Do(startServer)
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))
userDNDInfoResponse, err := api.GetDNDInfo(nil)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
eq := reflect.DeepEqual(userDNDInfoResponse, &userDNDInfo)
if !eq {
t.Errorf("got %v; want %v", userDNDInfoResponse, &userDNDInfo)
}
}
func TestSlack_GetDNDTeamInfo(t *testing.T) {
http.HandleFunc("/dnd.teamInfo", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{
"ok": true,
"users": {
"U023BECGF": {
"dnd_enabled": true,
"next_dnd_start_ts": 1450387800,
"next_dnd_end_ts": 1450423800
},
"U058CJVAA": {
"dnd_enabled": false,
"next_dnd_start_ts": 1,
"next_dnd_end_ts": 1
}
}
}`))
})
usersDNDInfo := map[string]DNDStatus{
"U023BECGF": {
Enabled: true,
NextStartTimestamp: 1450387800,
NextEndTimestamp: 1450423800,
},
"U058CJVAA": {
Enabled: false,
NextStartTimestamp: 1,
NextEndTimestamp: 1,
},
}
once.Do(startServer)
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))
usersDNDInfoResponse, err := api.GetDNDTeamInfo(nil)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
eq := reflect.DeepEqual(usersDNDInfoResponse, usersDNDInfo)
if !eq {
t.Errorf("got %v; want %v", usersDNDInfoResponse, usersDNDInfo)
}
}
func TestSlack_SetSnooze(t *testing.T) {
http.HandleFunc("/dnd.setSnooze", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{
"ok": true,
"dnd_enabled": true,
"snooze_endtime": 1450373897,
"snooze_remaining": 60
}`))
})
snooze := DNDStatus{
Enabled: true,
SnoozeInfo: SnoozeInfo{
SnoozeEndTime: 1450373897,
SnoozeRemaining: 60,
},
}
once.Do(startServer)
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))
snoozeResponse, err := api.SetSnooze(60)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
eq := reflect.DeepEqual(snoozeResponse, &snooze)
if !eq {
t.Errorf("got %v; want %v", snoozeResponse, &snooze)
}
}