diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 2a55263bd..b2fafa835 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -95,6 +95,13 @@ jobs: options: --name test volumes: ${{ github.workspace }}:/src run: dotnet test /src/backend/tools/TestSuite/TestSuite.ApiTests/TestSuite.ApiTests.csproj --filter Category!=NotAutomated + + - name: Dump docker logs on failure + if: failure() + uses: jwalton/gh-docker-logs@v1 + with: + images: 'squidex-tmp' + tail: '100' - name: Cleanup Test if: always() diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetDomainObject.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetDomainObject.cs index cacb45f38..1c6491944 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetDomainObject.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetDomainObject.cs @@ -1,4 +1,4 @@ -// ========================================================================== +// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) diff --git a/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs b/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs index 12b1e7b2e..13161c4ad 100644 --- a/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs +++ b/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs @@ -217,6 +217,8 @@ namespace Squidex.Infrastructure.Commands { Guard.NotNull(handler, nameof(handler)); + var wasDeleted = IsDeleted(); + var previousSnapshot = Snapshot; var previousVersion = Version; try @@ -233,7 +235,7 @@ namespace Squidex.Infrastructure.Commands { await EnsureLoadedAsync(true); - if (IsDeleted()) + if (wasDeleted) { if (CanRecreate() && isCreation) { @@ -304,9 +306,19 @@ namespace Squidex.Infrastructure.Commands { var newVersion = Version + 1; - var snapshotNew = Apply(Snapshot, @event); + var snapshotOld = Snapshot; + + if (IsDeleted()) + { + snapshotOld = new T + { + Version = Version + }; + } + + var snapshotNew = Apply(snapshotOld, @event); - if (!ReferenceEquals(Snapshot, snapshotNew) || isLoading) + if (!ReferenceEquals(snapshotOld, snapshotNew) || isLoading) { snapshotNew.Version = newVersion; snapshots.Add(snapshotNew, newVersion, true); diff --git a/backend/tests/Squidex.Infrastructure.Tests/Commands/DomainObjectTests.cs b/backend/tests/Squidex.Infrastructure.Tests/Commands/DomainObjectTests.cs index b03fe0def..bc6d982db 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/Commands/DomainObjectTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/Commands/DomainObjectTests.cs @@ -79,6 +79,7 @@ namespace Squidex.Infrastructure.Commands Assert.Equal(CommandResult.Empty(id, 0, EtagVersion.Empty), result); Assert.Equal(0, sut.Version); + Assert.Equal(0, sut.Snapshot.Version); Assert.Empty(sut.GetUncomittedEvents()); AssertSnapshot(sut.Snapshot, 4, 0); @@ -116,6 +117,7 @@ namespace Squidex.Infrastructure.Commands Assert.Equal(CommandResult.Empty(id, 2, 1), result); Assert.Equal(2, sut.Version); + Assert.Equal(2, sut.Snapshot.Version); Assert.Empty(sut.GetUncomittedEvents()); AssertSnapshot(sut.Snapshot, 4, 2); @@ -155,6 +157,7 @@ namespace Squidex.Infrastructure.Commands Assert.Equal(CommandResult.Empty(id, 2, 1), result); Assert.Equal(2, sut.Version); + Assert.Equal(2, sut.Snapshot.Version); Assert.Empty(sut.GetUncomittedEvents()); AssertSnapshot(sut.Snapshot, 4, 2); @@ -192,6 +195,7 @@ namespace Squidex.Infrastructure.Commands Assert.Equal(CommandResult.Empty(id, 1, 0), result); Assert.Equal(1, sut.Version); + Assert.Equal(1, sut.Snapshot.Version); Assert.Empty(sut.GetUncomittedEvents()); AssertSnapshot(sut.Snapshot, 8, 1); @@ -213,6 +217,7 @@ namespace Squidex.Infrastructure.Commands Assert.Equal(CommandResult.Empty(id, 1, 0), result); Assert.Equal(1, sut.Version); + Assert.Equal(1, sut.Snapshot.Version); Assert.Empty(sut.GetUncomittedEvents()); AssertSnapshot(sut.Snapshot, 8, 1); @@ -345,6 +350,7 @@ namespace Squidex.Infrastructure.Commands Assert.Equal(CommandResult.Empty(id, 0, 0), result); Assert.Equal(0, sut.Version); + Assert.Equal(0, sut.Snapshot.Version); Assert.Empty(sut.GetUncomittedEvents()); AssertSnapshot(sut.Snapshot, 4, 0); diff --git a/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs b/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs index 9c2005dab..aefd2127b 100644 --- a/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs +++ b/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs @@ -575,17 +575,17 @@ namespace TestSuite.ApiTests public async Task Should_delete_content(bool permanent) { // STEP 1: Create a new item. - var content = await _.Contents.CreateAsync(new TestEntityData { Number = 2 }, true); + var content_1 = await _.Contents.CreateAsync(new TestEntityData { Number = 2 }, true); // STEP 2: Delete the item. - await _.Contents.DeleteAsync(content.Id, permanent); + await _.Contents.DeleteAsync(content_1.Id, permanent); // STEP 3: Retrieve all items and ensure that the deleted item does not exist. var updated = await _.Contents.GetAsync(); - Assert.DoesNotContain(updated.Items, x => x.Id == content.Id); + Assert.DoesNotContain(updated.Items, x => x.Id == content_1.Id); // STEP 4: Retrieve all deleted items and check if found. @@ -594,7 +594,7 @@ namespace TestSuite.ApiTests Filter = "isDeleted eq true" }, QueryContext.Default.Unpublished(true)); - Assert.Equal(!permanent, deleted.Items.Any(x => x.Id == content.Id)); + Assert.Equal(!permanent, deleted.Items.Any(x => x.Id == content_1.Id)); } [Theory] @@ -614,6 +614,12 @@ namespace TestSuite.ApiTests var content_2 = await _.Contents.CreateAsync(new TestEntityData { Number = 2 }, content_1.Id, true); Assert.Equal(Status.Published, content_2.Status); + + + // STEP 4: Check if we can find it again with a query. + var contents_4 = await _.Contents.GetAsync(new ContentQuery { Filter = $"id eq '{content_1.Id}'" }); + + Assert.NotNull(contents_4.Items.Find(x => x.Id == content_1.Id)); } [Theory] @@ -633,6 +639,12 @@ namespace TestSuite.ApiTests var content_2 = await _.Contents.UpsertAsync(content_1.Id, new TestEntityData { Number = 2 }, true); Assert.Equal(Status.Published, content_2.Status); + + + // STEP 4: Check if we can find it again with a query. + var contents_4 = await _.Contents.GetAsync(new ContentQuery { Filter = $"id eq '{content_1.Id}'" }); + + Assert.NotNull(contents_4.Items.Find(x => x.Id == content_1.Id)); } } }