-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathinvitations_test.go
52 lines (44 loc) · 1.29 KB
/
invitations_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
package mackerel
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestFindInvitation(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/api/v0/invitations" {
t.Error("request URL should be but: ", req.URL.Path)
}
if req.Method != "GET" {
t.Error("request method should be GET but: ", req.Method)
}
respJSON, _ := json.Marshal(map[string][]map[string]interface{}{
"invitations": {
{
"email": "[email protected]",
"authority": "viewer",
"expiresAt": 1560000000,
},
},
})
res.Header()["Content-Type"] = []string{"application/json"}
fmt.Fprint(res, string(respJSON))
}))
defer ts.Close()
client, _ := NewClientWithOptions("dummy-key", ts.URL, false)
invitations, err := client.FindInvitations()
if err != nil {
t.Error("err should be nil but: ", err)
}
if invitations[0].Email != "[email protected]" {
t.Error("request sends json including email but: ", invitations[0].Email)
}
if invitations[0].Authority != "viewer" {
t.Error("request sends json including authority but: ", invitations[0].Authority)
}
if invitations[0].ExpiresAt != 1560000000 {
t.Error("request sends json including joinedAt but: ", invitations[0].ExpiresAt)
}
}