Skip to content

Commit

Permalink
Merge pull request #90 from plug-and-pay/feature/INTEG-290-remove-rul…
Browse files Browse the repository at this point in the history
…es-batches

feat: allow deletion of multiple rules
  • Loading branch information
JoeyDeHaas authored Oct 30, 2024
2 parents 64303f3 + ce5e699 commit d65d84a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Tests/Feature/ClientMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function delete(string $path): Response
return $this->standardResponse();
}

public function deleteMany(string $path, array $data): Response
{
return $this->standardResponse();
}

public function getAccessToken(string $code, string $codeVerifier, string $redirectUri, int $clientId): Response
{
return $this->standardResponse([
Expand Down
13 changes: 12 additions & 1 deletion Tests/Feature/Rule/DestroyRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function delete_rule_unauthenticated(): void
}

/** @test */
public function delete_existing_product(): void
public function delete_existing_rule(): void
{
$client = new DestroyRuleMockClient(Response::HTTP_NO_CONTENT, []);
$service = new RuleService($client);
Expand All @@ -53,4 +53,15 @@ public function delete_existing_product(): void

static::assertEquals('/v2/rules/1', $client->path());
}

/** @test */
public function delete_multiple_rules(): void
{
$client = new DestroyRuleMockClient(Response::HTTP_NO_CONTENT, []);
$service = new RuleService($client);

$service->deleteMany([1, 2, 3, 4]);

static::assertEquals('/v2/rules', $client->path());
}
}
16 changes: 16 additions & 0 deletions Tests/Feature/Rule/Mock/DestroyRuleMockClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ public function delete(string $path): Response
return new Response(Response::HTTP_NO_CONTENT);
}

/**
* @throws NotFoundException
* @throws ValidationException
* @throws JsonException
*/
public function deleteMany(string $path, array $data): Response
{
$this->path = $path;
$exception = ExceptionFactory::create($this->status);
if ($exception) {
throw $exception;
}

return new Response(Response::HTTP_NO_CONTENT);
}

public function path(): string
{
return $this->path;
Expand Down
2 changes: 2 additions & 0 deletions src/Contract/ClientDeleteInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
interface ClientDeleteInterface
{
public function delete(string $path): Response;

public function deleteMany(string $path, array $data): Response;
}
13 changes: 13 additions & 0 deletions src/Service/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ public function delete(string $path): Response
return new Response($response->getStatusCode());
}

/**
* @throws GuzzleException
* @throws JsonException
* @throws NotFoundException
* @throws ValidationException
*/
public function deleteMany(string $path, array $data): Response
{
$response = $this->request(self::METHOD_DELETE, $path, $data);

return new Response($response->getStatusCode());
}

/**
* @throws GuzzleException
* @throws JsonException
Expand Down
5 changes: 5 additions & 0 deletions src/Service/RuleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function delete(int $ruleId): void
$this->client->delete("/v2/rules/$ruleId");
}

public function deleteMany(array $ruleIds): void
{
$this->client->deleteMany('/v2/rules', ['ids' => $ruleIds]);
}

public function create(Rule $rule): Rule
{
$body = RuleToBody::build($rule);
Expand Down

0 comments on commit d65d84a

Please sign in to comment.