Skip to content

Commit

Permalink
fix(server): add order to view document (#1162)
Browse files Browse the repository at this point in the history
* fix: add order to infrastructure layer

* add unit test
  • Loading branch information
nourbalaha authored May 21, 2024
1 parent 32c38e4 commit 7618cf8
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/internal/infrastructure/mongo/mongodoc/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ func NewView(i *view.View) (*ViewDocument, string) {
Sort: NewSort(i.Sort()),
Filter: NewFilter(i.Filter()),
Columns: columns,
Order: i.Order(),
UpdatedAt: i.UpdatedAt(),
}, iId
}
Expand Down Expand Up @@ -394,6 +395,7 @@ func (d *ViewDocument) Model() (*view.View, error) {
Filter(d.Filter.Model()).
Columns((*view.ColumnList)(&columns)).
User(uID).
Order(d.Order).
UpdatedAt(d.UpdatedAt).
Build()
}
Expand Down
79 changes: 79 additions & 0 deletions server/internal/infrastructure/mongo/mongodoc/view_test.go
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)
}

0 comments on commit 7618cf8

Please sign in to comment.