Skip to content

Commit

Permalink
LCH-6279: New methods for reorigination.
Browse files Browse the repository at this point in the history
  • Loading branch information
amangrover90 committed Jan 9, 2023
1 parent 1636299 commit 3e53ec5
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/ContentHubClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,54 @@ public function suppressWebhook(string $webhook_uuid, string $suppress_duration
return self::getResponseJson($this->put("webhook/$webhook_uuid/suppress", $options));
}

/**
* Reoriginates entity uuid with new target origin.
*
* @param string $entity_uuid
* Entity uuid.
* @param string $target
* Origin of target site.
*
* @return mixed
* API response.
*
* @throws \Exception
*/
public function reoriginateEntity(string $entity_uuid, string $target) {
$client = $this->getClientByUuid($target);
if (empty($client)) {
throw new \RuntimeException(sprintf('%s target client is not registered, please check target origin uuid.', $target));
}
$options['body'] = json_encode(['target' => $target]);
return self::getResponseJson($this->post("entities/$entity_uuid/reoriginate", $options));
}

/**
* Reoriginate all entities from source origin to target origin.
*
* @param string $source
* Source origin uuid.
* @param string $target
* Target origin uuid.
*
* @return mixed
* API response.
*
* @throws \Exception
*/
public function reoriginateAllEntities(string $source, string $target) {
$clients = array_column($this->getClients(), 'uuid');
if (!in_array($source, $clients, TRUE)) {
throw new \RuntimeException(sprintf('%s source client is not registered, first register it and then try reorigination to target.', $source));
}

if (!in_array($target, $clients, TRUE)) {
throw new \RuntimeException(sprintf('%s target client is not registered, please check target origin uuid.', $target));
}
$options['body'] = json_encode(['origin' => $source, 'target' => $target]);
return self::getResponseJson($this->post('entities/reoriginate', $options));
}

/**
* Remove suppression from webhook.
*
Expand Down
40 changes: 40 additions & 0 deletions test/ContentHubClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,46 @@ public function testDeleteEntityReturnsHTTPDeletedIfAllGoesWell(): void { // php
$this->assertSame($response_code, $api_response->getStatusCode());
}

/**
* @covers \Acquia\ContentHubClient\ContentHubClient::reoriginateEntity
*/
public function testReoriginateEntity(): void {
$uuid = '0e714009-72f9-4016-8f26-5fae32e6abb8';
$target = 'client-2-uuid';
$response_body = [
'success' => TRUE,
'request_id' => 'some-uuid',
];

$this->ch_client
->shouldReceive('post')
->once()
->with("entities/$uuid/reoriginate", ['body' => json_encode(['target' => $target])])
->andReturn($this->makeMockResponse(SymfonyResponse::HTTP_ACCEPTED, [], json_encode($response_body)));
$this->assertSame($response_body, $this->ch_client->reoriginateEntity($uuid, $target));
}

/**
* @covers \Acquia\ContentHubClient\ContentHubClient::reoriginateAllEntities
*/
public function testReoriginateAllEntities(): void {
$source = 'client-1-uuid';
$target = 'client-2-uuid';
$response_body = [
'success' => TRUE,
'request_id' => 'some-uuid',
];

$this->ch_client
->shouldReceive('post')
->once()
->with('entities/reoriginate', [
'body' => json_encode(['origin' => $source, 'target' => $target]),
])
->andReturn($this->makeMockResponse(SymfonyResponse::HTTP_ACCEPTED, [], json_encode($response_body)));
$this->assertSame($response_body, $this->ch_client->reoriginateAllEntities($source, $target));
}

/**
* @covers \Acquia\ContentHubClient\ContentHubClient::deleteInterest
*/
Expand Down

0 comments on commit 3e53ec5

Please sign in to comment.