From c7c79a43d69816823a285f2aef977296e7d6bd4a Mon Sep 17 00:00:00 2001 From: yk-eukarya <81808708+yk-eukarya@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:56:47 +0200 Subject: [PATCH] fix(server): integration api returns 404 when updating empty model (#1259) fix --- server/e2e/integration_item_test.go | 21 ++++++++++ server/e2e/integration_model_test.go | 40 +++++++++++++++++--- server/e2e/integration_schema_test.go | 18 +++++++-- server/internal/adapter/integration/model.go | 2 +- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/server/e2e/integration_item_test.go b/server/e2e/integration_item_test.go index 48eabba9b3..f3edcd4ac6 100644 --- a/server/e2e/integration_item_test.go +++ b/server/e2e/integration_item_test.go @@ -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() @@ -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() @@ -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 @@ -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"). diff --git a/server/e2e/integration_model_test.go b/server/e2e/integration_model_test.go index e00974020f..818e03ae6b 100644 --- a/server/e2e/integration_model_test.go +++ b/server/e2e/integration_model_test.go @@ -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", @@ -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"). @@ -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"). diff --git a/server/e2e/integration_schema_test.go b/server/e2e/integration_schema_test.go index 8a37a2c553..6ecd143832 100644 --- a/server/e2e/integration_schema_test.go +++ b/server/e2e/integration_schema_test.go @@ -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"). @@ -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"). diff --git a/server/internal/adapter/integration/model.go b/server/internal/adapter/integration/model.go index d40581102b..02b74afca7 100644 --- a/server/internal/adapter/integration/model.go +++ b/server/internal/adapter/integration/model.go @@ -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 }