Skip to content

Commit

Permalink
fix(server): coresupport query missmatch (#1293)
Browse files Browse the repository at this point in the history
Co-authored-by: tomokazu tantaka <[email protected]>
Co-authored-by: lby <[email protected]>
  • Loading branch information
3 people authored Nov 29, 2024
1 parent 5fc8f1c commit 421da55
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
41 changes: 33 additions & 8 deletions server/e2e/gql_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()).
Expand All @@ -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)
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
34 changes: 8 additions & 26 deletions server/internal/infrastructure/mongo/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 421da55

Please sign in to comment.