Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions server/e2e/gql_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,46 @@ func TestDeleteMe(t *testing.T) {

func TestSearchUser(t *testing.T) {
e, _ := StartGQLServerAndRepos(t, baseSeederUser)
query := fmt.Sprintf(` { searchUser(nameOrEmail: "%s"){ id name email } }`, "e2e")
request := GraphQLRequest{
Query: query,
}
o := Request(e, uId1.String(), request).Object().Value("data").Object().Value("searchUser").Object()
o.Value("id").String().IsEqual(uId1.String())
o.Value("name").String().IsEqual("e2e")
o.Value("email").String().IsEqual("[email protected]")

query = fmt.Sprintf(` { searchUser(nameOrEmail: "%s"){ id name email } }`, "notfound")
request = GraphQLRequest{
Query: query,
}
resp := Request(e, uId1.String(), request).Object()
resp.Value("data").Object().Value("searchUser").IsNull()

resp.NotContainsKey("errors") // not exist
tests := []struct {
name string
input string
wantFound bool
}{
{
name: "exact match",
input: "e2e",
wantFound: true,
},
{
name: "trimming space",
input: " e2e",
wantFound: true,
},
{
name: "not found",
input: "notfound",
wantFound: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
query := fmt.Sprintf(`{ searchUser(nameOrEmail: "%s"){ id name email } }`,tt.input)
request := GraphQLRequest{ Query: query }
resp := Request(e, uId1.String(), request).Object().Value("data").Object()

if tt.wantFound {
o := resp.Value("searchUser").Object()
o.Value("id").String().IsEqual(uId1.String())
o.Value("name").String().IsEqual("e2e")
o.Value("email").String().IsEqual("[email protected]")
} else {
resp.Value("searchUser").IsNull()
resp.NotContainsKey("errors")
}
})
}
}

func TestNode(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions server/internal/adapter/gql/loader_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gql

import (
"context"
"strings"

"github.com/reearth/reearth/server/internal/adapter/gql/gqldataloader"
"github.com/reearth/reearth/server/internal/adapter/gql/gqlmodel"
Expand Down Expand Up @@ -38,6 +39,10 @@ func (c *UserLoader) Fetch(ctx context.Context, ids []gqlmodel.ID) ([]*gqlmodel.
}

func (c *UserLoader) SearchUser(ctx context.Context, nameOrEmail string) (*gqlmodel.User, error) {

trimmed := strings.TrimSpace(nameOrEmail)
nameOrEmail = trimmed

res, err := c.usecase.SearchUser(ctx, nameOrEmail)
if err != nil {
return nil, err
Expand Down