-
Notifications
You must be signed in to change notification settings - Fork 2
/
sendbirdclient_test.go
72 lines (61 loc) · 1.8 KB
/
sendbirdclient_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
package sendbird
import (
"net/http"
"net/http/httptest"
"net/url"
"reflect"
"testing"
)
var (
mux *http.ServeMux
client *SendbirdClient
server *httptest.Server
)
const TestApiToken = "API_TOKEN_1"
func setup() {
mux = http.NewServeMux()
server = httptest.NewServer(mux)
client = NewClient("SENDBIRD_API_TOKEN", "SENDBIRD_APP_ID", nil)
url, _ := url.Parse(server.URL)
client.BaseURL = url
}
func teardown() {
server.Close()
}
func testMethod(t *testing.T, r *http.Request, expected string) {
if expected != r.Method {
t.Errorf("Request method = %v, expected %v", r.Method, expected)
}
}
func TestNewClient(t *testing.T) {
c := NewClient("SENDBIRD_API_TOKEN", "SENDBIRD_APP_ID", nil)
if c.BaseURL.String() != defaultBaseURL {
t.Errorf("NewClient BaseURL = %v, expected %v", c.BaseURL.String(), defaultBaseURL)
}
}
func CheckForAuthContentType(t *testing.T, r *http.Request) {
contentType := r.Header.Get("Content-Type")
if contentType != "application/json, charset=utf8" {
t.Errorf("Content-Type Request Header should be set to \"application/json, charset=utf8\"")
}
}
func CheckForAuthParam(t *testing.T, r *http.Request, d interface{}) {
auth := reflect.ValueOf(d).FieldByName("Auth").String()
if auth == "" {
t.Errorf("Required request parameter of Auth not populated")
}
}
func CheckForV2ApiTokenParam(t *testing.T, r *http.Request, d interface{}) {
api_token := reflect.ValueOf(d).FieldByName("api_token").String()
if api_token == "" {
t.Errorf("Required request parameter of api_token not populated")
}
}
func CheckForV2ApiTokenQueryString(t *testing.T, r *http.Request) {
if err := r.ParseForm(); err != nil {
t.Errorf("Bot.Get - Unable to parse querystring", err)
}
if r.Form.Get("api_token") == "" {
t.Errorf("Required querystring parameter of api_token not populated")
}
}