Skip to content

Commit

Permalink
tests: add test for donations pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubersilva committed Jan 28, 2025
1 parent e22047b commit a2d2695
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion tests/Unit/Donations/Routes/GetDonationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,61 @@ class GetDonationsTest extends RestApiTestCase
{
use RefreshDatabase;

/**
* @unreleased
*
* @throws Exception
*/
public function testGetDonationsPagination()
{
Donation::query()->delete();

/** @var Donation $donation */
$donation1 = Donation::factory()->create();

/** @var Donation $donation */
$donation2 = Donation::factory()->create();

$route = '/' . DonationRoute::NAMESPACE . '/' . DonationRoute::DONATIONS;
$request = new WP_REST_Request(WP_REST_Server::READABLE, $route);

$request->set_query_params(
[
'page' => 1,
'per_page' => 1,
]
);
$response = $this->dispatchRequest($request);

$status = $response->get_status();
$data = $response->get_data();
$headers = $response->get_headers();

$this->assertEquals(200, $status);
$this->assertEquals(1, count($data));
$this->assertEquals($donation1->id, $data[0]->id);
$this->assertEquals(2, $headers['X-WP-Total']);
$this->assertEquals(2, $headers['X-WP-TotalPages']);

$request->set_query_params(
[
'page' => 2,
'per_page' => 1,
]
);
$response = $this->dispatchRequest($request);

$status = $response->get_status();
$data = $response->get_data();
$headers = $response->get_headers();

$this->assertEquals(200, $status);
$this->assertEquals(1, count($data));
$this->assertEquals($donation2->id, $data[0]->id);
$this->assertEquals(2, $headers['X-WP-Total']);
$this->assertEquals(2, $headers['X-WP-TotalPages']);
}

/**
* @unreleased
*
Expand All @@ -40,8 +95,8 @@ public function testGetDonationsByCampaignId()
'campaignId' => $campaign->id,
]
);

$response = $this->dispatchRequest($request);

$status = $response->get_status();
$data = $response->get_data();

Expand Down

0 comments on commit a2d2695

Please sign in to comment.