Skip to content

Commit

Permalink
Merge pull request #303 from HubSpot/review/pipeline
Browse files Browse the repository at this point in the history
update Crm Pipelines + tests
  • Loading branch information
ksvirkou-hubspot authored Mar 16, 2020
2 parents 008def0 + 98cf1c9 commit 99d4c71
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 186 deletions.
34 changes: 18 additions & 16 deletions src/Resources/CrmPipelines.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace SevenShores\Hubspot\Resources;

/**
* @see https://developers.hubspot.com/docs/methods/pipelines/pipelines_overview
*/
class CrmPipelines extends Resource
{
/**
Expand All @@ -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}";

Expand All @@ -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}";

Expand All @@ -46,16 +50,15 @@ public function create($objectType, array $properties)
}

/**
* @param string $objectType
* @param $id
* Update 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/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}";

Expand All @@ -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}";

Expand Down
103 changes: 103 additions & 0 deletions tests/Integration/Abstraction/CrmPipelinesTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace SevenShores\Hubspot\Tests\Integration\Abstraction;

use SevenShores\Hubspot\Resources\CrmPipelines;

/**
* @internal
* @coversNothing
*/
class CrmPipelinesTestCase extends EntityTestCase
{
/**
* @var string
*/
protected $type = 'deals';

/**
* @var SevenShores\Hubspot\Resources\CrmPipelines
*/
protected $resource;

/**
* @var SevenShores\Hubspot\Resources\CrmPipelines::class
*/
protected $resourceClass = CrmPipelines::class;

/** @test */
public function getAllPipelinesTest()
{
$response = $this->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,
],
],
],
];
}
}
13 changes: 13 additions & 0 deletions tests/Integration/Resources/CrmPipelinesDealsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace SevenShores\Hubspot\Tests\integration\Resources;

use SevenShores\Hubspot\Tests\Integration\Abstraction\CrmPipelinesTestCase;

/**
* @internal
* @coversNothing
*/
class CrmPipelinesDealsTest extends CrmPipelinesTestCase
{
}
170 changes: 0 additions & 170 deletions tests/Integration/Resources/CrmPipelinesTest.php

This file was deleted.

17 changes: 17 additions & 0 deletions tests/Integration/Resources/CrmPipelinesTicketsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace SevenShores\Hubspot\Tests\integration\Resources;

use SevenShores\Hubspot\Tests\Integration\Abstraction\CrmPipelinesTestCase;

/**
* @internal
* @coversNothing
*/
class CrmPipelinesTicketsTest extends CrmPipelinesTestCase
{
/**
* @var string
*/
protected $type = 'tickets';
}

0 comments on commit 99d4c71

Please sign in to comment.