From 097819a547b5bc292b6ee7f79f8ae5d783522409 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 19 Dec 2021 18:58:17 +0100 Subject: [PATCH] Test for Id patch. --- .../TestSuite.ApiTests/ContentUpdateTests.cs | 35 +++++++++++++++++-- .../TestSuite.Shared/Model/TestEntity.cs | 15 +++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs b/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs index f22520e2d..69991dfe9 100644 --- a/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs +++ b/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs @@ -485,15 +485,46 @@ namespace TestSuite.ApiTests try { // STEP 1: Create a new item. - content = await _.Contents.CreateAsync(new TestEntityData { Number = 1 }, true); + content = await _.Contents.CreateAsync(new TestEntityData { String = "test" }, true); - // STEP 2: Update the item and ensure that the data has changed. + // STEP 2: Path an item. + await _.Contents.PatchAsync(content.Id, new TestEntityData { Number = 1 }); + + + // STEP 3: Update the item and ensure that the data has changed. await _.Contents.PatchAsync(content.Id, new TestEntityData { Number = 2 }); var updated = await _.Contents.GetAsync(content.Id); Assert.Equal(2, updated.Data.Number); + Assert.Equal("test", updated.Data.String); + } + finally + { + if (content != null) + { + await _.Contents.DeleteAsync(content.Id); + } + } + } + + [Fact] + public async Task Should_patch_id_data_value() + { + TestEntity content = null; + try + { + // STEP 1: Create a new item. + content = await _.Contents.CreateAsync(new TestEntityData { Id = "id1" }, true); + + + // STEP 2: Update the item and ensure that the data has changed. + await _.Contents.PatchAsync(content.Id, new TestEntityData { Id = "id2" }); + + var updated = await _.Contents.GetAsync(content.Id); + + Assert.Equal("id2", updated.Data.Id); } finally { diff --git a/backend/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs b/backend/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs index adbf8ccf6..4f7264a87 100644 --- a/backend/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs +++ b/backend/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs @@ -54,7 +54,15 @@ namespace TestSuite.Model { DefaultValue = "default" } - } + }, + new UpsertSchemaFieldDto + { + Name = TestEntityData.IdField, + Properties = new StringFieldPropertiesDto + { + IsRequired = false + } + }, }, Scripts = new SchemaScriptsDto { @@ -81,11 +89,16 @@ namespace TestSuite.Model public static readonly string GeoField = nameof(Geo).ToLowerInvariant(); + public static readonly string IdField = nameof(Id).ToLowerInvariant(); + public Dictionary Localized { get; set; } [JsonConverter(typeof(InvariantConverter))] public int Number { get; set; } + [JsonConverter(typeof(InvariantConverter))] + public string Id { get; set; } + [JsonConverter(typeof(InvariantConverter))] public string String { get; set; }