Skip to content

Commit

Permalink
fix(server): fix filter bug (#1276)
Browse files Browse the repository at this point in the history
Co-authored-by: tomokazu tantaka <[email protected]>
  • Loading branch information
hexaforce and hexaforce authored Nov 25, 2024
1 parent 62ae80f commit 9527d75
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
44 changes: 43 additions & 1 deletion server/e2e/gql_asset_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
package e2e

import (
"context"
"net/http"
"os"
"testing"

"github.com/gavv/httpexpect/v2"
"github.com/reearth/reearth/server/internal/app/config"
"github.com/reearth/reearth/server/internal/usecase/repo"
"github.com/reearth/reearth/server/pkg/asset"
"github.com/reearth/reearthx/usecasex"
"github.com/stretchr/testify/assert"
)

// go test -v -run TestGetAssets ./e2e/...

func TestGetAssets(t *testing.T) {
c := &config.Config{
Origins: []string{"https://example.com"},
AuthSrv: config.AuthSrvConfig{
Disabled: true,
},
}
e := StartServer(t, c, true, baseSeeder)
e, r, _ := StartServerAndRepos(t, c, true, baseSeeder)

teamId := wID.String()

Expand Down Expand Up @@ -44,6 +51,41 @@ func TestGetAssets(t *testing.T) {
ValueEqual("name", "test.csv").
ValueEqual("coreSupport", false)

// Write directly to the DB
ctx := context.Background()
a1, err := asset.New().
NewID().Workspace(wID).Name("test.png").Size(30438).URL("https://example.com/xxxxxxxxxxxxxxxxxxxxxxxxxx.png").
// CoreSupport(true). // not set CoreSupport
Build()
assert.Nil(t, err)
err = r.Asset.Save(ctx, a1)
assert.Nil(t, err)

a2, err := asset.New().
NewID().Workspace(wID).Name("test.png").Size(30438).URL("https://example.com/xxxxxxxxxxxxxxxxxxxxxxxxxx.png").
CoreSupport(true). // CoreSupport true
Build()
assert.Nil(t, err)
err = r.Asset.Save(ctx, a2)
assert.Nil(t, err)

a3, err := asset.New().
NewID().Workspace(wID).Name("test.png").Size(30438).URL("https://example.com/xxxxxxxxxxxxxxxxxxxxxxxxxx.png").
CoreSupport(false). // CoreSupport false
Build()
assert.Nil(t, err)
err = r.Asset.Save(ctx, a3)
assert.Nil(t, err)

f := int64(20)
as, _, err := r.Asset.FindByWorkspace(ctx, wID, repo.AssetFilter{
Pagination: usecasex.CursorPagination{
First: &f,
}.Wrap(),
})
assert.Nil(t, err)
assert.Equal(t, len(as), 3)

res = getAssets(e, teamId)
assets := res.Object().Value("data").Object().Value("assets").Object().Value("nodes").Array().Iter()
for _, a := range assets {
Expand Down
7 changes: 2 additions & 5 deletions server/internal/infrastructure/mongo/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ func (r *Asset) FindByWorkspace(ctx context.Context, id accountdomain.WorkspaceI
}

var filter any = bson.M{
"team": id.String(),
"$or": []bson.M{
{"coresupport": true},
{"coresupport": bson.M{"$exists": false}},
},
"team": id.String(),
"coresupport": true,
}

if uFilter.Keyword != nil {
Expand Down

0 comments on commit 9527d75

Please sign in to comment.