Skip to content

Commit

Permalink
fix(server): integration api returns 404 when updating empty model (#…
Browse files Browse the repository at this point in the history
…1259)

fix
  • Loading branch information
yk-eukarya authored Oct 11, 2024
1 parent 25ecfe1 commit c7c79a4
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 10 deletions.
21 changes: 21 additions & 0 deletions server/e2e/integration_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
wId0 = accountdomain.NewWorkspaceID()
uId = accountdomain.NewUserID()
iId = id.NewIntegrationID()
mId0 = id.NewModelID()
mId1 = id.NewModelID()
mId2 = id.NewModelID()
mId3 = id.NewModelID()
Expand Down Expand Up @@ -72,7 +73,9 @@ var (
ikey2 = key.Random()
ikey3 = key.Random()
ikey4 = key.Random()
ikey0 = id.RandomKey()
pid = id.NewProjectID()
sid0 = id.NewSchemaID()
sid1 = id.NewSchemaID()
sid2 = id.NewSchemaID()
sid3 = id.NewSchemaID()
Expand Down Expand Up @@ -153,6 +156,11 @@ func baseSeeder(ctx context.Context, r *repo.Container) error {
sf3 := schema.NewField(schema.NewReference(mId1, sid1, nil, nil).TypeProperty()).ID(fId3).Key(sfKey3).MustBuild()
sf4 := schema.NewField(schema.NewBool().TypeProperty()).ID(fId4).Key(sfKey4).MustBuild()

s0 := schema.New().ID(sid0).Workspace(w.ID()).Project(p.ID()).Fields([]*schema.Field{}).MustBuild()
if err := r.Schema.Save(ctx, s0); err != nil {
return err
}

s1 := schema.New().ID(sid1).Workspace(w.ID()).Project(p.ID()).Fields([]*schema.Field{sf1, sf2}).TitleField(sf1.ID().Ref()).MustBuild()
if err := r.Schema.Save(ctx, s1); err != nil {
return err
Expand All @@ -168,6 +176,19 @@ func baseSeeder(ctx context.Context, r *repo.Container) error {
return err
}

m0 := model.New().
ID(mId0).
Name("m0").
Description("m0 desc").
Public(true).
Key(ikey0).
Project(p.ID()).
Schema(s0.ID()).
MustBuild()
if err := r.Model.Save(ctx, m0); err != nil {
return err
}

m1 := model.New().
ID(mId1).
Name("m1").
Expand Down
40 changes: 35 additions & 5 deletions server/e2e/integration_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,27 @@ func TestIntegrationModelUpdateAPI(t *testing.T) {
Expect().
Status(http.StatusUnauthorized)

obj := e.PATCH(endpoint, mId1).
// update empty model
obj := e.PATCH(endpoint, mId0).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"name": "M0 updated",
"description": "M0 desc updated",
"key": "M0KeyUpdated",
}).
Expect().
Status(http.StatusOK).
JSON().
Object()
obj.
ContainsKey("id").
ContainsKey("schemaId").
HasValue("projectId", pid).
HasValue("name", "M0 updated").
HasValue("description", "M0 desc updated").
HasValue("key", "M0KeyUpdated")

obj = e.PATCH(endpoint, mId1).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"name": "newM1 updated",
Expand Down Expand Up @@ -187,12 +207,22 @@ func TestIntegrationModelFilterAPI(t *testing.T) {
Object().
HasValue("page", 1).
HasValue("perPage", 10).
HasValue("totalCount", 5).
HasValue("totalCount", 6).
Value("models").
Array()
models.Length().IsEqual(5)
models.Length().IsEqual(6)

obj0 := models.Value(0).Object()
obj0.
HasValue("id", mId0.String()).
HasValue("name", "m0").
HasValue("description", "m0 desc").
HasValue("public", true).
HasValue("key", ikey0.String()).
HasValue("projectId", pid).
HasValue("schemaId", sid0)

obj1 := models.Value(0).Object()
obj1 := models.Value(1).Object()
obj1.
HasValue("id", mId1.String()).
HasValue("name", "m1").
Expand All @@ -206,7 +236,7 @@ func TestIntegrationModelFilterAPI(t *testing.T) {
obj1.Value("updatedAt").NotNull()
obj1.Value("lastModified").NotNull()

obj2 := models.Value(1).Object()
obj2 := models.Value(2).Object()
obj2.
HasValue("id", mId2.String()).
HasValue("name", "m2").
Expand Down
18 changes: 14 additions & 4 deletions server/e2e/integration_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,22 @@ func TestIntegrationScemaFilterAPI(t *testing.T) {
Object().
HasValue("page", 1).
HasValue("perPage", 10).
HasValue("totalCount", 5).
HasValue("totalCount", 6).
Value("models").
Array()
models.Length().IsEqual(5)
models.Length().IsEqual(6)

obj1 := models.Value(0).Object()
obj0 := models.Value(0).Object()
obj0.
HasValue("id", mId0.String()).
HasValue("name", "m0").
HasValue("description", "m0 desc").
HasValue("public", true).
HasValue("key", ikey0.String()).
HasValue("projectId", pid).
HasValue("schemaId", sid0)

obj1 := models.Value(1).Object()
obj1.
HasValue("id", mId1.String()).
HasValue("name", "m1").
Expand All @@ -62,7 +72,7 @@ func TestIntegrationScemaFilterAPI(t *testing.T) {
obj1.Value("updatedAt").NotNull()
obj1.Value("lastModified").NotNull()

obj2 := models.Value(1).Object()
obj2 := models.Value(2).Object()
obj2.
HasValue("id", mId2.String()).
HasValue("name", "m2").
Expand Down
2 changes: 1 addition & 1 deletion server/internal/adapter/integration/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (s *Server) ModelUpdate(ctx context.Context, request ModelUpdateRequestObje
}

lastModified, err := uc.Item.LastModifiedByModel(ctx, request.ModelId, op)
if err != nil {
if err != nil && !errors.Is(err, rerror.ErrNotFound) {
return nil, err
}

Expand Down

0 comments on commit c7c79a4

Please sign in to comment.