This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
/
org_users_test.go
92 lines (71 loc) · 1.91 KB
/
org_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
getOrgUsersJSON = `[{"orgID":1,"userID":1,"email":"admin@localhost","avatarUrl":"/avatar/46d229b033af06a191ff2267bca9ae56","login":"admin","role":"Admin","lastSeenAt":"2018-06-28T14:16:11Z","lastSeenAtAge":"\u003c 1m"}]`
addOrgUserJSON = `{"message":"User added to organization"}`
updateOrgUserJSON = `{"message":"Organization user updated"}`
removeOrgUserJSON = `{"message":"User removed from organization"}`
)
func TestOrgUsersCurrent(t *testing.T) {
client := gapiTestTools(t, 200, getOrgUsersJSON)
resp, err := client.OrgUsersCurrent()
if err != nil {
t.Fatal(err)
}
user := OrgUser{
OrgID: 1,
UserID: 1,
Email: "admin@localhost",
Login: "admin",
Role: "Admin",
}
if resp[0] != user {
t.Error("Not correctly parsing returned organization users.")
}
}
func TestOrgUsers(t *testing.T) {
client := gapiTestTools(t, 200, getOrgUsersJSON)
org := int64(1)
resp, err := client.OrgUsers(org)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
user := OrgUser{
OrgID: 1,
UserID: 1,
Email: "admin@localhost",
Login: "admin",
Role: "Admin",
}
if resp[0] != user {
t.Error("Not correctly parsing returned organization users.")
}
}
func TestAddOrgUser(t *testing.T) {
client := gapiTestTools(t, 200, addOrgUserJSON)
orgID, user, role := int64(1), "admin@localhost", "Admin"
err := client.AddOrgUser(orgID, user, role)
if err != nil {
t.Fatal(err)
}
}
func TestUpdateOrgUser(t *testing.T) {
client := gapiTestTools(t, 200, updateOrgUserJSON)
orgID, userID, role := int64(1), int64(1), "Editor"
err := client.UpdateOrgUser(orgID, userID, role)
if err != nil {
t.Fatal(err)
}
}
func TestRemoveOrgUser(t *testing.T) {
client := gapiTestTools(t, 200, removeOrgUserJSON)
orgID, userID := int64(1), int64(1)
err := client.RemoveOrgUser(orgID, userID)
if err != nil {
t.Error(err)
}
}