Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support user search #1285

Merged
merged 10 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 4 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,10 @@ github.com/redis/go-redis/v9 v9.1.0/go.mod h1:urWj3He21Dj5k4TK1y59xH8Uj6ATueP8AH
github.com/reearth/reearthx v0.0.0-20221109022045-dd54f4626639/go.mod h1:YZMXO1RhQ5fFL0GIOFvJq2GNskW7w+xoW4Zfu2QUXhw=
github.com/reearth/reearthx v0.0.0-20230531092445-3bdc26691898 h1:M9m03h+EBR33vxIfBnen5kavaIRRu7gXFkwqHqHU0l4=
github.com/reearth/reearthx v0.0.0-20230531092445-3bdc26691898/go.mod h1:Rh7MJPKq43f+HZ/PwjZ5vEbGPpllNFvUrxn9sBn2b+s=
github.com/reearth/reearthx v0.0.0-20241023075926-e29bdd6c4ae3 h1:aFm6QNDFs08EKlrWJN9IBqdxlDUuCBIIgBIcPkLHOZY=
github.com/reearth/reearthx v0.0.0-20241023075926-e29bdd6c4ae3/go.mod h1:d1WXkdCVzSoc8pl3vW9/9yKfk4fdoZQZhX8Ot8jqgnc=
github.com/reearth/reearthx v0.0.0-20241025125329-f01a05daf443 h1:r3bAWyEVAMX60W70OPeWd0uA+2sLhXgox41rQb2XKDY=
github.com/reearth/reearthx v0.0.0-20241025125329-f01a05daf443/go.mod h1:d1WXkdCVzSoc8pl3vW9/9yKfk4fdoZQZhX8Ot8jqgnc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481 h1:jMxcLa+VjJKhpCwbLUXAD15wJ+hhvXMLujCl3MkXpfM=
Expand Down
68 changes: 63 additions & 5 deletions server/e2e/gql_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ func TestMe(t *testing.T) {
o.Value("myWorkspaceId").String().IsEqual(wId2.String())
}

func TestSearchUser(t *testing.T) {
func TestUserByNameOrEmail(t *testing.T) {
e := StartServer(t, &app.Config{}, true, baseSeederUser)
query := fmt.Sprintf(` { searchUser(nameOrEmail: "%s"){ id name email } }`, "e2e")
query := fmt.Sprintf(` { userByNameOrEmail(nameOrEmail: "%s"){ id name email } }`, "e2e")
request := GraphQLRequest{
Query: query,
}
Expand All @@ -221,12 +221,12 @@ func TestSearchUser(t *testing.T) {
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()
WithBytes(jsonData).Expect().Status(http.StatusOK).JSON().Object().Value("data").Object().Value("userByNameOrEmail").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")
query = fmt.Sprintf(` { userByNameOrEmail(nameOrEmail: "%s"){ id name email } }`, "notfound")
request = GraphQLRequest{
Query: query,
}
Expand All @@ -239,7 +239,65 @@ func TestSearchUser(t *testing.T) {
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").IsNull()
Value("data").Object().Value("userByNameOrEmail").IsNull()
}

func TestUserSearch(t *testing.T) {
e := StartServer(t, &app.Config{}, true, baseSeederUser)
query := fmt.Sprintf(` { userSearch(keyword: "%s"){ id name email } }`, "e2e")
request := GraphQLRequest{
Query: query,
}
jsonData, err := json.Marshal(request)
if err != nil {
assert.NoError(t, err)
}
res := 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()
ul := res.Value("data").Object().Value("userSearch").Array()
ul.Length().IsEqual(4)
o := ul.Value(0).Object()
o.Value("id").String().IsEqual(uId1.String())
o.Value("name").String().IsEqual("e2e")
o.Value("email").String().IsEqual("[email protected]")

query = fmt.Sprintf(` { userSearch(keyword: "%s"){ id name email } }`, "e2e2")
request = GraphQLRequest{
Query: query,
}
jsonData, err = json.Marshal(request)
if err != nil {
assert.NoError(t, err)
}
res = 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()
ul = res.Value("data").Object().Value("userSearch").Array()
ul.Length().IsEqual(1)
o = ul.Value(0).Object()
o.Value("id").String().IsEqual(uId2.String())
o.Value("name").String().IsEqual("e2e2")
o.Value("email").String().IsEqual("[email protected]")

query = fmt.Sprintf(` { userSearch(keyword: "%s"){ id name email } }`, "notfound")
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("userSearch").Array().IsEmpty()
Comment on lines +245 to +300
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve test reliability and coverage.

The current implementation has several areas that could be improved:

  1. The test is tightly coupled to specific test data:

    • Assumes exactly 4 users match "e2e"
    • Assumes specific ordering of results
  2. Missing test cases:

    • Pagination parameters
    • Case sensitivity
    • Special characters in search
    • Minimum keyword length validation

Consider refactoring the test to be more resilient to data changes:

- ul.Length().IsEqual(4)
+ ul.Length().Gt(0)  // Assert some results exist

Also, consider adding validation for result ordering or explicitly documenting if the order is undefined.

Would you like me to help implement the additional test cases and make the tests more resilient?

Committable suggestion was skipped due to low confidence.

}

func TestNode(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/oapi-codegen/runtime v1.1.1
github.com/paulmach/go.geojson v1.5.0
github.com/ravilushqa/otelgqlgen v0.17.0
github.com/reearth/reearthx v0.0.0-20241023075926-e29bdd6c4ae3
github.com/reearth/reearthx v0.0.0-20241025125329-f01a05daf443
github.com/robbiet480/go.sns v0.0.0-20230523235941-e8d832c79d68
github.com/samber/lo v1.47.0
github.com/sendgrid/sendgrid-go v3.16.0+incompatible
Expand Down
2 changes: 0 additions & 2 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,6 @@ github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSg
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/ravilushqa/otelgqlgen v0.17.0 h1:bLwQfKqtj9P24QpjM2sc1ipBm5Fqv2u7DKN5LIpj3g8=
github.com/ravilushqa/otelgqlgen v0.17.0/go.mod h1:orOIikuYsay1y3CmLgd5gsHcT9EsnXwNKmkAplzzYXQ=
github.com/reearth/reearthx v0.0.0-20241023075926-e29bdd6c4ae3 h1:aFm6QNDFs08EKlrWJN9IBqdxlDUuCBIIgBIcPkLHOZY=
github.com/reearth/reearthx v0.0.0-20241023075926-e29bdd6c4ae3/go.mod h1:d1WXkdCVzSoc8pl3vW9/9yKfk4fdoZQZhX8Ot8jqgnc=
github.com/robbiet480/go.sns v0.0.0-20230523235941-e8d832c79d68 h1:Jknsfy5cqCH6qAuoU1qNZ51hfBJfMSJYwsH9j9mdVnw=
github.com/robbiet480/go.sns v0.0.0-20230523235941-e8d832c79d68/go.mod h1:9CDhL7uDVy8vEVDNPJzxq89dPaPBWP6hxQcC8woBHus=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
Expand Down
168 changes: 151 additions & 17 deletions server/internal/adapter/gql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading