mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
4.9 KiB
133 lines
4.9 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using Squidex.Domain.Apps.Core.Contents;
|
|
using Squidex.Domain.Apps.Entities.Apps.Commands;
|
|
using Squidex.Domain.Apps.Entities.TestHelpers;
|
|
using Squidex.Infrastructure;
|
|
using Xunit;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Apps.Guards
|
|
{
|
|
public class GuardAppWorkflowTests
|
|
{
|
|
[Fact]
|
|
public void CanConfigure_should_throw_exception_if_workflow_is_not_defined()
|
|
{
|
|
var command = new ConfigureWorkflow();
|
|
|
|
ValidationAssert.Throws(() => GuardAppWorkflows.CanConfigure(command),
|
|
new ValidationError("Workflow is required.", "Workflow"));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanConfigure_should_throw_exception_if_workflow_has_no_initial_step()
|
|
{
|
|
var command = new ConfigureWorkflow
|
|
{
|
|
Workflow = new Workflow(
|
|
new Dictionary<Status, WorkflowStep>
|
|
{
|
|
[Status.Published] = new WorkflowStep()
|
|
},
|
|
default)
|
|
};
|
|
|
|
ValidationAssert.Throws(() => GuardAppWorkflows.CanConfigure(command),
|
|
new ValidationError("Initial step is required.", "Workflow.Initial"));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanConfigure_should_throw_exception_if_workflow_does_not_have_published_state()
|
|
{
|
|
var command = new ConfigureWorkflow
|
|
{
|
|
Workflow = new Workflow(
|
|
new Dictionary<Status, WorkflowStep>
|
|
{
|
|
[Status.Draft] = new WorkflowStep()
|
|
},
|
|
Status.Draft)
|
|
};
|
|
|
|
ValidationAssert.Throws(() => GuardAppWorkflows.CanConfigure(command),
|
|
new ValidationError("Workflow must have a published step.", "Workflow.Steps"));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanConfigure_should_throw_exception_if_workflow_step_is_not_defined()
|
|
{
|
|
var command = new ConfigureWorkflow
|
|
{
|
|
Workflow = new Workflow(
|
|
new Dictionary<Status, WorkflowStep>
|
|
{
|
|
[Status.Published] = null
|
|
},
|
|
Status.Published)
|
|
};
|
|
|
|
ValidationAssert.Throws(() => GuardAppWorkflows.CanConfigure(command),
|
|
new ValidationError("Step is required.", "Workflow.Steps.Published"));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanConfigure_should_throw_exception_if_workflow_transition_is_invalid()
|
|
{
|
|
var command = new ConfigureWorkflow
|
|
{
|
|
Workflow = new Workflow(
|
|
new Dictionary<Status, WorkflowStep>
|
|
{
|
|
[Status.Published] =
|
|
new WorkflowStep(
|
|
new Dictionary<Status, WorkflowTransition>
|
|
{
|
|
[Status.Draft] = new WorkflowTransition()
|
|
})
|
|
},
|
|
Status.Published)
|
|
};
|
|
|
|
ValidationAssert.Throws(() => GuardAppWorkflows.CanConfigure(command),
|
|
new ValidationError("Transition has an invalid target.", "Workflow.Steps.Published.Transitions.Draft"));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanConfigure_should_throw_exception_if_workflow_transition_is_not_defined()
|
|
{
|
|
var command = new ConfigureWorkflow
|
|
{
|
|
Workflow = new Workflow(
|
|
new Dictionary<Status, WorkflowStep>
|
|
{
|
|
[Status.Draft] =
|
|
new WorkflowStep(),
|
|
[Status.Published] =
|
|
new WorkflowStep(
|
|
new Dictionary<Status, WorkflowTransition>
|
|
{
|
|
[Status.Draft] = null
|
|
})
|
|
},
|
|
Status.Published)
|
|
};
|
|
|
|
ValidationAssert.Throws(() => GuardAppWorkflows.CanConfigure(command),
|
|
new ValidationError("Transition is required.", "Workflow.Steps.Published.Transitions.Draft"));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanConfigure_should_not_throw_exception_if_workflow_is_valid()
|
|
{
|
|
var command = new ConfigureWorkflow { Workflow = Workflow.Default };
|
|
|
|
GuardAppWorkflows.CanConfigure(command);
|
|
}
|
|
}
|
|
}
|
|
|