diff --git a/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsPostEndpoint.php b/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsPostEndpoint.php index 5aaa9e5b7f..f59c5f71ed 100644 --- a/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsPostEndpoint.php +++ b/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsPostEndpoint.php @@ -6,6 +6,7 @@ use MailPoet\Automation\Engine\API\Endpoint; use MailPoet\Automation\Engine\API\Request; use MailPoet\Automation\Engine\API\Response; use MailPoet\Automation\Engine\Builder\CreateWorkflowController; +use MailPoet\Validator\Builder; class WorkflowsPostEndpoint extends Endpoint { /** @var CreateWorkflowController */ @@ -18,9 +19,23 @@ class WorkflowsPostEndpoint extends Endpoint { } public function handle(Request $request): Response { - // TODO: validation $data = $request->getParams(); $this->createController->createWorkflow($data); return new Response(); } + + public static function getRequestSchema(): array { + $step = Builder::object([ + 'id' => Builder::string()->required(), + 'type' => Builder::string()->required(), + 'key' => Builder::string()->required(), + 'args' => Builder::object(), + 'next_step_id' => Builder::string(), + ]); + + return [ + 'name' => Builder::string()->required(), + 'steps' => Builder::object()->required()->additionalProperties($step), + ]; + } } diff --git a/mailpoet/tests/integration/REST/Automation/Workflows/WorkflowsPostTest.php b/mailpoet/tests/integration/REST/Automation/Workflows/WorkflowsPostTest.php index 8b290c6446..d159061550 100644 --- a/mailpoet/tests/integration/REST/Automation/Workflows/WorkflowsPostTest.php +++ b/mailpoet/tests/integration/REST/Automation/Workflows/WorkflowsPostTest.php @@ -11,7 +11,7 @@ class WorkflowsPostTest extends AutomationTest { public function testGuestNotAllowed(): void { wp_set_current_user(0); - $data = $this->post(self::ENDPOINT_PATH); + $data = $this->post(self::ENDPOINT_PATH, ['json' => ['name' => 'Testing workflow', 'steps' => []]]); $this->assertSame([ 'code' => 'rest_forbidden',