Browse Source

Bugfixes (#720)

* Just a few bugfixes.

* Log errors.

* Fix state when recreated.
pull/722/head
Sebastian Stehle 5 years ago
committed by GitHub
parent
commit
79de8b69f7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      .github/workflows/dev.yml
  2. 2
      backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetDomainObject.cs
  3. 18
      backend/src/Squidex.Infrastructure/Commands/DomainObject.cs
  4. 6
      backend/tests/Squidex.Infrastructure.Tests/Commands/DomainObjectTests.cs
  5. 20
      backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs

7
.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()

2
backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetDomainObject.cs

@ -1,4 +1,4 @@
// ==========================================================================
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)

18
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);

6
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);

20
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));
}
}
}

Loading…
Cancel
Save