From 98cf1c9c797f83d736108b9e681c91070dfcbf0a Mon Sep 17 00:00:00 2001 From: ksvirkou Date: Sat, 14 Mar 2020 13:24:30 +0300 Subject: [PATCH] update Crm Pipelines + tests --- src/Resources/CrmPipelines.php | 34 ++-- .../Abstraction/CrmPipelinesTestCase.php | 103 +++++++++++ .../Resources/CrmPipelinesDealsTest.php | 13 ++ .../Resources/CrmPipelinesTest.php | 170 ------------------ .../Resources/CrmPipelinesTicketsTest.php | 17 ++ 5 files changed, 151 insertions(+), 186 deletions(-) create mode 100644 tests/Integration/Abstraction/CrmPipelinesTestCase.php create mode 100644 tests/Integration/Resources/CrmPipelinesDealsTest.php delete mode 100644 tests/Integration/Resources/CrmPipelinesTest.php create mode 100644 tests/Integration/Resources/CrmPipelinesTicketsTest.php diff --git a/src/Resources/CrmPipelines.php b/src/Resources/CrmPipelines.php index 200de299..c8db39dc 100644 --- a/src/Resources/CrmPipelines.php +++ b/src/Resources/CrmPipelines.php @@ -2,6 +2,9 @@ namespace SevenShores\Hubspot\Resources; +/** + * @see https://developers.hubspot.com/docs/methods/pipelines/pipelines_overview + */ class CrmPipelines extends Resource { /** @@ -11,13 +14,13 @@ class CrmPipelines extends Resource * @param string $objectType | Currently supports tickets or deals only * @param array $params | Array of optional parameter ['includeInactive' => 'EXCLUDE_DELETED' (default) | 'INCLUDE_DELETED'] * - * @see https://developers.hubspot.com/docs/methods/pipelines/get_pipelines_for_object_type - * * @throws \SevenShores\Hubspot\Exceptions\BadRequest * + * @see https://developers.hubspot.com/docs/methods/pipelines/get_pipelines_for_object_type + * * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response */ - public function all($objectType, array $params = []) + public function all(string $objectType, array $params = []) { $endpoint = "https://api.hubapi.com/crm-pipelines/v1/pipelines/{$objectType}"; @@ -27,16 +30,17 @@ public function all($objectType, array $params = []) } /** - * @param string $objectType - * @param array $properties Array of pipeline properties + * Create a new pipeline. * - * @throws \SevenShores\Hubspot\Exceptions\BadRequest + * @param array $properties Array of pipeline properties * - * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response + * @throws \SevenShores\Hubspot\Exceptions\BadRequest * * @see https://developers.hubspot.com/docs/methods/pipelines/create_new_pipeline + * + * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response */ - public function create($objectType, array $properties) + public function create(string $objectType, array $properties) { $endpoint = "https://api.hubapi.com/crm-pipelines/v1/pipelines/{$objectType}"; @@ -46,8 +50,7 @@ public function create($objectType, array $properties) } /** - * @param string $objectType - * @param $id + * Update an existing pipeline. * * @throws \SevenShores\Hubspot\Exceptions\BadRequest * @@ -55,7 +58,7 @@ public function create($objectType, array $properties) * * @see https://developers.hubspot.com/docs/methods/pipelines/update_pipeline */ - public function update($objectType, $id, array $properties) + public function update(string $objectType, string $id, array $properties) { $endpoint = "https://api.hubapi.com/crm-pipelines/v1/pipelines/{$objectType}/{$id}"; @@ -65,16 +68,15 @@ public function update($objectType, $id, array $properties) } /** - * @param $objectType - * @param $id + * Delete an existing pipeline. * * @throws \SevenShores\Hubspot\Exceptions\BadRequest * - * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response - * * @see https://developers.hubspot.com/docs/methods/pipelines/delete_pipeline + * + * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response */ - public function delete($objectType, $id) + public function delete(string $objectType, string $id) { $endpoint = "https://api.hubapi.com/crm-pipelines/v1/pipelines/{$objectType}/{$id}"; diff --git a/tests/Integration/Abstraction/CrmPipelinesTestCase.php b/tests/Integration/Abstraction/CrmPipelinesTestCase.php new file mode 100644 index 00000000..0dd60de8 --- /dev/null +++ b/tests/Integration/Abstraction/CrmPipelinesTestCase.php @@ -0,0 +1,103 @@ +resource->all($this->type); + + $this->assertEquals(200, $response->getStatusCode()); + } + + /** @test */ + public function getAllPipelinesIncludingDeleted() + { + $response = $this->resource->all($this->type, ['includeInactive' => 'INCLUDE_DELETED']); + + $this->assertEquals(200, $response->getStatusCode()); + } + + /** @test */ + public function createPipeline() + { + $this->assertEquals(200, $this->entity->getStatusCode()); + } + + /** @test */ + public function updatePipeline() + { + $response = $this->resource->update( + $this->type, + $this->entity->pipelineId, + $this->getData('Updated '.$this->type.' Pipeline') + ); + + $this->assertEquals(200, $response->getStatusCode()); + } + + /** @test */ + public function deletePipeline() + { + $response = $this->deleteEntity(); + + $this->assertEquals(204, $response->getStatusCode()); + + $this->entity = null; + } + + protected function createEntity() + { + return $this->resource->create($this->type, $this->getData()); + } + + protected function deleteEntity() + { + return $this->resource->delete($this->type, $this->entity->pipelineId); + } + + protected function getData(string $label = null) + { + if (is_null($label)) { + $label = 'Demo '.$this->type.' Pipeline'; + } + + return [ + 'label' => $label.' '.uniqid(), + 'displayOrder' => 1, + 'active' => true, + 'stages' => [ + [ + 'label' => 'Demo Stage', + 'displayOrder' => 1, + 'metadata' => [ + 'probability' => 0.5, + ], + ], + ], + ]; + } +} diff --git a/tests/Integration/Resources/CrmPipelinesDealsTest.php b/tests/Integration/Resources/CrmPipelinesDealsTest.php new file mode 100644 index 00000000..58315254 --- /dev/null +++ b/tests/Integration/Resources/CrmPipelinesDealsTest.php @@ -0,0 +1,13 @@ +pipelines = new CrmPipelines(new Client(['key' => getenv('HUBSPOT_TEST_API_KEY')])); - sleep(1); - } - - /** @test */ - public function getAllTicketsPipelinesTest() - { - $response = $this->pipelines->all('tickets'); - - $this->assertEquals(200, $response->getStatusCode()); - } - - /** @test */ - public function getAllTicketsPipelinesIncludingDeleted() - { - $response = $this->pipelines->all('tickets', ['includeInactive' => 'INCLUDE_DELETED']); - - $this->assertEquals(200, $response->getStatusCode()); - } - - /** @test */ - public function getAllDealsPipelinesTest() - { - $response = $this->pipelines->all('deals'); - - $this->assertEquals(200, $response->getStatusCode()); - } - - /** @test */ - public function getAllDealsPipelinesIncludingDeleted() - { - $response = $this->pipelines->all('deals', ['includeInactive' => 'INCLUDE_DELETED']); - - $this->assertEquals(200, $response->getStatusCode()); - } - - /** @test */ - public function createTicketsPipeline() - { - $response = $this->createPipeline('tickets', $this->getTicketsData()); - - $this->assertEquals(200, $response->getStatusCode()); - - $this->deletePipeline('tickets', $response->pipelineId); - } - - /** @test */ - public function createDealsPipeline() - { - $response = $this->createPipeline('deals', $this->getDealsData()); - - $this->assertEquals(200, $response->getStatusCode()); - - $this->deletePipeline('deals', $response->pipelineId); - } - - /** @test */ - public function updateTicketsPipeline() - { - $data = $this->getTicketsData(); - $pipeline = $this->createPipeline('tickets', $data); - - $data['label'] = 'Updated Ticket Pipeline '.uniqid(); - - $response = $this->pipelines->update('tickets', $pipeline->pipelineId, $data); - - $this->assertEquals(200, $response->getStatusCode()); - - $this->deletePipeline('tickets', $response->pipelineId); - } - - /** @test */ - public function updateDealsPipeline() - { - $data = $this->getDealsData(); - $pipeline = $this->createPipeline('deals', $data); - - $data['label'] = 'Updated Deals Pipeline '.uniqid(); - - $response = $this->pipelines->update('deals', $pipeline->pipelineId, $data); - - $this->assertEquals(200, $response->getStatusCode()); - - $this->deletePipeline('deals', $response->pipelineId); - } - - /** @test */ - public function deleteTicketsPipeline() - { - $pipeline = $this->createPipeline('tickets', $this->getTicketsData()); - - $response = $this->deletePipeline('tickets', $pipeline->pipelineId); - - $this->assertEquals(204, $response->getStatusCode()); - } - - /** @test */ - public function deleteDealsPipeline() - { - $pipeline = $this->createPipeline('deals', $this->getDealsData()); - - $response = $this->deletePipeline('deals', $pipeline->pipelineId); - - $this->assertEquals(204, $response->getStatusCode()); - } - - protected function createPipeline($objectType, array $data) - { - return $this->pipelines->create($objectType, $data); - } - - protected function deletePipeline($objectType, $id) - { - return $this->pipelines->delete($objectType, $id); - } - - protected function getDealsData() - { - return [ - 'label' => 'Demo Deal Pipeline '.uniqid(), - 'displayOrder' => 1, - 'active' => true, - 'stages' => [ - [ - 'label' => 'Demo Stage', - 'displayOrder' => 1, - 'metadata' => [ - 'probability' => 0.5, - ], - ], - ], - ]; - } - - protected function getTicketsData() - { - return [ - 'label' => 'Demo Ticket Pipeline '.uniqid(), - 'displayOrder' => 1, - 'active' => true, - 'stages' => [ - [ - 'label' => 'Demo Stage', - 'displayOrder' => 1, - ], - ], - ]; - } -} diff --git a/tests/Integration/Resources/CrmPipelinesTicketsTest.php b/tests/Integration/Resources/CrmPipelinesTicketsTest.php new file mode 100644 index 00000000..a63dda99 --- /dev/null +++ b/tests/Integration/Resources/CrmPipelinesTicketsTest.php @@ -0,0 +1,17 @@ +