forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users_test.go
78 lines (72 loc) · 3.15 KB
/
users_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
package slack
import (
"net/http"
"testing"
)
func getUserIdentity(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-Type", "application/json")
response := []byte(`{
"ok": true,
"user": {
"id": "UXXXXXXXX",
"name": "Test User",
"email": "[email protected]",
"image_24": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_24.jpg",
"image_32": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_32.jpg",
"image_48": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_48.jpg",
"image_72": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_72.jpg",
"image_192": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_192.jpg",
"image_512": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_512.jpg"
},
"team": {
"id": "TXXXXXXXX",
"name": "team-name",
"domain": "team-domain",
"image_34": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_34.jpg",
"image_44": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_44.jpg",
"image_68": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_68.jpg",
"image_88": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_88.jpg",
"image_102": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_102.jpg",
"image_132": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_132.jpg",
"image_230": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_230.jpg",
"image_original": "https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-10-18\/92962080834_ef14c1469fc0741caea1_original.jpg"
}
}`)
rw.Write(response)
}
func TestGetUserIdentity(t *testing.T) {
http.HandleFunc("/users.identity", getUserIdentity)
once.Do(startServer)
SLACK_API = "http://" + serverAddr + "/"
api := New("testing-token")
identity, err := api.GetUserIdentity()
if err != nil {
t.Errorf("Unexpected error: %s", err)
return
}
// t.Fatal refers to -> t.Errorf & return
if identity.User.ID != "UXXXXXXXX" {
t.Fatal(ErrIncorrectResponse)
}
if identity.User.Name != "Test User" {
t.Fatal(ErrIncorrectResponse)
}
if identity.User.Email != "[email protected]" {
t.Fatal(ErrIncorrectResponse)
}
if identity.Team.ID != "TXXXXXXXX" {
t.Fatal(ErrIncorrectResponse)
}
if identity.Team.Name != "team-name" {
t.Fatal(ErrIncorrectResponse)
}
if identity.Team.Domain != "team-domain" {
t.Fatal(ErrIncorrectResponse)
}
if identity.User.Image24 == "" {
t.Fatal(ErrIncorrectResponse)
}
if identity.Team.Image34 == "" {
t.Fatal(ErrIncorrectResponse)
}
}