-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolver_user_test.go
120 lines (106 loc) · 2.92 KB
/
resolver_user_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main_test
import (
"context"
"fmt"
"testing"
graphql "github.com/graph-gophers/graphql-go"
"github.com/graph-gophers/graphql-go/gqltesting"
"piot-server/schema"
)
func TestUsersGet(t *testing.T) {
db := GetDb(t)
CleanDb(t, db)
CreateUser(t, db, "user1@test.com", "")
schema := graphql.MustParseSchema(schema.GetRootSchema(), getResolver(t, db))
gqltesting.RunTests(t, []*gqltesting.Test{
{
Context: context.TODO(),
Schema: schema,
Query: `
{
users { email }
}
`,
ExpectedResult: `
{
"users": [
{
"email": "user1@test.com"
}
]
}
`,
},
})
}
func TestUserGet(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: context.TODO(),
Schema: schema,
Query: fmt.Sprintf(`
{
user(id: "%s") {email, orgs {name}}
}
`, userId.Hex()),
ExpectedResult: `
{
"user": {
"email": "user1@test.com",
"orgs": [{"name": "org1"}, {"name": "org2"}]
}
}
`,
})
}
func TestUserCreate(t *testing.T) {
db := GetDb(t)
CleanDb(t, db)
schema := graphql.MustParseSchema(schema.GetRootSchema(), getResolver(t, db))
gqltesting.RunTest(t, &gqltesting.Test{
Context: context.TODO(),
Schema: schema,
Query: `
mutation {
createUser(email: "user_new@test.com", password: "pwd") { email }
}
`,
ExpectedResult: `
{
"createUser": {
"email": "user_new@test.com"
}
}
`,
})
}
func TestUserUpdate(t *testing.T) {
db := GetDb(t)
CleanDb(t, db)
id := CreateUser(t, db, "user1@test.com", "")
schema := graphql.MustParseSchema(schema.GetRootSchema(), getResolver(t, db))
t.Logf("User to be updated %s", id)
gqltesting.RunTest(t, &gqltesting.Test{
Context: context.TODO(),
Schema: schema,
Query: fmt.Sprintf(`
mutation {
updateUser(user: {id: "%s", email: "user1_new@test.com"}) { email }
}
`, id.Hex()),
ExpectedResult: `
{
"updateUser": {
"email": "user1_new@test.com"
}
}
`,
})
}