This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
hEditReaction.go
137 lines (128 loc) · 2.59 KB
/
hEditReaction.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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) editReaction(
expectedErrorCode errors.Code,
reactionID store.ID,
editorID store.ID,
newMessage string,
) *gqlmod.Reaction {
t := h.c.t
var old struct {
Reaction *gqlmod.Reaction `json:"reaction"`
}
require.NoError(t, h.ts.Debug().QueryVar(
`query($reactionID: Identifier!) {
reaction(id: $reactionID) {
id
emotion
message
creation
author {
id
}
subject {
__typename
... on Post {
id
}
... on Reaction {
id
}
}
}
}`,
map[string]interface{}{
"reactionID": string(reactionID),
},
&old,
))
var result struct {
EditReaction *gqlmod.Reaction `json:"editReaction"`
}
checkErr(t, expectedErrorCode, h.c.QueryVar(
`mutation (
$reaction: Identifier!
$editor: Identifier!
$newMessage: String!
) {
editReaction(
reaction: $reaction
editor: $editor
newMessage: $newMessage
) {
id
emotion
subject {
__typename
... on Post {
id
}
... on Reaction {
id
}
}
message
creation
author {
id
}
}
}`,
map[string]interface{}{
"reaction": string(reactionID),
"editor": string(editorID),
"newMessage": newMessage,
},
&result,
))
if expectedErrorCode != "" {
return nil
}
require.NotNil(t, result.EditReaction)
if old.Reaction != nil {
require.Equal(t, *old.Reaction.ID, *result.EditReaction.ID)
require.Equal(t, *old.Reaction.Emotion, *result.EditReaction.Emotion)
require.Equal(t, old.Reaction.Subject, result.EditReaction.Subject)
require.Equal(t, newMessage, *result.EditReaction.Message)
require.Equal(
t,
*old.Reaction.Author.ID,
*result.EditReaction.Author.ID,
)
require.Equal(t, *old.Reaction.Creation, *result.EditReaction.Creation)
}
return result.EditReaction
}
// EditReaction helps edit a reaction and assumes success
func (ok AssumeSuccess) EditReaction(
reactionID store.ID,
editorID store.ID,
newMessage string,
) *gqlmod.Reaction {
return ok.h.editReaction(
"",
reactionID,
editorID,
newMessage,
)
}
// EditReaction assumes the given error code to be returned
func (notOk AssumeFailure) EditReaction(
expectedErrorCode errors.Code,
reactionID store.ID,
editorID store.ID,
newMessage string,
) {
notOk.checkErrCode(expectedErrorCode)
notOk.h.editReaction(
expectedErrorCode,
reactionID,
editorID,
newMessage,
)
}