Skip to content

LCH-6737 : deleteMultipleInterest method added #194

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

Merged
merged 6 commits into from
Jan 31, 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
18 changes: 18 additions & 0 deletions src/ContentHubClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,24 @@ public function deleteInterest(string $uuid, string $webhook_uuid): ResponseInte
return $this->delete("interest/$uuid/$webhook_uuid");
}

/**
* Deletes multiple entities from a webhook's interest list.
*
* @param string $webhook_uuid
* Webhook UUID.
* @param array $interest_list
* An array of interest items.
* @param string $site_role
* Site Role.
*
* @return \Psr\Http\Message\ResponseInterface
* Response.
*/
public function deleteMultipleInterest(string $webhook_uuid, array $interest_list, string $site_role): ResponseInterface {
$options['body'] = json_encode(['uuids' => [$interest_list]]);
return $this->delete("v2/interest/$webhook_uuid/$site_role", $options);
}

/**
* Returns an extended interest list based on the site role.
*
Expand Down
32 changes: 32 additions & 0 deletions test/ContentHubClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,38 @@ public function testDeleteInterestReturnsHTTPAcceptedIfAllGoesWell(): void { //
$this->assertSame($response_code, $api_response->getStatusCode());
}

/**
* @covers \Acquia\ContentHubClient\ContentHubClient::deleteMultipleInterest
*/
public function testDeleteMultipleInterest(): void {
$webhook_uuid = $this->test_data['webhook-uuid'];
$site_role = 'subscriber';

// Test for single interest item.
$interest_list = [$this->test_data['uuid']];

$this->ch_client
->shouldReceive('delete')
->once()
->with("v2/interest/$webhook_uuid/$site_role", ['body' => json_encode(['uuids' => [$interest_list]])])
->andReturn($this->makeMockResponse(SymfonyResponse::HTTP_OK, [], ''));

$api_response = $this->ch_client->deleteMultipleInterest($webhook_uuid, $interest_list, 'subscriber');
$this->assertSame(SymfonyResponse::HTTP_OK, $api_response->getStatusCode());

// Test for multiple interest item.
$interest_list = [$this->test_data['uuid'], 'some-uuid-2'];

$this->ch_client
->shouldReceive('delete')
->once()
->with("v2/interest/$webhook_uuid/$site_role", ['body' => json_encode(['uuids' => [$interest_list]])])
->andReturn($this->makeMockResponse(SymfonyResponse::HTTP_OK, [], ''));

$api_response = $this->ch_client->deleteMultipleInterest($webhook_uuid, $interest_list, 'subscriber');
$this->assertSame(SymfonyResponse::HTTP_OK, $api_response->getStatusCode());
}

/**
* @covers \Acquia\ContentHubClient\ContentHubClient::purge
* @throws \Exception
Expand Down