Skip to content

Commit

Permalink
LCH-6593: Add optional argument to fetch disabled entities in interes…
Browse files Browse the repository at this point in the history
…t list api. (#182)

* LCH-6593: Add optional argument to fetch disabled entities in interest list api.

* LCH-6593: Fix existing tests and add more tests for fetching interest list with disabled/enabled entities.
  • Loading branch information
amangrover90 authored Aug 2, 2023
1 parent 897d510 commit 62ca7d0
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/ContentHubClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,14 +769,25 @@ public function deleteInterest(string $uuid, string $webhook_uuid): ResponseInte
* Identifier of the webhook.
* @param string $site_role
* The role of the site.
* @param bool|null $disable_syndication
* Filter for disabled entities.
* If set to true, only disabled entities will be returned.
* If set to false, only enabled entities will be returned.
* If not set, all the entities will be returned.
*
* @return array
* An associate array keyed by the entity uuid.
*
* @throws \Exception
*/
public function getInterestsByWebhookAndSiteRole(string $webhook_uuid, string $site_role): array {
$data = self::getResponseJson($this->get("interest/webhook/$webhook_uuid/$site_role"));
public function getInterestsByWebhookAndSiteRole(string $webhook_uuid, string $site_role, ?bool $disable_syndication = NULL): array {
$options = [];
if (isset($disable_syndication)) {
$options['query'] = [
'disable_syndication' => $disable_syndication,
];
}
$data = self::getResponseJson($this->get("interest/webhook/$webhook_uuid/$site_role", $options));
return $data['data'] ?? [];
}

Expand Down
56 changes: 54 additions & 2 deletions test/ContentHubClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ public function testGetInterestsByWebhookAndSiteRoleIfAny(): void {
$this->ch_client
->shouldReceive('get')
->once()
->with("interest/webhook/$webhook_uuid/$site_role")
->with("interest/webhook/$webhook_uuid/$site_role", [])
->andReturn($this->makeMockResponse(SymfonyResponse::HTTP_OK, [], json_encode($response)));

$this->assertSame($this->ch_client->getInterestsByWebhookAndSiteRole($webhook_uuid, $site_role), $response['data']);
Expand All @@ -1370,12 +1370,64 @@ public function testGetInterestsByWebhookAndSiteRoleIfNone(): void {
$this->ch_client
->shouldReceive('get')
->once()
->with("interest/webhook/$webhook_uuid/$site_role")
->with("interest/webhook/$webhook_uuid/$site_role", [])
->andReturn($this->makeMockResponse(SymfonyResponse::HTTP_OK, [], json_encode($response)));

$this->assertSame($this->ch_client->getInterestsByWebhookAndSiteRole($webhook_uuid, $site_role), []);
}

/**
* @covers ::getInterestsByWebhookAndSiteRole
*/
public function testGetDisabledInterestsByWebhookAndSiteRoleIfAny(): void {
$response = [
'success' => TRUE,
'data' => [
'0e714009-72f9-4016-8f26-5fae32e6abb8' => [
'status' => SyndicationStatus::IMPORT_SUCCESSFUL,
'reason' => 'ipsum',
'event_ref' => '0e714009-72f9-4016-8f26-5fae32e6abb9',
'disabled_syndication' => TRUE,
],
],
];
$webhook_uuid = 'some-webhook-uuid';
$site_role = 'subscriber';
$this->ch_client
->shouldReceive('get')
->once()
->with("interest/webhook/$webhook_uuid/$site_role", ['query' => ['disable_syndication' => TRUE]])
->andReturn($this->makeMockResponse(SymfonyResponse::HTTP_OK, [], json_encode($response)));

$this->assertSame($this->ch_client->getInterestsByWebhookAndSiteRole($webhook_uuid, $site_role, TRUE), $response['data']);
}

/**
* @covers ::getInterestsByWebhookAndSiteRole
*/
public function testGetEnabledInterestsByWebhookAndSiteRoleIfAny(): void {
$response = [
'success' => TRUE,
'data' => [
'0e714009-72f9-4016-8f26-5fae32e6abb8' => [
'status' => SyndicationStatus::IMPORT_SUCCESSFUL,
'reason' => 'ipsum',
'event_ref' => '0e714009-72f9-4016-8f26-5fae32e6abb9',
'disabled_syndication' => FALSE,
],
],
];
$webhook_uuid = 'some-webhook-uuid';
$site_role = 'subscriber';
$this->ch_client
->shouldReceive('get')
->once()
->with("interest/webhook/$webhook_uuid/$site_role", ['query' => ['disable_syndication' => FALSE]])
->andReturn($this->makeMockResponse(SymfonyResponse::HTTP_OK, [], json_encode($response)));

$this->assertSame($this->ch_client->getInterestsByWebhookAndSiteRole($webhook_uuid, $site_role, FALSE), $response['data']);
}

/**
* @covers ::addEntitiesToInterestListBySiteRole
*/
Expand Down

0 comments on commit 62ca7d0

Please sign in to comment.