diff --git a/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/CommandVersionGraphType.cs b/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/CommandVersionGraphType.cs index 30fb044ea..dd29901d8 100644 --- a/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/CommandVersionGraphType.cs +++ b/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/CommandVersionGraphType.cs @@ -11,7 +11,7 @@ using Squidex.Infrastructure.Commands; namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types { - public sealed class CommandVersionGraphType : ComplexGraphType + public sealed class CommandVersionGraphType : ObjectGraphType { public CommandVersionGraphType() { @@ -21,14 +21,14 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types { Name = "version", ResolvedType = new IntGraphType(), - Resolver = ResolveEtag(), + Resolver = ResolveVersion(), Description = "The new version of the item." }); Description = "The result of a mutation"; } - private static IFieldResolver ResolveEtag() + private static IFieldResolver ResolveVersion() { return new FuncFieldResolver(x => { diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs index 509ba6db0..9c513477e 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs @@ -131,6 +131,117 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL AssertResult(expected, result); } + [Fact] + public async Task Should_publish_command_for_publish() + { + var contentId = Guid.NewGuid(); + + var query = $@" + mutation {{ + publishMySchemaContent(id: ""{contentId}"") {{ + version + }} + }}"; + + commandContext.Complete(new EntitySavedResult(13)); + + var result = await sut.QueryAsync(app, user, new GraphQLQuery { Query = query }); + + var expected = new + { + data = new + { + publishMySchemaContent = new + { + version = 13 + } + } + }; + + AssertResult(expected, result); + + A.CallTo(() => commandBus.PublishAsync( + A.That.Matches(x => + x.SchemaId.Equals(schema.NamedId()) && + x.ContentId == contentId && + x.Status == Status.Published))) + .MustHaveHappened(); + } + + [Fact] + public async Task Should_publish_command_for_unpublish() + { + var contentId = Guid.NewGuid(); + + var query = $@" + mutation {{ + unpublishMySchemaContent(id: ""{contentId}"") {{ + version + }} + }}"; + + commandContext.Complete(new EntitySavedResult(13)); + + var result = await sut.QueryAsync(app, user, new GraphQLQuery { Query = query }); + + var expected = new + { + data = new + { + unpublishMySchemaContent = new + { + version = 13 + } + } + }; + + AssertResult(expected, result); + + A.CallTo(() => commandBus.PublishAsync( + A.That.Matches(x => + x.SchemaId.Equals(schema.NamedId()) && + x.ContentId == contentId && + x.Status == Status.Draft))) + .MustHaveHappened(); + } + + [Fact] + public async Task Should_publish_command_for_archive() + { + var contentId = Guid.NewGuid(); + + var query = $@" + mutation {{ + archiveMySchemaContent(id: ""{contentId}"") {{ + version + }} + }}"; + + commandContext.Complete(new EntitySavedResult(13)); + + var result = await sut.QueryAsync(app, user, new GraphQLQuery { Query = query }); + + var expected = new + { + data = new + { + archiveMySchemaContent = new + { + version = 13 + } + } + }; + + AssertResult(expected, result); + + A.CallTo(() => commandBus.PublishAsync( + A.That.Matches(x => + x.SchemaId.Equals(schema.NamedId()) && + x.ContentId == contentId && + x.Status == Status.Archived))) + .MustHaveHappened(); + } + [Fact] public async Task Should_publish_command_for_restore() {