-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): modify query response (#1327)
Co-authored-by: Tomokazu Tantaka <[email protected]>
- Loading branch information
Showing
4 changed files
with
42 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,9 @@ package e2e | |
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/reearth/reearth/server/internal/app/config" | ||
"github.com/reearth/reearth/server/internal/usecase/repo" | ||
"github.com/reearth/reearthx/account/accountdomain" | ||
"github.com/reearth/reearthx/account/accountdomain/user" | ||
|
@@ -95,63 +92,21 @@ func baseSeederUser(ctx context.Context, r *repo.Container) error { | |
return nil | ||
} | ||
|
||
// func TestSignUp(t *testing.T) { | ||
// e, _ := StartGQLServer(t, &config.Config{ | ||
// Origins: []string{"https://example.com"}, | ||
// AuthSrv: config.AuthSrvConfig{ | ||
// Disabled: true, | ||
// }, | ||
// }, true, baseSeederUser) | ||
// query := `mutation { signup(input: {lang: "ja",theme: DEFAULT,secret: "Ajsownndww1"}){ user{ id name email } }}` | ||
// request := GraphQLRequest{ | ||
// Query: query, | ||
// } | ||
// jsonData, err := json.Marshal(request) | ||
// if err != nil { | ||
// assert.NoError(t, err) | ||
// } | ||
// o := e.POST("/api/graphql"). | ||
// WithHeader("authorization", "Bearer test"). | ||
// WithHeader("Content-Type", "application/json"). | ||
// WithHeader("X-Reearth-Debug-User", uId1.String()). | ||
// WithBytes(jsonData).Expect().Status(http.StatusOK).JSON().Object().Value("data").Object().Value("signup").Object().Value("user").Object() | ||
// o.Value("name").String().Equal("updated") | ||
// o.Value("email").String().Equal("[email protected]") | ||
// } | ||
|
||
func TestUpdateMe(t *testing.T) { | ||
e, _ := StartGQLServer(t, &config.Config{ | ||
Origins: []string{"https://example.com"}, | ||
AuthSrv: config.AuthSrvConfig{ | ||
Disabled: true, | ||
}, | ||
}, true, baseSeederUser) | ||
e, _ := StartGQLServerAndRepos(t, baseSeederUser) | ||
query := `mutation { updateMe(input: {name: "updated",email:"[email protected]",lang: "ja",theme: DEFAULT,password: "Ajsownndww1",passwordConfirmation: "Ajsownndww1"}){ me{ id name email lang theme } }}` | ||
request := GraphQLRequest{ | ||
Query: query, | ||
} | ||
jsonData, err := json.Marshal(request) | ||
if err != nil { | ||
assert.NoError(t, err) | ||
} | ||
o := e.POST("/api/graphql"). | ||
WithHeader("authorization", "Bearer test"). | ||
WithHeader("Content-Type", "application/json"). | ||
WithHeader("X-Reearth-Debug-User", uId1.String()). | ||
WithBytes(jsonData).Expect().Status(http.StatusOK).JSON().Object().Value("data").Object().Value("updateMe").Object().Value("me").Object() | ||
o := Request(e, uId1.String(), request).Object().Value("data").Object().Value("updateMe").Object().Value("me").Object() | ||
o.Value("name").String().Equal("updated") | ||
o.Value("email").String().Equal("[email protected]") | ||
o.Value("lang").String().Equal("ja") | ||
o.Value("theme").String().Equal("default") | ||
} | ||
|
||
func TestRemoveMyAuth(t *testing.T) { | ||
e, r := StartGQLServer(t, &config.Config{ | ||
Origins: []string{"https://example.com"}, | ||
AuthSrv: config.AuthSrvConfig{ | ||
Disabled: true, | ||
}, | ||
}, true, baseSeederUser) | ||
e, r := StartGQLServerAndRepos(t, baseSeederUser) | ||
u, err := r.User.FindByID(context.Background(), uId1) | ||
assert.Nil(t, err) | ||
assert.Equal(t, &user.Auth{Provider: "reearth", Sub: "reearth|" + uId1.String()}, u.Auths().GetByProvider("reearth")) | ||
|
@@ -160,28 +115,15 @@ func TestRemoveMyAuth(t *testing.T) { | |
request := GraphQLRequest{ | ||
Query: query, | ||
} | ||
jsonData, err := json.Marshal(request) | ||
if err != nil { | ||
assert.NoError(t, err) | ||
} | ||
e.POST("/api/graphql"). | ||
WithHeader("authorization", "Bearer test"). | ||
WithHeader("Content-Type", "application/json"). | ||
WithHeader("X-Reearth-Debug-User", uId1.String()). | ||
WithBytes(jsonData).Expect().Status(http.StatusOK).JSON().Object() | ||
Request(e, uId1.String(), request).Object() | ||
|
||
u, err = r.User.FindByID(context.Background(), uId1) | ||
assert.Nil(t, err) | ||
assert.Nil(t, u.Auths().Get("sub")) | ||
} | ||
|
||
func TestDeleteMe(t *testing.T) { | ||
e, r := StartGQLServer(t, &config.Config{ | ||
Origins: []string{"https://example.com"}, | ||
AuthSrv: config.AuthSrvConfig{ | ||
Disabled: true, | ||
}, | ||
}, true, baseSeederUser) | ||
e, r := StartGQLServerAndRepos(t, baseSeederUser) | ||
u, err := r.User.FindByID(context.Background(), uId1) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, u) | ||
|
@@ -190,40 +132,19 @@ func TestDeleteMe(t *testing.T) { | |
request := GraphQLRequest{ | ||
Query: query, | ||
} | ||
jsonData, err := json.Marshal(request) | ||
if err != nil { | ||
assert.NoError(t, err) | ||
} | ||
e.POST("/api/graphql"). | ||
WithHeader("authorization", "Bearer test"). | ||
WithHeader("Content-Type", "application/json"). | ||
WithHeader("X-Reearth-Debug-User", uId1.String()). | ||
WithBytes(jsonData).Expect().Status(http.StatusOK).JSON().Object() | ||
Request(e, uId1.String(), request).Object() | ||
|
||
_, err = r.User.FindByID(context.Background(), uId1) | ||
assert.Equal(t, rerror.ErrNotFound, err) | ||
} | ||
|
||
func TestSearchUser(t *testing.T) { | ||
e, _ := StartGQLServer(t, &config.Config{ | ||
Origins: []string{"https://example.com"}, | ||
AuthSrv: config.AuthSrvConfig{ | ||
Disabled: true, | ||
}, | ||
}, true, baseSeederUser) | ||
e, _ := StartGQLServerAndRepos(t, baseSeederUser) | ||
query := fmt.Sprintf(` { searchUser(nameOrEmail: "%s"){ id name email } }`, "e2e") | ||
request := GraphQLRequest{ | ||
Query: query, | ||
} | ||
jsonData, err := json.Marshal(request) | ||
if err != nil { | ||
assert.NoError(t, err) | ||
} | ||
o := e.POST("/api/graphql"). | ||
WithHeader("authorization", "Bearer test"). | ||
WithHeader("Content-Type", "application/json"). | ||
WithHeader("X-Reearth-Debug-User", uId1.String()). | ||
WithBytes(jsonData).Expect().Status(http.StatusOK).JSON().Object().Value("data").Object().Value("searchUser").Object() | ||
o := Request(e, uId1.String(), request).Object().Value("data").Object().Value("searchUser").Object() | ||
o.Value("id").String().Equal(uId1.String()) | ||
o.Value("name").String().Equal("e2e") | ||
o.Value("email").String().Equal("[email protected]") | ||
|
@@ -232,60 +153,28 @@ func TestSearchUser(t *testing.T) { | |
request = GraphQLRequest{ | ||
Query: query, | ||
} | ||
jsonData, err = json.Marshal(request) | ||
if err != nil { | ||
assert.NoError(t, err) | ||
} | ||
e.POST("/api/graphql"). | ||
WithHeader("authorization", "Bearer test"). | ||
WithHeader("Content-Type", "application/json"). | ||
WithHeader("X-Reearth-Debug-User", uId1.String()). | ||
WithBytes(jsonData).Expect().Status(http.StatusOK).JSON().Object(). | ||
Value("data").Object().Value("searchUser").Null() | ||
resp := Request(e, uId1.String(), request).Object() | ||
resp.Value("data").Object().Value("searchUser").Null() | ||
|
||
resp.NotContainsKey("errors") // not exist | ||
} | ||
|
||
func TestNode(t *testing.T) { | ||
e, _ := StartGQLServer(t, &config.Config{ | ||
Origins: []string{"https://example.com"}, | ||
AuthSrv: config.AuthSrvConfig{ | ||
Disabled: true, | ||
}, | ||
}, true, baseSeederUser) | ||
e, _ := StartGQLServerAndRepos(t, baseSeederUser) | ||
query := fmt.Sprintf(` { node(id: "%s", type: USER){ id } }`, uId1.String()) | ||
request := GraphQLRequest{ | ||
Query: query, | ||
} | ||
jsonData, err := json.Marshal(request) | ||
if err != nil { | ||
assert.NoError(t, err) | ||
} | ||
o := e.POST("/api/graphql"). | ||
WithHeader("authorization", "Bearer test"). | ||
WithHeader("Content-Type", "application/json"). | ||
WithHeader("X-Reearth-Debug-User", uId1.String()). | ||
WithBytes(jsonData).Expect().Status(http.StatusOK).JSON().Object().Value("data").Object().Value("node").Object() | ||
o := Request(e, uId1.String(), request).Object().Value("data").Object().Value("node").Object() | ||
o.Value("id").String().Equal(uId1.String()) | ||
} | ||
|
||
func TestNodes(t *testing.T) { | ||
e, _ := StartGQLServer(t, &config.Config{ | ||
Origins: []string{"https://example.com"}, | ||
AuthSrv: config.AuthSrvConfig{ | ||
Disabled: true, | ||
}, | ||
}, true, baseSeederUser) | ||
e, _ := StartGQLServerAndRepos(t, baseSeederUser) | ||
query := fmt.Sprintf(` { nodes(id: "%s", type: USER){ id } }`, uId1.String()) | ||
request := GraphQLRequest{ | ||
Query: query, | ||
} | ||
jsonData, err := json.Marshal(request) | ||
if err != nil { | ||
assert.NoError(t, err) | ||
} | ||
o := e.POST("/api/graphql"). | ||
WithHeader("authorization", "Bearer test"). | ||
WithHeader("Content-Type", "application/json"). | ||
WithHeader("X-Reearth-Debug-User", uId1.String()). | ||
WithBytes(jsonData).Expect().Status(http.StatusOK).JSON().Object().Value("data").Object().Value("nodes") | ||
o := Request(e, uId1.String(), request).Object().Value("data").Object().Value("nodes") | ||
o.Array().Contains(map[string]string{"id": uId1.String()}) | ||
} |
Oops, something went wrong.