Extend tests for WorkflowCreateFromTemplate enpdoint
[MAILPOET-4531]
This commit is contained in:
@@ -11,18 +11,43 @@ use MailPoet\REST\Automation\AutomationTest;
|
||||
class WorkflowsCreateFromTemplateTest extends AutomationTest {
|
||||
private const ENDPOINT_PATH = '/mailpoet/v1/automation/workflows/create-from-template';
|
||||
|
||||
/** @var WorkflowStorage */
|
||||
private $workflowStorage;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->workflowStorage = $this->diContainer->get(WorkflowStorage::class);
|
||||
}
|
||||
|
||||
public function testCreateWorkflowFromTemplate(): void {
|
||||
$storage = ContainerWrapper::getInstance()->get(WorkflowStorage::class);
|
||||
$countBefore = count($storage->getWorkflows());
|
||||
$countBefore = count($this->workflowStorage->getWorkflows());
|
||||
$this->post(self::ENDPOINT_PATH, [
|
||||
'json' => [
|
||||
'slug' => 'simple-welcome-email'
|
||||
],
|
||||
]);
|
||||
$countAfter = count($storage->getWorkflows());
|
||||
$countAfter = count($this->workflowStorage->getWorkflows());
|
||||
expect($countAfter)->equals($countBefore + 1);
|
||||
}
|
||||
|
||||
public function testGuestNotAllowed(): void {
|
||||
wp_set_current_user(0);
|
||||
$countBefore = count($this->workflowStorage->getWorkflows());
|
||||
$data = $this->post(self::ENDPOINT_PATH, [
|
||||
'json' => [
|
||||
'slug' => 'simple-welcome-email'
|
||||
],
|
||||
]);
|
||||
$countAfter = count($this->workflowStorage->getWorkflows());
|
||||
$this->assertEquals($countBefore, $countAfter);
|
||||
|
||||
$this->assertSame([
|
||||
'code' => 'rest_forbidden',
|
||||
'message' => 'Sorry, you are not allowed to do that.',
|
||||
'data' => ['status' => 401],
|
||||
], $data);
|
||||
}
|
||||
|
||||
public function testWorkflowsCreatedFromTemplatesAreCreatedInDraftStatus(): void {
|
||||
$storage = ContainerWrapper::getInstance()->get(WorkflowStorage::class);
|
||||
$this->post(self::ENDPOINT_PATH, [
|
||||
@@ -35,4 +60,21 @@ class WorkflowsCreateFromTemplateTest extends AutomationTest {
|
||||
expect($createdWorkflow->getStatus())->equals('draft');
|
||||
}
|
||||
|
||||
public function testWorkflowsCreatedFromTemplatesReturnsWorkflowId(): void {
|
||||
$storage = ContainerWrapper::getInstance()->get(WorkflowStorage::class);
|
||||
$response = $this->post(self::ENDPOINT_PATH, [
|
||||
'json' => [
|
||||
'slug' => 'simple-welcome-email'
|
||||
],
|
||||
]);
|
||||
$allWorkflows = $storage->getWorkflows();
|
||||
$createdWorkflow = array_pop($allWorkflows);
|
||||
$this->assertSame($createdWorkflow->getId(), $response['data']['id']);
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
$this->workflowStorage->flush();
|
||||
parent::_after();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user