|
|
|
@ -5,11 +5,8 @@ |
|
|
|
// All rights reserved. Licensed under the MIT license.
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
using System.Text.Json; |
|
|
|
using GraphQL; |
|
|
|
using NodaTime.Text; |
|
|
|
using Squidex.Domain.Apps.Core.Contents; |
|
|
|
using Squidex.Domain.Apps.Core.TestHelpers; |
|
|
|
using Squidex.Domain.Apps.Entities.Contents.Commands; |
|
|
|
using Squidex.Infrastructure; |
|
|
|
using Squidex.Infrastructure.Commands; |
|
|
|
@ -34,14 +31,15 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_error_if_user_has_no_permission_to_create() |
|
|
|
{ |
|
|
|
var query = @"
|
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
Query = @"
|
|
|
|
mutation { |
|
|
|
createMySchemaContent(data: { myNumber: { iv: 42 } }) { |
|
|
|
createMySchemaContent(data: { }) { |
|
|
|
id |
|
|
|
} |
|
|
|
}";
|
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }); |
|
|
|
}"
|
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -79,18 +77,26 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_single_content_if_creating_content() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
mutation { |
|
|
|
createMySchemaContent(data: <DATA>, publish: true) { |
|
|
|
<FIELDS_CONTENT> |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(content); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsCreate; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }, permission); |
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
Query = @"
|
|
|
|
mutation MyMutation($data: MySchemaDataInputDto!) { |
|
|
|
createMySchemaContent(data: $data, publish: true) { |
|
|
|
{fields} |
|
|
|
} |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
fields = TestContent.AllFields |
|
|
|
}, |
|
|
|
Variables = new |
|
|
|
{ |
|
|
|
data = TestContent.Input(content, TestSchemas.Ref1.Id, TestSchemas.Ref2.Id), |
|
|
|
}, |
|
|
|
Permission = PermissionIds.AppContentsCreate |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -115,55 +121,27 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_single_content_if_creating_content_with_custom_id() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
mutation { |
|
|
|
createMySchemaContent(data: <DATA>, id: '123', publish: true) { |
|
|
|
<FIELDS_CONTENT> |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(content); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsCreate; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }, permission); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
data = new |
|
|
|
{ |
|
|
|
createMySchemaContent = TestContent.Response(content) |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
AssertResult(expected, actual); |
|
|
|
|
|
|
|
A.CallTo(() => commandBus.PublishAsync( |
|
|
|
A<CreateContent>.That.Matches(x => |
|
|
|
x.ExpectedVersion == EtagVersion.Any && |
|
|
|
x.ContentId == DomainId.Create("123") && |
|
|
|
x.SchemaId.Equals(TestSchemas.DefaultId) && |
|
|
|
x.Status == Status.Published && |
|
|
|
x.Data.Equals(content.Data)), |
|
|
|
A<CancellationToken>._)) |
|
|
|
.MustHaveHappened(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_return_single_content_if_creating_content_with_variable() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
mutation OP($data: MySchemaDataInputDto!) { |
|
|
|
createMySchemaContent(data: $data, publish: true) { |
|
|
|
<FIELDS_CONTENT> |
|
|
|
Query = @"
|
|
|
|
mutation MyMutation($data: MySchemaDataInputDto!) { |
|
|
|
createMySchemaContent(data: $data, id: '{contentId}', publish: true) { |
|
|
|
{fields} |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(content); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsCreate; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query, Variables = GetInput() }, permission); |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
contentId, |
|
|
|
fields = TestContent.AllFields |
|
|
|
}, |
|
|
|
Variables = new |
|
|
|
{ |
|
|
|
data = TestContent.Input(content, TestSchemas.Ref1.Id, TestSchemas.Ref2.Id) |
|
|
|
}, |
|
|
|
Permission = PermissionIds.AppContentsCreate |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -178,6 +156,7 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
A.CallTo(() => commandBus.PublishAsync( |
|
|
|
A<CreateContent>.That.Matches(x => |
|
|
|
x.ExpectedVersion == EtagVersion.Any && |
|
|
|
x.ContentId == contentId && |
|
|
|
x.SchemaId.Equals(TestSchemas.DefaultId) && |
|
|
|
x.Status == Status.Published && |
|
|
|
x.Data.Equals(content.Data)), |
|
|
|
@ -188,14 +167,19 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_error_if_user_has_no_permission_to_update() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
Query = @"
|
|
|
|
mutation { |
|
|
|
updateMySchemaContent(id: '<ID>', data: { myNumber: { iv: 42 } }) { |
|
|
|
updateMySchemaContent(id: '{contentId}', data: { }) { |
|
|
|
id |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }); |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
contentId |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -233,54 +217,27 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_single_content_if_updating_content() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
mutation { |
|
|
|
updateMySchemaContent(id: '<ID>', data: <DATA>, expectedVersion: 10) { |
|
|
|
<FIELDS_CONTENT> |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(content); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsUpdateOwn; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }, permission); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
data = new |
|
|
|
{ |
|
|
|
updateMySchemaContent = TestContent.Response(content) |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
AssertResult(expected, actual); |
|
|
|
|
|
|
|
A.CallTo(() => commandBus.PublishAsync( |
|
|
|
A<UpdateContent>.That.Matches(x => |
|
|
|
x.ContentId == content.Id && |
|
|
|
x.ExpectedVersion == 10 && |
|
|
|
x.SchemaId.Equals(TestSchemas.DefaultId) && |
|
|
|
x.Data.Equals(content.Data)), |
|
|
|
A<CancellationToken>._)) |
|
|
|
.MustHaveHappened(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_return_single_content_if_updating_content_with_variable() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
mutation OP($data: MySchemaDataInputDto!) { |
|
|
|
updateMySchemaContent(id: '<ID>', data: $data, expectedVersion: 10) { |
|
|
|
<FIELDS_CONTENT> |
|
|
|
Query = @"
|
|
|
|
mutation MyMutation($data: MySchemaDataInputDto!) { |
|
|
|
updateMySchemaContent(id: '{contentId}', data: $data, expectedVersion: 10) { |
|
|
|
{fields} |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(content); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsUpdateOwn; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query, Variables = GetInput() }, permission); |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
contentId, |
|
|
|
fields = TestContent.AllFields |
|
|
|
}, |
|
|
|
Variables = new |
|
|
|
{ |
|
|
|
data = TestContent.Input(content, TestSchemas.Ref1.Id, TestSchemas.Ref2.Id) |
|
|
|
}, |
|
|
|
Permission = PermissionIds.AppContentsUpdateOwn |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -294,7 +251,7 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
|
|
|
|
A.CallTo(() => commandBus.PublishAsync( |
|
|
|
A<UpdateContent>.That.Matches(x => |
|
|
|
x.ContentId == content.Id && |
|
|
|
x.ContentId == contentId && |
|
|
|
x.ExpectedVersion == 10 && |
|
|
|
x.SchemaId.Equals(TestSchemas.DefaultId) && |
|
|
|
x.Data.Equals(content.Data)), |
|
|
|
@ -305,14 +262,15 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_error_if_user_has_no_permission_to_upsert() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
Query = @"
|
|
|
|
mutation { |
|
|
|
upsertMySchemaContent(id: '<ID>', data: { myNumber: { iv: 42 } }) { |
|
|
|
upsertMySchemaContent(id: '{contentId}', data: { }) { |
|
|
|
id |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }); |
|
|
|
}"
|
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -350,55 +308,27 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_single_content_if_upserting_content() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
mutation { |
|
|
|
upsertMySchemaContent(id: '<ID>', data: <DATA>, publish: true, expectedVersion: 10) { |
|
|
|
<FIELDS_CONTENT> |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(content); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsUpsert; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }, permission); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
data = new |
|
|
|
{ |
|
|
|
upsertMySchemaContent = TestContent.Response(content) |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
AssertResult(expected, actual); |
|
|
|
|
|
|
|
A.CallTo(() => commandBus.PublishAsync( |
|
|
|
A<UpsertContent>.That.Matches(x => |
|
|
|
x.ContentId == content.Id && |
|
|
|
x.ExpectedVersion == 10 && |
|
|
|
x.SchemaId.Equals(TestSchemas.DefaultId) && |
|
|
|
x.Status == Status.Published && |
|
|
|
x.Data.Equals(content.Data)), |
|
|
|
A<CancellationToken>._)) |
|
|
|
.MustHaveHappened(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_return_single_content_if_upserting_content_with_variable() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
mutation OP($data: MySchemaDataInputDto!) { |
|
|
|
upsertMySchemaContent(id: '<ID>', data: $data, publish: true, expectedVersion: 10) { |
|
|
|
<FIELDS_CONTENT> |
|
|
|
Query = @"
|
|
|
|
mutation MyMutation($data: MySchemaDataInputDto!) { |
|
|
|
upsertMySchemaContent(id: '{contentId}', data: $data, publish: true, expectedVersion: 10) { |
|
|
|
{fields} |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(content); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsUpsert; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query, Variables = GetInput() }, permission); |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
contentId, |
|
|
|
fields = TestContent.AllFields |
|
|
|
}, |
|
|
|
Variables = new |
|
|
|
{ |
|
|
|
data = TestContent.Input(content, TestSchemas.Ref1.Id, TestSchemas.Ref2.Id) |
|
|
|
}, |
|
|
|
Permission = PermissionIds.AppContentsUpsert |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -412,7 +342,7 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
|
|
|
|
A.CallTo(() => commandBus.PublishAsync( |
|
|
|
A<UpsertContent>.That.Matches(x => |
|
|
|
x.ContentId == content.Id && |
|
|
|
x.ContentId == contentId && |
|
|
|
x.ExpectedVersion == 10 && |
|
|
|
x.SchemaId.Equals(TestSchemas.DefaultId) && |
|
|
|
x.Status == Status.Published && |
|
|
|
@ -424,14 +354,19 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_error_if_user_has_no_permission_to_patch() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
Query = @"
|
|
|
|
mutation { |
|
|
|
patchMySchemaContent(id: '<ID>', data: { myNumber: { iv: 42 } }) { |
|
|
|
patchMySchemaContent(id: '{contentId}', data: { }) { |
|
|
|
id |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }); |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
contentId |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -469,54 +404,27 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_single_content_if_patching_content() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
mutation { |
|
|
|
patchMySchemaContent(id: '<ID>', data: <DATA>, expectedVersion: 10) { |
|
|
|
<FIELDS_CONTENT> |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(content); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsUpdateOwn; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }, permission); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
data = new |
|
|
|
{ |
|
|
|
patchMySchemaContent = TestContent.Response(content) |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
AssertResult(expected, actual); |
|
|
|
|
|
|
|
A.CallTo(() => commandBus.PublishAsync( |
|
|
|
A<PatchContent>.That.Matches(x => |
|
|
|
x.ContentId == content.Id && |
|
|
|
x.ExpectedVersion == 10 && |
|
|
|
x.SchemaId.Equals(TestSchemas.DefaultId) && |
|
|
|
x.Data.Equals(content.Data)), |
|
|
|
A<CancellationToken>._)) |
|
|
|
.MustHaveHappened(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_return_single_content_if_patching_content_with_variable() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
mutation OP($data: MySchemaDataInputDto!) { |
|
|
|
patchMySchemaContent(id: '<ID>', data: $data, expectedVersion: 10) { |
|
|
|
<FIELDS_CONTENT> |
|
|
|
Query = @"
|
|
|
|
mutation MyMutation($data: MySchemaDataInputDto!) { |
|
|
|
patchMySchemaContent(id: '{contentId}', data: $data, expectedVersion: 10) { |
|
|
|
{fields} |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(content); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsUpdateOwn; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query, Variables = GetInput() }, permission); |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
contentId, |
|
|
|
fields = TestContent.AllFields |
|
|
|
}, |
|
|
|
Variables = new |
|
|
|
{ |
|
|
|
data = TestContent.Input(content, TestSchemas.Ref1.Id, TestSchemas.Ref2.Id) |
|
|
|
}, |
|
|
|
Permission = PermissionIds.AppContentsUpdateOwn |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -530,7 +438,7 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
|
|
|
|
A.CallTo(() => commandBus.PublishAsync( |
|
|
|
A<PatchContent>.That.Matches(x => |
|
|
|
x.ContentId == content.Id && |
|
|
|
x.ContentId == contentId && |
|
|
|
x.ExpectedVersion == 10 && |
|
|
|
x.SchemaId.Equals(TestSchemas.DefaultId) && |
|
|
|
x.Data.Equals(content.Data)), |
|
|
|
@ -541,14 +449,19 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_error_if_user_has_no_permission_to_change_status() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
Query = @"
|
|
|
|
mutation { |
|
|
|
changeMySchemaContent(id: '<ID>', status: 'Published') { |
|
|
|
changeMySchemaContent(id: '{contentId}', status: 'Published') { |
|
|
|
id |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }); |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
contentId |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -588,18 +501,23 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
{ |
|
|
|
var dueTime = InstantPattern.General.Parse("2021-12-12T11:10:09Z").Value; |
|
|
|
|
|
|
|
var query = CreateQuery(@"
|
|
|
|
mutation { |
|
|
|
changeMySchemaContent(id: '<ID>', status: 'Published', dueTime: '2021-12-12T11:10:09Z', expectedVersion: 10) { |
|
|
|
<FIELDS_CONTENT> |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(content); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsChangeStatusOwn; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }, permission); |
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
Query = @"
|
|
|
|
mutation { |
|
|
|
changeMySchemaContent(id: '{contentId}', status: 'Published', dueTime: '2021-12-12T11:10:09Z', expectedVersion: 10) { |
|
|
|
{fields} |
|
|
|
} |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
contentId, |
|
|
|
fields = TestContent.AllFields |
|
|
|
}, |
|
|
|
Permission = PermissionIds.AppContentsChangeStatusOwn |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -625,18 +543,23 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_single_content_if_changing_status_without_due_time() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
mutation { |
|
|
|
changeMySchemaContent(id: '<ID>', status: 'Published', expectedVersion: 10) { |
|
|
|
<FIELDS_CONTENT> |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(content); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsChangeStatusOwn; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }, permission); |
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
Query = @"
|
|
|
|
mutation { |
|
|
|
changeMySchemaContent(id: '{contentId}', status: 'Published', expectedVersion: 10) { |
|
|
|
{fields} |
|
|
|
} |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
contentId, |
|
|
|
fields = TestContent.AllFields |
|
|
|
}, |
|
|
|
Permission = PermissionIds.AppContentsChangeStatusOwn |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -662,18 +585,23 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_single_content_if_changing_status_with_null_due_time() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
mutation { |
|
|
|
changeMySchemaContent(id: '<ID>', status: 'Published', dueTime: null, expectedVersion: 10) { |
|
|
|
<FIELDS_CONTENT> |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(content); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsChangeStatusOwn; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }, permission); |
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
Query = @"
|
|
|
|
mutation { |
|
|
|
changeMySchemaContent(id: '{contentId}', status: 'Published', dueTime: null, expectedVersion: 10) { |
|
|
|
{fields} |
|
|
|
} |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
contentId, |
|
|
|
fields = TestContent.AllFields |
|
|
|
}, |
|
|
|
Permission = PermissionIds.AppContentsChangeStatusOwn |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -699,14 +627,19 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_error_if_user_has_no_permission_to_delete() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
Query = @"
|
|
|
|
mutation { |
|
|
|
deleteMySchemaContent(id: '<ID>') { |
|
|
|
deleteMySchemaContent(id: '{contentId}') { |
|
|
|
version |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }); |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
contentId |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -741,18 +674,22 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_new_version_if_deleting_content() |
|
|
|
{ |
|
|
|
var query = CreateQuery(@"
|
|
|
|
commandContext.Complete(CommandResult.Empty(contentId, 1, 0)); |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new TestQuery |
|
|
|
{ |
|
|
|
Query = @"
|
|
|
|
mutation { |
|
|
|
deleteMySchemaContent(id: '<ID>', expectedVersion: 10) { |
|
|
|
version |
|
|
|
deleteMySchemaContent(id: '{contentId}', expectedVersion: 10) { |
|
|
|
version |
|
|
|
} |
|
|
|
}", contentId, content);
|
|
|
|
|
|
|
|
commandContext.Complete(CommandResult.Empty(contentId, 13, 12)); |
|
|
|
|
|
|
|
var permission = PermissionIds.AppContentsDeleteOwn; |
|
|
|
|
|
|
|
var actual = await ExecuteAsync(new ExecutionOptions { Query = query }, permission); |
|
|
|
}",
|
|
|
|
Args = new |
|
|
|
{ |
|
|
|
contentId |
|
|
|
}, |
|
|
|
Permission = PermissionIds.AppContentsDeleteOwn |
|
|
|
}); |
|
|
|
|
|
|
|
var expected = new |
|
|
|
{ |
|
|
|
@ -760,7 +697,7 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
{ |
|
|
|
deleteMySchemaContent = new |
|
|
|
{ |
|
|
|
version = 13 |
|
|
|
version = 1 |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
@ -775,16 +712,4 @@ public class GraphQLMutationTests : GraphQLTestBase |
|
|
|
A<CancellationToken>._)) |
|
|
|
.MustHaveHappened(); |
|
|
|
} |
|
|
|
|
|
|
|
private Inputs GetInput() |
|
|
|
{ |
|
|
|
var input = new |
|
|
|
{ |
|
|
|
data = TestContent.Input(content, TestSchemas.Ref1.Id, TestSchemas.Ref2.Id) |
|
|
|
}; |
|
|
|
|
|
|
|
var element = JsonSerializer.SerializeToElement(input, TestUtils.DefaultOptions()); |
|
|
|
|
|
|
|
return serializer.ReadNode<Inputs>(element)!; |
|
|
|
} |
|
|
|
} |
|
|
|
|