This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
/
hCreateReaction.go
103 lines (94 loc) · 2.03 KB
/
hCreateReaction.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
package setup
import (
"time"
"github.com/romshark/dgraph_graphql_go/api/graph/gqlmod"
"github.com/romshark/dgraph_graphql_go/store"
"github.com/romshark/dgraph_graphql_go/store/enum/emotion"
"github.com/romshark/dgraph_graphql_go/store/errors"
"github.com/stretchr/testify/require"
)
func (h Helper) createReaction(
expectedErrorCode errors.Code,
author store.ID,
subject store.ID,
emotion emotion.Emotion,
message string,
) *gqlmod.Reaction {
t := h.c.t
var result struct {
CreateReaction *gqlmod.Reaction `json:"createReaction"`
}
checkErr(t, expectedErrorCode, h.c.QueryVar(
`mutation (
$author: Identifier!
$subject: Identifier!
$emotion: Emotion!
$message: String!
) {
createReaction(
author: $author
subject: $subject
emotion: $emotion
message: $message
) {
id
creation
message
emotion
}
}`,
map[string]interface{}{
"author": string(author),
"subject": string(subject),
"emotion": string(emotion),
"message": message,
},
&result,
))
if expectedErrorCode != "" {
return nil
}
require.NotNil(t, result.CreateReaction)
require.Len(t, *result.CreateReaction.ID, 32)
require.Equal(t, emotion, *result.CreateReaction.Emotion)
require.Equal(t, message, *result.CreateReaction.Message)
require.WithinDuration(
t,
time.Now(),
*result.CreateReaction.Creation,
h.creationTimeTollerance,
)
return result.CreateReaction
}
// CreateReaction helps creating a reaction and assumes success
func (ok AssumeSuccess) CreateReaction(
author store.ID,
subject store.ID,
emotion emotion.Emotion,
message string,
) *gqlmod.Reaction {
return ok.h.createReaction(
"",
author,
subject,
emotion,
message,
)
}
// CreateReaction assumes the given error code to be returned
func (notOk AssumeFailure) CreateReaction(
expectedErrorCode errors.Code,
author store.ID,
subject store.ID,
emotion emotion.Emotion,
message string,
) {
notOk.checkErrCode(expectedErrorCode)
notOk.h.createReaction(
expectedErrorCode,
author,
subject,
emotion,
message,
)
}