Skip to content

Commit

Permalink
Added support for checkout / undo checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasse Lehtinen committed Aug 16, 2023
1 parent a0487a3 commit 206eb31
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

These endpoints are not supported yet

- checkout
- copy
- create folder
- email
Expand All @@ -13,7 +12,6 @@ These endpoints are not supported yet
- promote
- Rendition Presets
- revokeAuthKeys
- undo checkout
- updateAuthKey
- versioning and history
- ZIP download
41 changes: 40 additions & 1 deletion src/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,49 @@ public function removeRelation(
return $body;
}

/**
* Checkout.
*
* @param string $assetId ID of the asset to be checked out
* @return object
*/
public function checkout(
string $assetId,
) {
$response = $this->client->request('POST', 'checkout/'.$assetId, [
'headers' => [
'Authorization' => 'Bearer '.$this->authToken,
],
]);

$body = json_decode($response->getBody()->getContents());

return $body;
}

/**
* Undo checkout.
*
* @param string $assetId ID of the asset on which the checkout is undone
* @return bool
*/
public function undoCheckout(
string $assetId,
) {
$response = $this->client->request('POST', 'undocheckout/'.$assetId, [
'headers' => [
'Authorization' => 'Bearer '.$this->authToken,
],
]);

$body = json_decode($response->getBody()->getContents());

return is_object($body);
}

/**
* Logout
*
* @param array $relationIds A comma-delimited list of relation ids to be removed. To find the relation ids, use a relation search.
* @return bool
*/
public function logout()
Expand Down
32 changes: 32 additions & 0 deletions tests/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,38 @@
expect($searchResults->hits)->toHaveCount(0);
});

test('can checkout and undo checkout', function () {
// Upload a test file
$temporaryFilename = tempnam('/tmp', 'ElvisTest');
$createResults = $this->assets->create(filename: $temporaryFilename, folderPath: '/Users/elvis-package-testing/');
expect($createResults)->toBeObject();
expect($createResults)->toHaveProperty('id');
expect($createResults->id)->toBeString();

// Checkout file
$checkout = $this->assets->checkout(assetId: $createResults->id);
expect($checkout)->toBeObject();
expect($checkout)->toHaveProperty('checkedOut');
expect($checkout)->toHaveProperty('checkedOutBy');

// Search for asset
$searchResults = $this->assets->search(query: 'id:'.$createResults->id);
expect($searchResults)->toBeObject();
expect($searchResults->hits)->toHaveCount(1);
expect($searchResults->hits[0]->metadata)->toHaveProperty('checkedOutBy');

// Undo checkout
$undoCheckout = $this->assets->undoCheckout(assetId: $createResults->id);
expect($undoCheckout)->toBeTrue();

// Check that asset was updated
$searchResults = $this->assets->search(query: 'id:'.$createResults->id);
expect($searchResults)->toBeObject();
expect($searchResults->hits)->toHaveCount(1);
expect($searchResults->hits[0]->metadata)->not->toHaveProperty('checkedOutBy');

});

test('throws exception when trying to login with incorrect password', function () {
Config::set('woodwing-assets.username', 'foobar');
Config::set('woodwing-assets.password', 'foobar');
Expand Down

0 comments on commit 206eb31

Please sign in to comment.