|
|
@ -20,23 +20,24 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
{ |
|
|
{ |
|
|
public class GraphQLMutationTests : GraphQLTestBase |
|
|
public class GraphQLMutationTests : GraphQLTestBase |
|
|
{ |
|
|
{ |
|
|
|
|
|
private readonly Guid contentId = Guid.NewGuid(); |
|
|
|
|
|
private readonly IContentEntity content; |
|
|
private readonly CommandContext commandContext = new CommandContext(new PatchContent()); |
|
|
private readonly CommandContext commandContext = new CommandContext(new PatchContent()); |
|
|
|
|
|
|
|
|
public GraphQLMutationTests() |
|
|
public GraphQLMutationTests() |
|
|
{ |
|
|
{ |
|
|
|
|
|
content = CreateContent(contentId, Guid.Empty, Guid.Empty, null, true); |
|
|
|
|
|
|
|
|
A.CallTo(() => commandBus.PublishAsync(A<ICommand>.Ignored)) |
|
|
A.CallTo(() => commandBus.PublishAsync(A<ICommand>.Ignored)) |
|
|
.Returns(commandContext); |
|
|
.Returns(commandContext); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_return_single_content_when_updating_content() |
|
|
public async Task Should_return_single_content_when_creating_content() |
|
|
{ |
|
|
{ |
|
|
var contentId = Guid.NewGuid(); |
|
|
|
|
|
var content = CreateContent(contentId, Guid.Empty, Guid.Empty); |
|
|
|
|
|
|
|
|
|
|
|
var query = $@"
|
|
|
var query = $@"
|
|
|
mutation OP($data: MySchemaInputDto!) {{ |
|
|
mutation OP($data: MySchemaInputDto!) {{ |
|
|
updateMySchemaContent(id: ""{contentId}"", data: $data, expectedVersion: 10) {{ |
|
|
createMySchemaContent(data: $data, expectedVersion: 10) {{ |
|
|
version |
|
|
version |
|
|
data {{ |
|
|
data {{ |
|
|
myString {{ |
|
|
myString {{ |
|
|
@ -51,9 +52,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
myDatetime {{ |
|
|
myDatetime {{ |
|
|
iv |
|
|
iv |
|
|
}} |
|
|
}} |
|
|
myJson {{ |
|
|
|
|
|
iv |
|
|
|
|
|
}} |
|
|
|
|
|
myGeolocation {{ |
|
|
myGeolocation {{ |
|
|
iv |
|
|
iv |
|
|
}} |
|
|
}} |
|
|
@ -64,7 +62,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
}} |
|
|
}} |
|
|
}}";
|
|
|
}}";
|
|
|
|
|
|
|
|
|
commandContext.Complete(new ContentDataChangedResult(content.Data, 13)); |
|
|
commandContext.Complete(new EntityCreatedResult<NamedContentData>(content.Data, 13)); |
|
|
|
|
|
|
|
|
var inputContent = GetInputContent(content); |
|
|
var inputContent = GetInputContent(content); |
|
|
|
|
|
|
|
|
@ -78,7 +76,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
{ |
|
|
{ |
|
|
data = new |
|
|
data = new |
|
|
{ |
|
|
{ |
|
|
updateMySchemaContent = new |
|
|
createMySchemaContent = new |
|
|
{ |
|
|
{ |
|
|
version = 13, |
|
|
version = 13, |
|
|
data = new |
|
|
data = new |
|
|
@ -99,13 +97,95 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
{ |
|
|
{ |
|
|
iv = content.LastModified.ToDateTimeUtc() |
|
|
iv = content.LastModified.ToDateTimeUtc() |
|
|
}, |
|
|
}, |
|
|
myJson = new |
|
|
myGeolocation = new |
|
|
{ |
|
|
{ |
|
|
iv = new |
|
|
iv = new |
|
|
{ |
|
|
{ |
|
|
value = 1 |
|
|
latitude = 10, |
|
|
|
|
|
longitude = 20 |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
myTags = new |
|
|
|
|
|
{ |
|
|
|
|
|
iv = new[] |
|
|
|
|
|
{ |
|
|
|
|
|
"tag1", |
|
|
|
|
|
"tag2" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
AssertResult(expected, result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public async Task Should_return_single_content_when_updating_content() |
|
|
|
|
|
{ |
|
|
|
|
|
var query = $@"
|
|
|
|
|
|
mutation OP($data: MySchemaInputDto!) {{ |
|
|
|
|
|
updateMySchemaContent(id: ""{contentId}"", data: $data, expectedVersion: 10) {{ |
|
|
|
|
|
version |
|
|
|
|
|
data {{ |
|
|
|
|
|
myString {{ |
|
|
|
|
|
de |
|
|
|
|
|
}} |
|
|
|
|
|
myNumber {{ |
|
|
|
|
|
iv |
|
|
|
|
|
}} |
|
|
|
|
|
myBoolean {{ |
|
|
|
|
|
iv |
|
|
|
|
|
}} |
|
|
|
|
|
myDatetime {{ |
|
|
|
|
|
iv |
|
|
|
|
|
}} |
|
|
|
|
|
myGeolocation {{ |
|
|
|
|
|
iv |
|
|
|
|
|
}} |
|
|
|
|
|
myTags {{ |
|
|
|
|
|
iv |
|
|
|
|
|
}} |
|
|
|
|
|
}} |
|
|
|
|
|
}} |
|
|
|
|
|
}}";
|
|
|
|
|
|
|
|
|
|
|
|
commandContext.Complete(new ContentDataChangedResult(content.Data, 13)); |
|
|
|
|
|
|
|
|
|
|
|
var inputContent = GetInputContent(content); |
|
|
|
|
|
|
|
|
|
|
|
var variables = |
|
|
|
|
|
new JObject( |
|
|
|
|
|
new JProperty("data", inputContent)); |
|
|
|
|
|
|
|
|
|
|
|
var result = await sut.QueryAsync(app, user, new GraphQLQuery { Query = query, Variables = variables }); |
|
|
|
|
|
|
|
|
|
|
|
var expected = new |
|
|
|
|
|
{ |
|
|
|
|
|
data = new |
|
|
|
|
|
{ |
|
|
|
|
|
updateMySchemaContent = new |
|
|
|
|
|
{ |
|
|
|
|
|
version = 13, |
|
|
|
|
|
data = new |
|
|
|
|
|
{ |
|
|
|
|
|
myString = new |
|
|
|
|
|
{ |
|
|
|
|
|
de = "value" |
|
|
|
|
|
}, |
|
|
|
|
|
myNumber = new |
|
|
|
|
|
{ |
|
|
|
|
|
iv = 1 |
|
|
|
|
|
}, |
|
|
|
|
|
myBoolean = new |
|
|
|
|
|
{ |
|
|
|
|
|
iv = true |
|
|
|
|
|
}, |
|
|
|
|
|
myDatetime = new |
|
|
|
|
|
{ |
|
|
|
|
|
iv = content.LastModified.ToDateTimeUtc() |
|
|
|
|
|
}, |
|
|
myGeolocation = new |
|
|
myGeolocation = new |
|
|
{ |
|
|
{ |
|
|
iv = new |
|
|
iv = new |
|
|
@ -133,9 +213,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_return_single_content_when_patching_content() |
|
|
public async Task Should_return_single_content_when_patching_content() |
|
|
{ |
|
|
{ |
|
|
var contentId = Guid.NewGuid(); |
|
|
|
|
|
var content = CreateContent(contentId, Guid.Empty, Guid.Empty); |
|
|
|
|
|
|
|
|
|
|
|
var query = $@"
|
|
|
var query = $@"
|
|
|
mutation OP($data: MySchemaInputDto!) {{ |
|
|
mutation OP($data: MySchemaInputDto!) {{ |
|
|
patchMySchemaContent(id: ""{contentId}"", data: $data, expectedVersion: 10) {{ |
|
|
patchMySchemaContent(id: ""{contentId}"", data: $data, expectedVersion: 10) {{ |
|
|
@ -153,9 +230,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
myDatetime {{ |
|
|
myDatetime {{ |
|
|
iv |
|
|
iv |
|
|
}} |
|
|
}} |
|
|
myJson {{ |
|
|
|
|
|
iv |
|
|
|
|
|
}} |
|
|
|
|
|
myGeolocation {{ |
|
|
myGeolocation {{ |
|
|
iv |
|
|
iv |
|
|
}} |
|
|
}} |
|
|
@ -183,7 +257,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
patchMySchemaContent = new |
|
|
patchMySchemaContent = new |
|
|
{ |
|
|
{ |
|
|
version = 13, |
|
|
version = 13, |
|
|
data = new { |
|
|
data = new |
|
|
|
|
|
{ |
|
|
myString = new |
|
|
myString = new |
|
|
{ |
|
|
{ |
|
|
de = "value" |
|
|
de = "value" |
|
|
@ -200,13 +275,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
{ |
|
|
{ |
|
|
iv = content.LastModified.ToDateTimeUtc() |
|
|
iv = content.LastModified.ToDateTimeUtc() |
|
|
}, |
|
|
}, |
|
|
myJson = new |
|
|
|
|
|
{ |
|
|
|
|
|
iv = new |
|
|
|
|
|
{ |
|
|
|
|
|
value = 1 |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
myGeolocation = new |
|
|
myGeolocation = new |
|
|
{ |
|
|
{ |
|
|
iv = new |
|
|
iv = new |
|
|
@ -234,8 +302,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_publish_command_for_publish() |
|
|
public async Task Should_publish_command_for_publish() |
|
|
{ |
|
|
{ |
|
|
var contentId = Guid.NewGuid(); |
|
|
|
|
|
|
|
|
|
|
|
var query = $@"
|
|
|
var query = $@"
|
|
|
mutation {{ |
|
|
mutation {{ |
|
|
publishMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{ |
|
|
publishMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{ |
|
|
@ -272,8 +338,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_publish_command_for_unpublish() |
|
|
public async Task Should_publish_command_for_unpublish() |
|
|
{ |
|
|
{ |
|
|
var contentId = Guid.NewGuid(); |
|
|
|
|
|
|
|
|
|
|
|
var query = $@"
|
|
|
var query = $@"
|
|
|
mutation {{ |
|
|
mutation {{ |
|
|
unpublishMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{ |
|
|
unpublishMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{ |
|
|
@ -310,8 +374,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_publish_command_for_archive() |
|
|
public async Task Should_publish_command_for_archive() |
|
|
{ |
|
|
{ |
|
|
var contentId = Guid.NewGuid(); |
|
|
|
|
|
|
|
|
|
|
|
var query = $@"
|
|
|
var query = $@"
|
|
|
mutation {{ |
|
|
mutation {{ |
|
|
archiveMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{ |
|
|
archiveMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{ |
|
|
@ -348,8 +410,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_publish_command_for_restore() |
|
|
public async Task Should_publish_command_for_restore() |
|
|
{ |
|
|
{ |
|
|
var contentId = Guid.NewGuid(); |
|
|
|
|
|
|
|
|
|
|
|
var query = $@"
|
|
|
var query = $@"
|
|
|
mutation {{ |
|
|
mutation {{ |
|
|
restoreMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{ |
|
|
restoreMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{ |
|
|
@ -386,8 +446,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task Should_publish_command_for_delete() |
|
|
public async Task Should_publish_command_for_delete() |
|
|
{ |
|
|
{ |
|
|
var contentId = Guid.NewGuid(); |
|
|
|
|
|
|
|
|
|
|
|
var query = $@"
|
|
|
var query = $@"
|
|
|
mutation {{ |
|
|
mutation {{ |
|
|
deleteMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{ |
|
|
deleteMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{ |
|
|
@ -426,10 +484,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
|
|
|
|
|
|
foreach (var kvp in content.Data) |
|
|
foreach (var kvp in content.Data) |
|
|
{ |
|
|
{ |
|
|
if (kvp.Key != "my-json") |
|
|
camelContent[kvp.Key.ToCamelCase()] = kvp.Value; |
|
|
{ |
|
|
|
|
|
camelContent[kvp.Key.ToCamelCase()] = kvp.Value; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return JObject.FromObject(camelContent); |
|
|
return JObject.FromObject(camelContent); |
|
|
|