From 421da554fba2749172f03a81070834784f092ca5 Mon Sep 17 00:00:00 2001 From: tantaka tomokazu Date: Fri, 29 Nov 2024 16:58:41 +0900 Subject: [PATCH] fix(server): coresupport query missmatch (#1293) Co-authored-by: tomokazu tantaka Co-authored-by: lby --- server/e2e/gql_project_test.go | 41 +++++++++++++++---- .../internal/infrastructure/mongo/project.go | 34 ++++----------- 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/server/e2e/gql_project_test.go b/server/e2e/gql_project_test.go index c218c7921e..b426986046 100644 --- a/server/e2e/gql_project_test.go +++ b/server/e2e/gql_project_test.go @@ -555,7 +555,7 @@ func testData(e *httpexpect.Expect) { deleteProject(e, id) // delete } -func projects(t *testing.T, ctx context.Context, r *repo.Container, count int, wID idx.ID[accountdomain.Workspace], name string, alias string) { +func projects(t *testing.T, ctx context.Context, r *repo.Container, count int, wID idx.ID[accountdomain.Workspace], name string, alias string, coreSupport bool) { for i := range make([]int, count) { p := project.New(). ID(project.NewID()). @@ -566,7 +566,25 @@ func projects(t *testing.T, ctx context.Context, r *repo.Container, count int, w Alias(alias). IsArchived(false). Deleted(false). - CoreSupport(true). + CoreSupport(coreSupport). + MustBuild() + err := r.Project.Save(ctx, p) + assert.Nil(t, err) + } +} + +func projectsOldData(t *testing.T, ctx context.Context, r *repo.Container, count int, wID idx.ID[accountdomain.Workspace], name string, alias string) { + for i := range make([]int, count) { + p := project.New(). + ID(project.NewID()). + Name(fmt.Sprintf(name+" name%d", i+1)). + Description(fmt.Sprintf(name+" description%d", i+1)). + ImageURL(lo.Must(url.Parse("https://test.com"))). + Workspace(wID). + Alias(alias). + IsArchived(false). + // Deleted(false). not exist + // CoreSupport(true). not exist MustBuild() err := r.Project.Save(ctx, p) assert.Nil(t, err) @@ -583,8 +601,8 @@ func TestGetProjectPagination(t *testing.T) { e, r, _ := StartServerAndRepos(t, c, true, baseSeeder) ctx := context.Background() - projects(t, ctx, r, 20, wID, "[wID]project", "ALIAS1") - projects(t, ctx, r, 20, wId1, "[wId1]project", "ALIAS2") + projects(t, ctx, r, 20, wID, "[wID]project", "ALIAS1", true) + projects(t, ctx, r, 20, wId1, "[wId1]project", "ALIAS2", true) // ===== First request requestBody := GraphQLRequest{ @@ -661,10 +679,17 @@ func TestGetProjectPaginationKeyword(t *testing.T) { e, r, _ := StartServerAndRepos(t, c, true, baseSeeder) ctx := context.Background() - projects(t, ctx, r, 10, wID, "AAAAAAA", "ALIAS1") - projects(t, ctx, r, 10, wID, "BBBBBBB", "ALIAS2") - projects(t, ctx, r, 10, wID, "AAAProjectAAAA", "ALIAS1") - projects(t, ctx, r, 10, wID, "BBBProjectBBBB", "ALIAS2") + // no match data + projects(t, ctx, r, 10, wID, "AAAAAAA", "ALIAS1", true) + projects(t, ctx, r, 10, wID, "BBBBBBB", "ALIAS2", true) + + // match data + projects(t, ctx, r, 10, wID, "AAAProjectAAAA", "ALIAS3", true) + projects(t, ctx, r, 10, wID, "BBBProjectBBBB", "ALIAS4", true) + + // no match data + projects(t, ctx, r, 10, wID, "AAAProjectAAAA", "ALIAS5", false) + projectsOldData(t, ctx, r, 10, wID, "BBBProjectBBBB", "ALIAS6") // ===== First request requestBody := GraphQLRequest{ diff --git a/server/internal/infrastructure/mongo/project.go b/server/internal/infrastructure/mongo/project.go index 21959c31b7..aea7186ddf 100644 --- a/server/internal/infrastructure/mongo/project.go +++ b/server/internal/infrastructure/mongo/project.go @@ -85,20 +85,11 @@ func (r *Project) FindByWorkspace(ctx context.Context, id accountdomain.Workspac filter := bson.M{ "team": id.String(), - "$and": []bson.M{ - { - "$or": []bson.M{ - {"deleted": false}, - {"deleted": bson.M{"$exists": false}}, - }, - }, - { - "$or": []bson.M{ - {"coresupport": true}, - {"coresupport": bson.M{"$exists": false}}, - }, - }, + "$or": []bson.M{ + {"deleted": false}, + {"deleted": bson.M{"$exists": false}}, }, + "coresupport": true, } if uFilter.Keyword != nil { @@ -124,20 +115,11 @@ func (r *Project) FindStarredByWorkspace(ctx context.Context, id accountdomain.W filter := bson.M{ "team": id.String(), "starred": true, - "$and": []bson.M{ - { - "$or": []bson.M{ - {"deleted": false}, - {"deleted": bson.M{"$exists": false}}, - }, - }, - { - "$or": []bson.M{ - {"coresupport": true}, - {"coresupport": bson.M{"$exists": false}}, - }, - }, + "$or": []bson.M{ + {"deleted": false}, + {"deleted": bson.M{"$exists": false}}, }, + "coresupport": true, } return r.find(ctx, filter)