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
/
hCreatePost.go
92 lines (83 loc) · 1.85 KB
/
hCreatePost.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
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/errors"
"github.com/stretchr/testify/require"
)
func (h Helper) createPost(
expectedErrorCode errors.Code,
authorID store.ID,
title string,
contents string,
) *gqlmod.Post {
t := h.c.t
var result struct {
CreatePost *gqlmod.Post `json:"createPost"`
}
checkErr(t, expectedErrorCode, h.c.QueryVar(
`mutation (
$author: Identifier!
$title: String!
$contents: String!
) {
createPost(
author: $author
title: $title
contents: $contents
) {
id
title
contents
creation
author {
id
}
reactions {
id
}
}
}`,
map[string]interface{}{
"author": string(authorID),
"title": title,
"contents": contents,
},
&result,
))
if expectedErrorCode != "" {
return nil
}
require.NotNil(t, result.CreatePost)
require.Len(t, *result.CreatePost.ID, 32)
require.Equal(t, title, *result.CreatePost.Title)
require.Equal(t, contents, *result.CreatePost.Contents)
require.Equal(t, authorID, *result.CreatePost.Author.ID)
require.Len(t, result.CreatePost.Reactions, 0)
require.WithinDuration(
t,
time.Now(),
*result.CreatePost.Creation,
h.creationTimeTollerance,
)
return result.CreatePost
}
// CreatePost helps creating a user and assumes success
func (ok AssumeSuccess) CreatePost(
authorID store.ID,
title string,
contents string,
) *gqlmod.Post {
return ok.h.createPost("", authorID, title, contents)
}
// CreatePost assumes the given error code to be returned
func (notOk AssumeFailure) CreatePost(
expectedErrorCode errors.Code,
authorID store.ID,
title string,
contents string,
) {
notOk.checkErrCode(expectedErrorCode)
notOk.h.createPost(expectedErrorCode, authorID, title, contents)
}