Browse Source

Create endpoint.

pull/222/head
Sebastian Stehle 8 years ago
parent
commit
84f56b2999
  1. 2
      src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/AppMutationsGraphType.cs
  2. 133
      tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs
  3. 10
      tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLTestBase.cs

2
src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/AppMutationsGraphType.cs

@ -89,7 +89,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
var result = commandContext.Result<EntityCreatedResult<NamedContentData>>(); var result = commandContext.Result<EntityCreatedResult<NamedContentData>>();
var response = ContentEntity.Create(command, result); var response = ContentEntity.Create(command, result);
return ContentEntity.Create(command, result); return (IContentEntity)ContentEntity.Create(command, result);
}), }),
Description = $"Creates an {schemaName} content." Description = $"Creates an {schemaName} content."
}); });

133
tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs

@ -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) {{
@ -425,12 +483,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
var camelContent = new NamedContentData(); var camelContent = new NamedContentData();
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);
} }

10
tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLTestBase.cs

@ -90,14 +90,12 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
sut = new CachingGraphQLService(cache, appProvider, assetRepository, commandBus, contentQuery, new FakeUrlGenerator()); sut = new CachingGraphQLService(cache, appProvider, assetRepository, commandBus, contentQuery, new FakeUrlGenerator());
} }
protected static IContentEntity CreateContent(Guid id, Guid refId, Guid assetId, NamedContentData data = null) protected static IContentEntity CreateContent(Guid id, Guid refId, Guid assetId, NamedContentData data = null, bool noJson = false)
{ {
var now = DateTime.UtcNow.ToInstant(); var now = DateTime.UtcNow.ToInstant();
data = data ?? data = data ??
new NamedContentData() new NamedContentData()
.AddField("my-json",
new ContentFieldData().AddValue("iv", JToken.FromObject(new { value = 1 })))
.AddField("my-string", .AddField("my-string",
new ContentFieldData().AddValue("de", "value")) new ContentFieldData().AddValue("de", "value"))
.AddField("my-assets", .AddField("my-assets",
@ -115,6 +113,12 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
.AddField("my-geolocation", .AddField("my-geolocation",
new ContentFieldData().AddValue("iv", JToken.FromObject(new { latitude = 10, longitude = 20 }))); new ContentFieldData().AddValue("iv", JToken.FromObject(new { latitude = 10, longitude = 20 })));
if (!noJson)
{
data.AddField("my-json",
new ContentFieldData().AddValue("iv", JToken.FromObject(new { value = 1 })));
}
var content = new ContentEntity var content = new ContentEntity
{ {
Id = id, Id = id,

Loading…
Cancel
Save