Skip to content

Commit

Permalink
Expiration in minutes can be passed in when creating a hold token
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Aug 31, 2018
1 parent 23d8775 commit fa9fb19
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/HoldTokens/HoldTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ public function __construct($client)
}

/**
* @param $expiresInMinutes int
* @return HoldToken
*/
public function create()
public function create($expiresInMinutes = null)
{
$res = $this->client->post('/hold-tokens');
$request = new \stdClass();
if (!is_null($expiresInMinutes)) {
$request->expiresInMinutes = $expiresInMinutes;
}
$res = $this->client->post('/hold-tokens', ['json' => $request]);
$json = \GuzzleHttp\json_decode($res->getBody());
$mapper = SeatsioJsonMapper::create();
return $mapper->map($json, new HoldToken());
Expand Down
20 changes: 19 additions & 1 deletion tests/HoldTokens/CreateHoldTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@

namespace Seatsio\HoldTokens;

use DateInterval;
use DateTime;
use Seatsio\SeatsioClientTest;

class CreateHoldTokenTest extends SeatsioClientTest
{

public function test()
{
$lowerBound = (new DateTime('UTC'))->add(new DateInterval('PT15M'));
$upperBound = (new DateTime('UTC'))->add(new DateInterval('PT16M'));

$holdToken = $this->seatsioClient->holdTokens->create();

self::assertNotEmpty($holdToken->holdToken);
self::assertNotEmpty($holdToken->expiresAt);
self::assertGreaterThanOrEqual($lowerBound, $holdToken->expiresAt);
self::assertLessThanOrEqual($upperBound, $holdToken->expiresAt);
}

public function testExpiresInMinutes()
{
$lowerBound = (new DateTime('UTC'))->add(new DateInterval('PT5M'));
$upperBound = (new DateTime('UTC'))->add(new DateInterval('PT6M'));

$holdToken = $this->seatsioClient->holdTokens->create(5);

self::assertNotEmpty($holdToken->holdToken);
self::assertGreaterThanOrEqual($lowerBound, $holdToken->expiresAt);
self::assertLessThanOrEqual($upperBound, $holdToken->expiresAt);
}

}
8 changes: 7 additions & 1 deletion tests/HoldTokens/UpdateHoldTokenExpirationDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@

namespace Seatsio\HoldTokens;

use DateInterval;
use DateTime;
use Seatsio\SeatsioClientTest;

class UpdateHoldTokenExpirationDateTest extends SeatsioClientTest
{

public function test()
{
$lowerBound = (new DateTime('UTC'))->add(new DateInterval('PT30M'));
$upperBound = (new DateTime('UTC'))->add(new DateInterval('PT31M'));

$holdToken = $this->seatsioClient->holdTokens->create();

$updatedHoldToken = $this->seatsioClient->holdTokens->expireInMinutes($holdToken->holdToken, 30);

self::assertEquals($holdToken->holdToken, $updatedHoldToken->holdToken);
self::assertNotEquals($holdToken->expiresAt, $updatedHoldToken->expiresAt);
self::assertGreaterThanOrEqual($lowerBound, $updatedHoldToken->expiresAt);
self::assertLessThanOrEqual($upperBound, $updatedHoldToken->expiresAt);
}

}

0 comments on commit fa9fb19

Please sign in to comment.