Skip to content

Commit

Permalink
[11.13] Addition of Status & Environment to list of possible values (#…
Browse files Browse the repository at this point in the history
…769)

* Addition of Status & Environment to list of possible values that can be sent to deployment

* Fix style issue

* Missed a space..

* Fix style issues

* Missed something in the style

* Update php doc with new additional values

* Fix for style

* update spaces

* Missed something with the style

* copy paste error
  • Loading branch information
donkidd authored Dec 3, 2023
1 parent f56d415 commit b3244ef
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Api/Deployments.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class Deployments extends AbstractApi
* @var string $order_by Return deployments ordered by id, iid, created_at, updated_at,
* or ref fields (default is id)
* @var string $sort Return deployments sorted in asc or desc order (default is desc)
* @var string $status Return deployments filtered by status of deployment allowed
* values of status are 'created', 'running', 'success', 'failed',
* 'canceled', 'blocked'
* @var string $environment Return deployments filtered to a particular environment
* }
*
* @return mixed
Expand All @@ -36,6 +40,11 @@ public function all($project_id, array $parameters = [])
$resolver->setDefined('sort')
->setAllowedTypes('sort', 'string')
->setAllowedValues('sort', ['desc', 'asc']);
$resolver->setDefined('status')
->setAllowedTypes('status', 'string')
->setAllowedValues('status', ['created', 'running', 'success', 'failed', 'canceled', 'blocked']);
$resolver->setDefined('environment')
->setAllowedTypes('environment', 'string');

return $this->get($this->getProjectPath($project_id, 'deployments'), $resolver->resolve($parameters));
}
Expand Down
55 changes: 55 additions & 0 deletions tests/Api/DeploymentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,59 @@ protected function getApiClass()
{
return Deployments::class;
}

/**
* @test
*/
public function shouldAllowDeploymentFilterByStatus(): void
{
$expectedArray = $this->getMultipleDeploymentsData();

$api = $this->getMultipleDeploymentsRequestMock(
'projects/1/deployments',
$expectedArray,
['status' => 'success']
);

$this->assertEquals(
$expectedArray,
$api->all(1, ['status' => 'success'])
);
}

/**
* @test
*/
public function shouldAllowFilterByEnvironment(): void
{
$expectedArray = $this->getMultipleDeploymentsData();

$api = $this->getMultipleDeploymentsRequestMock(
'projects/1/deployments',
$expectedArray,
['environment' => 'production']
);

$this->assertEquals(
$expectedArray,
$api->all(1, ['environment' => 'production'])
);
}

/**
* @test
*/
public function shouldAllowEmptyArrayIfAllExcludedByFilter(): void
{
$expectedArray = $this->getMultipleDeploymentsData();

$api = $this->getMultipleDeploymentsRequestMock(
'projects/1/deployments',
[],
['environment' => 'test']
);

$this->assertEquals([], $api->all(1, ['environment' => 'test'])
);
}
}

0 comments on commit b3244ef

Please sign in to comment.