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. 135
      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 response = ContentEntity.Create(command, result);
return ContentEntity.Create(command, result);
return (IContentEntity)ContentEntity.Create(command, result);
}),
Description = $"Creates an {schemaName} content."
});

135
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
{
private readonly Guid contentId = Guid.NewGuid();
private readonly IContentEntity content;
private readonly CommandContext commandContext = new CommandContext(new PatchContent());
public GraphQLMutationTests()
{
content = CreateContent(contentId, Guid.Empty, Guid.Empty, null, true);
A.CallTo(() => commandBus.PublishAsync(A<ICommand>.Ignored))
.Returns(commandContext);
}
[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 = $@"
mutation OP($data: MySchemaInputDto!) {{
updateMySchemaContent(id: ""{contentId}"", data: $data, expectedVersion: 10) {{
createMySchemaContent(data: $data, expectedVersion: 10) {{
version
data {{
myString {{
@ -51,9 +52,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
myDatetime {{
iv
}}
myJson {{
iv
}}
myGeolocation {{
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);
@ -78,7 +76,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
{
data = new
{
updateMySchemaContent = new
createMySchemaContent = new
{
version = 13,
data = new
@ -99,13 +97,95 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
{
iv = content.LastModified.ToDateTimeUtc()
},
myJson = new
myGeolocation = 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
{
iv = new
@ -133,9 +213,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
[Fact]
public async Task Should_return_single_content_when_patching_content()
{
var contentId = Guid.NewGuid();
var content = CreateContent(contentId, Guid.Empty, Guid.Empty);
var query = $@"
mutation OP($data: MySchemaInputDto!) {{
patchMySchemaContent(id: ""{contentId}"", data: $data, expectedVersion: 10) {{
@ -153,9 +230,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
myDatetime {{
iv
}}
myJson {{
iv
}}
myGeolocation {{
iv
}}
@ -183,7 +257,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
patchMySchemaContent = new
{
version = 13,
data = new {
data = new
{
myString = new
{
de = "value"
@ -200,13 +275,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
{
iv = content.LastModified.ToDateTimeUtc()
},
myJson = new
{
iv = new
{
value = 1
}
},
myGeolocation = new
{
iv = new
@ -234,8 +302,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
[Fact]
public async Task Should_publish_command_for_publish()
{
var contentId = Guid.NewGuid();
var query = $@"
mutation {{
publishMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{
@ -272,8 +338,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
[Fact]
public async Task Should_publish_command_for_unpublish()
{
var contentId = Guid.NewGuid();
var query = $@"
mutation {{
unpublishMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{
@ -310,8 +374,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
[Fact]
public async Task Should_publish_command_for_archive()
{
var contentId = Guid.NewGuid();
var query = $@"
mutation {{
archiveMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{
@ -348,8 +410,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
[Fact]
public async Task Should_publish_command_for_restore()
{
var contentId = Guid.NewGuid();
var query = $@"
mutation {{
restoreMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{
@ -386,8 +446,6 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
[Fact]
public async Task Should_publish_command_for_delete()
{
var contentId = Guid.NewGuid();
var query = $@"
mutation {{
deleteMySchemaContent(id: ""{contentId}"", expectedVersion: 10) {{
@ -426,10 +484,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
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);

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());
}
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();
data = data ??
new NamedContentData()
.AddField("my-json",
new ContentFieldData().AddValue("iv", JToken.FromObject(new { value = 1 })))
.AddField("my-string",
new ContentFieldData().AddValue("de", "value"))
.AddField("my-assets",
@ -115,6 +113,12 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
.AddField("my-geolocation",
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
{
Id = id,

Loading…
Cancel
Save