diff --git a/server/internal/infrastructure/mongo/mongodoc/view.go b/server/internal/infrastructure/mongo/mongodoc/view.go index e1b7224d3d..4c0d241f4e 100644 --- a/server/internal/infrastructure/mongo/mongodoc/view.go +++ b/server/internal/infrastructure/mongo/mongodoc/view.go @@ -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 } @@ -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() } diff --git a/server/internal/infrastructure/mongo/mongodoc/view_test.go b/server/internal/infrastructure/mongo/mongodoc/view_test.go new file mode 100644 index 0000000000..e5af899ccc --- /dev/null +++ b/server/internal/infrastructure/mongo/mongodoc/view_test.go @@ -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) +}