Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow deletion of multiple rules #90

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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