diff --git a/backend/tools/TestSuite/TestSuite.ApiTests/ContentReferencesTests.cs b/backend/tools/TestSuite/TestSuite.ApiTests/ContentReferencesTests.cs new file mode 100644 index 000000000..fe67504d9 --- /dev/null +++ b/backend/tools/TestSuite/TestSuite.ApiTests/ContentReferencesTests.cs @@ -0,0 +1,61 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using System; +using System.Threading.Tasks; +using TestSuite.Fixtures; +using TestSuite.Model; +using Xunit; + +#pragma warning disable SA1300 // Element should begin with upper-case letter +#pragma warning disable SA1507 // Code should not contain multiple blank lines in a row + +namespace TestSuite.ApiTests +{ + public class ContentReferencesTests : IClassFixture + { + public ContentReferencesFixture _ { get; } + + public ContentReferencesTests(ContentReferencesFixture fixture) + { + _ = fixture; + } + + [Fact] + public async Task Should_not_deliver_unpublished_references() + { + // STEP 1: Create a referenced content. + var dataA = new TestEntityWithReferencesData(); + + var contentA_1 = await _.Contents.CreateAsync(dataA); + + + // STEP 2: Create a content with a reference. + var dataB = new TestEntityWithReferencesData { References = new[] { contentA_1.Id } }; + + var contentB_1 = await _.Contents.CreateAsync(dataB); + + await _.Contents.ChangeStatusAsync(contentB_1.Id, "Published"); + + + // STEP 3: Query new item + var contentB_2 = await _.Contents.GetAsync(contentB_1.Id); + + Assert.Empty(contentB_2.Data.References); + + + // STEP 4: Publish reference + await _.Contents.ChangeStatusAsync(contentA_1.Id, "Published"); + + + // STEP 5: Query new item again + var contentB_3 = await _.Contents.GetAsync(contentB_1.Id); + + Assert.Equal(new Guid[] { contentA_1.Id }, contentB_3.Data.References); + } + } +} diff --git a/backend/tools/TestSuite/TestSuite.Shared/Fixtures/ContentReferencesFixture.cs b/backend/tools/TestSuite/TestSuite.Shared/Fixtures/ContentReferencesFixture.cs new file mode 100644 index 000000000..0189cc8e6 --- /dev/null +++ b/backend/tools/TestSuite/TestSuite.Shared/Fixtures/ContentReferencesFixture.cs @@ -0,0 +1,30 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using System.Threading.Tasks; +using Squidex.ClientLibrary; +using TestSuite.Model; + +namespace TestSuite.Fixtures +{ + public sealed class ContentReferencesFixture : CreatedAppFixture + { + public string SchemaName { get; } = "references"; + + public IContentsClient Contents { get; } + + public ContentReferencesFixture() + { + Task.Run(async () => + { + await TestEntityWithReferences.CreateSchemaAsync(Schemas, AppName, SchemaName); + }).Wait(); + + Contents = ClientManager.CreateContentsClient(SchemaName); + } + } +}