-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolver_userprofile_test.go
90 lines (81 loc) · 2.29 KB
/
resolver_userprofile_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
package main_test
import (
"fmt"
"piot-server/schema"
"testing"
graphql "github.com/graph-gophers/graphql-go"
"github.com/graph-gophers/graphql-go/gqltesting"
)
func TestUserProfile(t *testing.T) {
db := GetDb(t)
CleanDb(t, db)
orgId := CreateOrg(t, db, "org1")
org2Id := CreateOrg(t, db, "org2")
userId := CreateUser(t, db, "user1@test.com", "")
AddOrgUser(t, db, orgId, userId)
AddOrgUser(t, db, org2Id, userId)
schema := graphql.MustParseSchema(schema.GetRootSchema(), getResolver(t, db))
gqltesting.RunTest(t, &gqltesting.Test{
Context: AuthContext(t, userId, orgId),
Schema: schema,
Query: `
{
userProfile() {email, org_id, is_admin, orgs {name}}
}
`,
ExpectedResult: fmt.Sprintf(`
{
"userProfile": {
"email": "user1@test.com",
"org_id": "%s",
"is_admin": false,
"orgs": [{"name": "org1"}, {"name": "org2"}]
}
}
`, orgId.Hex()),
})
}
func TestUserProfileUpdate(t *testing.T) {
db := GetDb(t)
CleanDb(t, db)
orgId := CreateOrg(t, db, "org1")
org2Id := CreateOrg(t, db, "org2")
userId := CreateUser(t, db, "user1@test.com", "")
AddOrgUser(t, db, orgId, userId)
AddOrgUser(t, db, org2Id, userId)
schema := graphql.MustParseSchema(schema.GetRootSchema(), getResolver(t, db))
// set second org as active
gqltesting.RunTest(t, &gqltesting.Test{
Context: AuthContext(t, userId, orgId),
Schema: schema,
Query: fmt.Sprintf(`
mutation {
updateUserProfile(profile: {org_id: "%s"}) {org_id}
}
`, org2Id.Hex()),
ExpectedResult: fmt.Sprintf(`
{
"updateUserProfile": {
"org_id": "%s"
}
}
`, org2Id.Hex()),
})
// set first org as active
gqltesting.RunTest(t, &gqltesting.Test{
Context: AuthContext(t, userId, orgId),
Schema: schema,
Query: fmt.Sprintf(`
mutation {
updateUserProfile(profile: {org_id: "%s"}) {org_id}
}
`, orgId.Hex()),
ExpectedResult: fmt.Sprintf(`
{
"updateUserProfile": {
"org_id": "%s"
}
}
`, orgId.Hex()),
})
}