This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
/
hCreateSession.go
81 lines (72 loc) · 1.6 KB
/
hCreateSession.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
package setup
import (
"time"
"github.com/romshark/dgraph_graphql_go/api/graph/gqlmod"
"github.com/romshark/dgraph_graphql_go/store/errors"
"github.com/stretchr/testify/require"
)
func (h Helper) createSession(
expectedErrorCode errors.Code,
email string,
password string,
) *gqlmod.Session {
t := h.c.t
var result struct {
CreateSession *gqlmod.Session `json:"createSession"`
}
checkErr(t, expectedErrorCode, h.c.QueryVar(
`mutation (
$email: String!
$password: String!
) {
createSession(
email: $email
password: $password,
) {
key
creation
user {
id
email
displayName
creation
}
}
}`,
map[string]interface{}{
"email": email,
"password": password,
},
&result,
))
if expectedErrorCode != "" {
return nil
}
require.NotNil(t, result.CreateSession)
require.True(t, len(*result.CreateSession.Key) > 1)
require.NotNil(t, result.CreateSession.User)
require.Equal(t, email, *result.CreateSession.User.Email)
require.WithinDuration(
t,
time.Now(),
*result.CreateSession.Creation,
h.creationTimeTollerance,
)
return result.CreateSession
}
// CreateSession helps creating a new session and assumes success
func (ok AssumeSuccess) CreateSession(
email string,
password string,
) *gqlmod.Session {
return ok.h.createSession("", email, password)
}
// CreateSession assumes the given error code to be returned
func (notOkay AssumeFailure) CreateSession(
expectedErrorCode errors.Code,
email string,
password string,
) {
notOkay.checkErrCode(expectedErrorCode)
notOkay.h.createSession(expectedErrorCode, email, password)
}