diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemaCommandsTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemaCommandsTests.cs new file mode 100644 index 000000000..5b550be02 --- /dev/null +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemaCommandsTests.cs @@ -0,0 +1,80 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using System.Collections.Generic; +using FluentAssertions; +using Squidex.Domain.Apps.Core; +using Squidex.Domain.Apps.Core.Schemas; +using Squidex.Domain.Apps.Entities.Schemas.Commands; +using Xunit; + +namespace Squidex.Domain.Apps.Entities.Schemas +{ + public class SchemaCommandsTests + { + [Fact] + public void Should_convert_upsert_command() + { + var command = new SynchronizeSchema + { + IsPublished = true, + Properties = new SchemaProperties { Hints = "MyHints" }, + Fields = new List + { + new UpsertSchemaField + { + Name = "myString", + IsDisabled = true, + IsHidden = true, + IsLocked = true, + Properties = new StringFieldProperties + { + IsRequired = true + }, + Partitioning = "language" + } + }, + FieldsInLists = new FieldNames("meta.id", "myString"), + FieldsInReferences = new FieldNames("myString"), + Scripts = new SchemaScripts + { + Change = "change-script" + }, + PreviewUrls = new Dictionary + { + ["mobile"] = "http://mobile" + }, + Category = "myCategory" + }; + + var expected = + new Schema("my-schema") + .Update(new SchemaProperties { Hints = "MyHints" }) + .AddString(1, "myString", Partitioning.Language, new StringFieldProperties + { + IsRequired = true + }) + .HideField(1).DisableField(1).LockField(1) + .ChangeCategory("myCategory") + .ConfigureFieldsInLists(new FieldNames("meta.id", "myString")) + .ConfigureFieldsInReferences(new FieldNames("myString")) + .ConfigureScripts(new SchemaScripts + { + Change = "change-script" + }) + .ConfigurePreviewUrls(new Dictionary + { + ["mobile"] = "http://mobile" + }) + .Publish(); + + var actual = command.ToSchema("my-schema", false); + + actual.Should().BeEquivalentTo(expected); + } + } +} diff --git a/frontend/app/shared/services/schemas.service.ts b/frontend/app/shared/services/schemas.service.ts index a98dced5e..40ab71038 100644 --- a/frontend/app/shared/services/schemas.service.ts +++ b/frontend/app/shared/services/schemas.service.ts @@ -178,6 +178,10 @@ export class SchemaDetailsDto extends SchemaDto { }; const result: any = { + properties: cleanup(this.properties), + category: this.category, + fieldsInLists: this.fieldsInLists, + fieldsInReferences: this.fieldsInReferences, fields: this.fields.map(field => { const copy = cleanup(field, ...fieldKeys); @@ -199,7 +203,7 @@ export class SchemaDetailsDto extends SchemaDto { return copy; }), - properties: cleanup(this.properties) + isPublished: this.isPublished }; return result;