This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
/
hEditUser.go
119 lines (110 loc) · 2.28 KB
/
hEditUser.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
package setup
import (
"github.com/romshark/dgraph_graphql_go/api/graph/gqlmod"
"github.com/romshark/dgraph_graphql_go/store"
"github.com/romshark/dgraph_graphql_go/store/errors"
"github.com/stretchr/testify/require"
)
func (h Helper) editUser(
expectedErrorCode errors.Code,
userID store.ID,
editorID store.ID,
newEmail *string,
newPassword *string,
) *gqlmod.User {
t := h.c.t
var old struct {
User *gqlmod.User `json:"user"`
}
require.NoError(t, h.ts.Debug().QueryVar(
`query($userID: Identifier!) {
user(id: $userID) {
id
creation
displayName
email
}
}`,
map[string]interface{}{
"userID": string(userID),
},
&old,
))
var result struct {
EditUser *gqlmod.User `json:"editUser"`
}
checkErr(t, expectedErrorCode, h.c.QueryVar(
`mutation (
$user: Identifier!
$editor: Identifier!
$newEmail: String
$newPassword: String
) {
editUser(
user: $user
editor: $editor
newEmail: $newEmail
newPassword: $newPassword
) {
id
creation
displayName
email
}
}`,
map[string]interface{}{
"user": string(userID),
"editor": string(editorID),
"newEmail": newEmail,
"newPassword": newPassword,
},
&result,
))
if expectedErrorCode != "" {
return nil
}
require.NotNil(t, result.EditUser)
if old.User != nil {
require.Equal(t, *old.User.ID, *result.EditUser.ID)
if newEmail != nil {
require.Equal(t, *newEmail, *result.EditUser.Email)
} else {
require.Equal(t, *old.User.Email, *result.EditUser.Email)
}
require.Equal(t, *old.User.DisplayName, *result.EditUser.DisplayName)
require.Equal(t, *old.User.Creation, *result.EditUser.Creation)
}
return result.EditUser
}
// EditUser helps editing a user and assumes success
func (ok AssumeSuccess) EditUser(
userID store.ID,
editorID store.ID,
newEmail *string,
newPassword *string,
) *gqlmod.User {
return ok.h.editUser(
"",
userID,
editorID,
newEmail,
newPassword,
)
}
// EditUser assumes the given error code to be returned
func (notOk AssumeFailure) EditUser(
expectedErrorCode errors.Code,
userID store.ID,
editorID store.ID,
newEmail *string,
newPassword *string,
) {
notOk.checkErrCode(expectedErrorCode)
notOk.h.editUser(
expectedErrorCode,
userID,
editorID,
newEmail,
newPassword,
)
}