Skip to content

Commit

Permalink
test: add test for ListDonation filtered by donor ID
Browse files Browse the repository at this point in the history
  • Loading branch information
David GABISON committed Aug 5, 2024
1 parent 73e8b5d commit b4f5184
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions tests/Unit/Donations/Endpoints/TestListDonations.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ public function testShouldReturnListWithSameSize()
$mockRequest->set_param('testMode', give_is_test_mode());

$listDonations = give(ListDonations::class);
$expectedItems = $this->getMockColumns($donations);

$response = $listDonations->handleRequest($mockRequest);

$this->assertSameSize($donations, $response->data['items']);
$this->assertSame($expectedItems, $response->data['items']);
}

/**
Expand All @@ -58,7 +59,39 @@ public function testShouldReturnListWithSameData()
$mockRequest->set_param('sortDirection', $sortDirection);
$mockRequest->set_param('testMode', give_is_test_mode());

$expectedItems = $this->getMockColumns($donations,$sortDirection);
$expectedItems = $this->getMockColumns($donations, $sortDirection);

$listDonations = give(ListDonations::class);

$response = $listDonations->handleRequest($mockRequest);

$this->assertSame($expectedItems, $response->data['items']);
}

/**
* @unreleased
*
* @return void
* @throws Exception
*/
public function testShouldReturnFilteredListByDonorId()
{
$donations = Donation::factory()->count(5)->create();
$donorId = $donations[0]->donorId;

$mockRequest = $this->getMockRequest();
// set_params
$mockRequest->set_param('page', 1);
$mockRequest->set_param('perPage', 30);
$mockRequest->set_param('locale', 'us-US');
$mockRequest->set_param('donor', (string)$donorId);
$mockRequest->set_param('testMode', give_is_test_mode());

$expectedItems = $this->getMockColumns(
array_filter($donations, function ($donation) use ($donorId) {
return $donation->donorId === $donorId;
})
);

$listDonations = give(ListDonations::class);

Expand Down

0 comments on commit b4f5184

Please sign in to comment.