|
|
|
@ -23,6 +23,8 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
public class DynamicContentWorkflowTests |
|
|
|
{ |
|
|
|
private readonly NamedId<Guid> appId = NamedId.Of(Guid.NewGuid(), "my-app"); |
|
|
|
private readonly NamedId<Guid> schemaId = NamedId.Of(Guid.NewGuid(), "my-schema"); |
|
|
|
private readonly NamedId<Guid> simpleSchemaId = NamedId.Of(Guid.NewGuid(), "my-simple-schema"); |
|
|
|
private readonly IAppProvider appProvider = A.Fake<IAppProvider>(); |
|
|
|
private readonly IAppEntity appEntity = A.Fake<IAppEntity>(); |
|
|
|
private readonly DynamicContentWorkflow sut; |
|
|
|
@ -56,13 +58,38 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
StatusColors.Published) |
|
|
|
}); |
|
|
|
|
|
|
|
private readonly Workflow simpleWorkflow; |
|
|
|
|
|
|
|
public DynamicContentWorkflowTests() |
|
|
|
{ |
|
|
|
simpleWorkflow = new Workflow( |
|
|
|
Status.Draft, |
|
|
|
new Dictionary<Status, WorkflowStep> |
|
|
|
{ |
|
|
|
[Status.Draft] = |
|
|
|
new WorkflowStep( |
|
|
|
new Dictionary<Status, WorkflowTransition> |
|
|
|
{ |
|
|
|
[Status.Published] = new WorkflowTransition() |
|
|
|
}, |
|
|
|
StatusColors.Draft), |
|
|
|
[Status.Published] = |
|
|
|
new WorkflowStep( |
|
|
|
new Dictionary<Status, WorkflowTransition> |
|
|
|
{ |
|
|
|
[Status.Draft] = new WorkflowTransition() |
|
|
|
}, |
|
|
|
StatusColors.Published) |
|
|
|
}, |
|
|
|
new List<Guid> { simpleSchemaId.Id }); |
|
|
|
|
|
|
|
var workflows = Workflows.Empty.Set(workflow).Set(Guid.NewGuid(), simpleWorkflow); |
|
|
|
|
|
|
|
A.CallTo(() => appProvider.GetAppAsync(appId.Id)) |
|
|
|
.Returns(appEntity); |
|
|
|
|
|
|
|
A.CallTo(() => appEntity.Workflows) |
|
|
|
.Returns(Workflows.Empty.Set(workflow)); |
|
|
|
.Returns(workflows); |
|
|
|
|
|
|
|
sut = new DynamicContentWorkflow(new JintScriptEngine(), appProvider); |
|
|
|
} |
|
|
|
@ -229,24 +256,67 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
result.Should().BeEquivalentTo(expected); |
|
|
|
} |
|
|
|
|
|
|
|
private ISchemaEntity CreateSchema() |
|
|
|
[Fact] |
|
|
|
public async Task Should_return_all_statuses_for_simple_schema_workflow() |
|
|
|
{ |
|
|
|
var expected = new[] |
|
|
|
{ |
|
|
|
new StatusInfo(Status.Draft, StatusColors.Draft), |
|
|
|
new StatusInfo(Status.Published, StatusColors.Published) |
|
|
|
}; |
|
|
|
|
|
|
|
var result = await sut.GetAllAsync(CreateSchema(true)); |
|
|
|
|
|
|
|
result.Should().BeEquivalentTo(expected); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_return_all_statuses_for_default_workflow_when_no_workflow_configured() |
|
|
|
{ |
|
|
|
A.CallTo(() => appEntity.Workflows).Returns(Workflows.Empty); |
|
|
|
|
|
|
|
var expected = new[] |
|
|
|
{ |
|
|
|
new StatusInfo(Status.Archived, StatusColors.Archived), |
|
|
|
new StatusInfo(Status.Draft, StatusColors.Draft), |
|
|
|
new StatusInfo(Status.Published, StatusColors.Published) |
|
|
|
}; |
|
|
|
|
|
|
|
var result = await sut.GetAllAsync(CreateSchema(true)); |
|
|
|
|
|
|
|
result.Should().BeEquivalentTo(expected); |
|
|
|
} |
|
|
|
|
|
|
|
private ISchemaEntity CreateSchema(bool simple = false) |
|
|
|
{ |
|
|
|
var schema = A.Fake<ISchemaEntity>(); |
|
|
|
|
|
|
|
A.CallTo(() => schema.AppId).Returns(appId); |
|
|
|
A.CallTo(() => schema.Id).Returns(simple ? simpleSchemaId.Id : schemaId.Id); |
|
|
|
|
|
|
|
return schema; |
|
|
|
} |
|
|
|
|
|
|
|
private IContentEntity CreateContent(Status status, int value) |
|
|
|
private IContentEntity CreateContent(Status status, int value, bool simple = false) |
|
|
|
{ |
|
|
|
var data = |
|
|
|
var content = new ContentEntity { AppId = appId, Status = status }; |
|
|
|
|
|
|
|
if (simple) |
|
|
|
{ |
|
|
|
content.SchemaId = simpleSchemaId; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
content.SchemaId = schemaId; |
|
|
|
} |
|
|
|
|
|
|
|
content.DataDraft = |
|
|
|
new NamedContentData() |
|
|
|
.AddField("field", |
|
|
|
new ContentFieldData() |
|
|
|
.AddValue("iv", value)); |
|
|
|
|
|
|
|
return new ContentEntity { AppId = appId, Status = status, DataDraft = data }; |
|
|
|
return content; |
|
|
|
} |
|
|
|
|
|
|
|
private ClaimsPrincipal User(string role) |
|
|
|
|