diff --git a/.gitignore b/.gitignore index 1ccef05..ecfa0ca 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /.idea *.swp *.swo +.idea/ diff --git a/src/Actions/ManagesWorkflow.php b/src/Actions/ManagesWorkflow.php new file mode 100644 index 0000000..bee95f6 --- /dev/null +++ b/src/Actions/ManagesWorkflow.php @@ -0,0 +1,87 @@ +get('workflows?' . http_build_query(['page' => $page, 'limit' => $limit]))['data']; + + return new Workflow($response, $this); + } + + /** + * Create Workflow. + * + * @param array $data + * @return \Novu\SDK\Resources\Workflow + */ + public function createWorkflow(array $data) + { + $response = $this->post('workflows', $data)['data']; + + return new Workflow($response, $this); + } + + /** + * Get Workflow. + * + * @param string $workflowId + * @return \Novu\SDK\Resources\Workflow + */ + public function getWorkflow(string $workflowId) + { + $response = $this->get("workflows/{$workflowId}")['data']; + + return new Workflow($response, $this); + } + + /** + * Update Workflow. + * + * @param string $workflowId + * @param array $data + * @return \Novu\SDK\Resources\Workflow + */ + public function updateWorkflow(string $workflowId, array $data) + { + $response = $this->put("workflows/{$workflowId}", $data)['data']; + + return new Workflow($response, $this); + } + + /** + * Delete Workflow. + * + * @param string $workflowId + * @return bool + */ + public function deleteWorkflow(string $workflowId) + { + $response = $this->delete("workflows/{$workflowId}")['data']; + + return $response; + } + + /** + * Update Workflow Status. + * + * @param string $workflowId + * @param array $data + * @return \Novu\SDK\Resources\Workflow + */ + public function updateWorkflowStatus(string $workflowId, array $data) + { + $response = $this->put("workflows/{$workflowId}/status", $data)['data']; + + return new Workflow($response, $this); + } +} diff --git a/src/Novu.php b/src/Novu.php index 3ced58e..10230bd 100644 --- a/src/Novu.php +++ b/src/Novu.php @@ -26,6 +26,7 @@ class Novu Actions\ManagesTriggers, Actions\ManagesNotificationGroups, Actions\ManagesNotificationTemplates, + Actions\ManagesWorkflow, Actions\ManagesBlueprints; /** diff --git a/src/Resources/Workflow.php b/src/Resources/Workflow.php new file mode 100644 index 0000000..082e246 --- /dev/null +++ b/src/Resources/Workflow.php @@ -0,0 +1,131 @@ +toBeTrue(); -}); diff --git a/tests/WorkflowTests.php b/tests/WorkflowTests.php new file mode 100644 index 0000000..0b71c3b --- /dev/null +++ b/tests/WorkflowTests.php @@ -0,0 +1,152 @@ +novu = new Novu([getenv('NOVU_API_KEY')]); + } + + public function testCreateWorkflow() + { + $workflow = $this->novu->createWorkflow( + [ + 'name' => 'Onboarding Workflow', + 'notificationGroupId' => '5f5f5f5f5f5f5f5f5f5f5f5f', + 'steps' => [ + [ + 'active' => true, + 'shouldStopOnFail' => false, + 'uuid' => '78ab8c72-46de-49e4-8464-257085960f9e', + 'name' => 'Chat', + 'filters' => [ + [ + 'value' => 'AND', + 'children' => [ + [ + 'field' => '{{chatContent}}', + 'value' => 'flag', + 'operator' => 'NOT_IN', + 'on' => 'PAYLOAD', + ], + ], + ], + ], + 'template' => [ + 'type' => 'chat', + 'active' => true, + 'subject' => '', + 'variables' => [ + [ + 'name' => 'chatContent', + 'type' => 'STRING', + 'required' => true, + ], + ], + 'content' => '{{chatContent}}', + 'contentType' => 'editor', + ], + ], + ], + 'description' => 'Onboarding workflow to trigger after user sign up', +// 'active' => true, +// 'draft' => false, +// 'critical' => false, + ] + ); + $this->assertNotNull($workflow->id); + $this->assertEquals('Onboarding Workflow', $workflow->name); + $this->assertEquals(false, $workflow->active); + $this->assertEquals(true, $workflow->draft); + $this->assertEquals(false, $workflow->critical); + + return $workflow; + } + + /** + * @depends testCreateWorkflow + */ + public function testGetWorkflow(Workflow $workflow) + { + $workflow = $this->novu->getWorkflow($workflow->id); + $this->assertNotNull($workflow->id); + $this->assertEquals('Onboarding Workflow', $workflow->name); + $this->assertFalse($workflow->active); + $this->assertTrue($workflow->draft); + $this->assertFalse($workflow->critical); + + return $workflow; + } + + public function testGetWorkflows() + { + $workflows = $this->novu->getWorkflows(); + $this->assertNotNull($workflows); + } + + /** + * @depends testCreateWorkflow + */ + public function testUpdateWorkflows(Workflow $workflow) + { + $workflow = $this->novu->updateWorkflow($workflow->id, [ + 'name' => 'Test Workflow', + 'active' => true, + 'draft' => false, + 'critical' => false, + 'isBlueprint' => false, + 'notificationGroupId' => '5f5f5f5f5f5f5f5f5f5f5f5f', + 'tags' => ['test', 'test2'], + 'steps' => [ + [ + 'type' => 'email', + 'name' => 'test', + 'email' => 'test@test.com', + 'active' => true, + ], + ], + ]); + $this->assertNotNull($workflow->id); + $this->assertEquals('Test Workflow', $workflow->name); + $this->assertEquals(true, $workflow->active); + $this->assertEquals(false, $workflow->draft); + $this->assertEquals(false, $workflow->critical); + } + + /** + * @depends testCreateWorkflow + */ + public function testUpdateWorkflowStatus(Workflow $workflow) + { + $workflow = $this->novu->updateWorkflowStatus($workflow->id, [ + 'active' => true, + 'draft' => false, + 'critical' => false, + ]); + $this->assertNotNull($workflow->id); + $this->assertEquals('Test Workflow', $workflow->name); + $this->assertTrue($workflow->active); + $this->assertFalse($workflow->draft); + $this->assertFalse($workflow->critical); + } + + /** + * @depends testCreateWorkflow + */ + public function testDeleteWorkflow(Workflow $workflow) + { + $workflow = $this->novu->deleteWorkflow($workflow->id); + $this->assertTrue($workflow); + } +}