Skip to content

Commit 5ab7650

Browse files
committed
Update TokenPaginatedResponse and add tests for pagination logic
1 parent 103c66a commit 5ab7650

2 files changed

Lines changed: 76 additions & 2 deletions

File tree

src/Responses/TokenPaginatedResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class TokenPaginatedResponse
2828
/**
2929
* The token for the next page.
3030
*
31-
* @var string
31+
* @var string|null
3232
*/
33-
protected string $nextPageToken;
33+
protected ?string $nextPageToken;
3434

3535
/**
3636
* Whether this is the last page.

tests/IssuesTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,4 +468,78 @@ public function it_should_throw_a_failed_action_exception_when_no_transition_is_
468468
// When
469469
$jira->updateIssueStatus('1', new IssueStatus(['id' => '999', 'name' => 'Unavailable Status']));
470470
}
471+
472+
#[Test]
473+
public function it_should_indicate_there_is_a_next_page_when_a_next_page_token_is_present()
474+
{
475+
// Given
476+
$jira = new Client(['clientId' => 1, 'clientSecret' => 'secret', 'redirectUrl' => 'none'], 'myorg', $this->token);
477+
478+
$jira->setClient($service = Mockery::mock('\GuzzleHttp\Client'));
479+
480+
$service->shouldReceive('request')
481+
->withArgs(function ($verb) {
482+
return $verb === 'GET';
483+
})
484+
->once()
485+
->andReturn(new Response(200, ['Content-Type' => 'application/json'], json_encode([
486+
'issues' => [$this->issue],
487+
'nextPageToken' => 'abc123',
488+
'isLast' => false,
489+
])));
490+
491+
$service->shouldReceive('request')
492+
->withArgs(function ($verb, $uri) {
493+
return $verb === 'POST' && $uri === 'search/approximate-count';
494+
})
495+
->once()
496+
->andReturn(new Response(200, ['Content-Type' => 'application/json'], json_encode([
497+
'count' => 10,
498+
])));
499+
500+
// When
501+
$issues = $jira->issues();
502+
503+
// Then
504+
$this->assertEquals('abc123', $issues->nextPageToken());
505+
$this->assertFalse($issues->isLastPage());
506+
$this->assertTrue($issues->hasNextPage());
507+
}
508+
509+
#[Test]
510+
public function it_should_indicate_the_last_page_when_is_last_is_true_even_with_a_next_page_token_present()
511+
{
512+
// Given
513+
$jira = new Client(['clientId' => 1, 'clientSecret' => 'secret', 'redirectUrl' => 'none'], 'myorg', $this->token);
514+
515+
$jira->setClient($service = Mockery::mock('\GuzzleHttp\Client'));
516+
517+
$service->shouldReceive('request')
518+
->withArgs(function ($verb) {
519+
return $verb === 'GET';
520+
})
521+
->once()
522+
->andReturn(new Response(200, ['Content-Type' => 'application/json'], json_encode([
523+
'issues' => [$this->issue],
524+
'nextPageToken' => 'abc123',
525+
'isLast' => true,
526+
])));
527+
528+
$service->shouldReceive('request')
529+
->withArgs(function ($verb, $uri) {
530+
return $verb === 'POST' && $uri === 'search/approximate-count';
531+
})
532+
->once()
533+
->andReturn(new Response(200, ['Content-Type' => 'application/json'], json_encode([
534+
'count' => 10,
535+
])));
536+
537+
// When
538+
$issues = $jira->issues();
539+
540+
// Then
541+
$this->assertEquals('abc123', $issues->nextPageToken());
542+
$this->assertTrue($issues->isLastPage());
543+
$this->assertFalse($issues->hasNextPage());
544+
}
471545
}

0 commit comments

Comments
 (0)