-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(server): add order to view document (#1162)
* fix: add order to infrastructure layer * add unit test
- Loading branch information
1 parent
32c38e4
commit 7618cf8
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
server/internal/infrastructure/mongo/mongodoc/view_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package mongodoc | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/reearth/reearth-cms/server/pkg/item/view" | ||
"github.com/reearth/reearth-cms/server/pkg/model" | ||
"github.com/reearth/reearth-cms/server/pkg/project" | ||
"github.com/reearth/reearth-cms/server/pkg/schema" | ||
"github.com/reearth/reearthx/account/accountdomain/user" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestViewDocument_Model(t *testing.T) { | ||
now := time.Now() | ||
uId, vId, mId, pId, sId := user.NewID(), view.NewID(), model.NewID(), project.NewID(), schema.NewID() | ||
c := view.ColumnList{} | ||
|
||
vDoc := &ViewDocument{ | ||
ID: vId.String(), | ||
Name: "test", | ||
User: uId.String(), | ||
Project: pId.String(), | ||
ModelId: mId.String(), | ||
Schema: sId.String(), | ||
Columns: []ColumnDocument{}, | ||
Order: 1, | ||
UpdatedAt: now, | ||
} | ||
|
||
want := view.New().ID(vId). | ||
Name("test"). | ||
User(uId). | ||
Project(pId). | ||
Model(mId). | ||
Schema(sId). | ||
Columns(&c). | ||
Order(1). | ||
UpdatedAt(now). | ||
MustBuild() | ||
|
||
got, err := vDoc.Model() | ||
assert.NoError(t, err) | ||
assert.Equal(t, want, got) | ||
} | ||
|
||
func TestNewView(t *testing.T) { | ||
now := time.Now() | ||
uId, vId, mId, pId, sId := user.NewID(), view.NewID(), model.NewID(), project.NewID(), schema.NewID() | ||
c := view.ColumnList{} | ||
|
||
v := view.New().ID(vId). | ||
Name("test"). | ||
User(uId). | ||
Project(pId). | ||
Model(mId). | ||
Schema(sId). | ||
Columns(&c). | ||
Order(1). | ||
UpdatedAt(now). | ||
MustBuild() | ||
|
||
want := &ViewDocument{ | ||
ID: vId.String(), | ||
Name: "test", | ||
User: uId.String(), | ||
Project: pId.String(), | ||
ModelId: mId.String(), | ||
Schema: sId.String(), | ||
Columns: []ColumnDocument{}, | ||
Order: 1, | ||
UpdatedAt: now, | ||
} | ||
|
||
got, gotId := NewView(v) | ||
assert.Equal(t, want, got) | ||
assert.Equal(t, want.ID, gotId) | ||
} |