Create templated workflows in draft status

MAILPOET-4264
This commit is contained in:
John Oleksowicz
2022-06-02 15:35:02 -05:00
committed by Veljko V
parent 25b9f3a876
commit 2bf59eab9a
4 changed files with 21 additions and 1 deletions

View File

@ -34,6 +34,7 @@ class CreateWorkflowFromTemplateController {
throw UnexpectedValueException::create()->withMessage('Template not found.');
}
$workflow->setDraft();
$this->storage->createWorkflow($workflow);
return $workflow;
}

View File

@ -8,6 +8,7 @@ use MailPoet\Automation\Engine\Utils\Json;
class Workflow {
public const STATUS_ACTIVE = 'active';
public const STATUS_INACTIVE = 'inactive';
public const STATUS_DRAFT = 'draft';
/** @var int */
private $id;
@ -55,6 +56,10 @@ class Workflow {
return $this->status;
}
public function setDraft(): void {
$this->status = self::STATUS_DRAFT;
}
public function getCreatedAt(): DateTimeImmutable {
return $this->createdAt;
}

View File

@ -23,4 +23,18 @@ class WorkflowsCreateFromTemplateTest extends AutomationTest {
$countAfter = count($storage->getWorkflows());
expect($countAfter)->equals($countBefore + 1);
}
public function testWorkflowsCreatedFromTemplatesAreCreatedInDraftStatus(): void {
$storage = ContainerWrapper::getInstance()->get(WorkflowStorage::class);
$this->post(self::ENDPOINT_PATH, [
'json' => [
'name' => 'Testing workflow from template',
'template' => 'delayed-email-after-signup'
],
]);
$allWorkflows = $storage->getWorkflows();
$createdWorkflow = array_pop($allWorkflows);
expect($createdWorkflow->getStatus())->equals('draft');
}
}