Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 15374ce

Browse files
committed
Updated user tests
1 parent b28228e commit 15374ce

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

‎app/resolver/user_test.go‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import (
1515
mocket "github.com/selvatico/go-mocket"
1616
)
1717

18+
type UserParams struct {
19+
testName string
20+
id int
21+
email string
22+
}
23+
1824
func TestOne(t *testing.T) {
1925
ctx := context.Background()
2026

@@ -36,34 +42,36 @@ func TestOne(t *testing.T) {
3642
}
3743

3844
tests := []struct {
39-
name string
40-
id int
41-
email string
42-
mock func()
43-
asserts func(err error)
45+
userParams UserParams
46+
mock func()
47+
asserts func(userParams UserParams, out *graphql1.UsersOneOut, err error)
4448
}{
4549
{
46-
name: "USER EXIST",
47-
id: id,
48-
email: defaultEmail,
49-
mock: mockDefaultResult,
50-
asserts: func(err error) {
50+
userParams: UserParams{id: 2, email: "test1@gmail.com", testName: "USER NOT EXIST"},
51+
mock: mockDefaultResult,
52+
asserts: func(userParams UserParams, out *graphql1.UsersOneOut, err error) {
53+
assert.NotNil(t, err, "err should not be nil")
54+
assert.Nil(t, out, "out should be nil")
55+
},
56+
},
57+
{
58+
userParams: UserParams{id: id, email: defaultEmail, testName: "USER EXIST"},
59+
mock: mockDefaultResult,
60+
asserts: func(userParams UserParams, out *graphql1.UsersOneOut, err error) {
5161
assert.Nil(t, err, "err should be nil")
62+
assert.Equal(t, cast.ToString(userParams.id), out.ID, "id should be equals")
63+
assert.Equal(t, userParams.email, out.Email, "email should be equals")
5264
},
5365
},
5466
}
5567

5668
for _, test := range tests {
57-
t.Run(test.name, func(t *testing.T) {
69+
t.Run(test.userParams.testName, func(t *testing.T) {
5870
mocket.Catcher.Reset()
5971
test.mock()
6072

61-
out, _ := cfg.Resolvers.UsersQuery().One(ctx, &obj, "test@gmail.com")
62-
t.Log(out.ID, out.Email)
63-
64-
assert.Equal(t, cast.ToString(test.id), out.ID, "id should be equals")
65-
assert.Equal(t, test.email, out.Email, "email should be equals")
66-
test.asserts(err)
73+
out, err := cfg.Resolvers.UsersQuery().One(ctx, &obj, test.userParams.email)
74+
test.asserts(test.userParams, out, err)
6775
})
6876
}
6977
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /