Skip to content

Commit b4f5184

Browse files
author
David GABISON
committed
test: add test for ListDonation filtered by donor ID
1 parent 73e8b5d commit b4f5184

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

tests/Unit/Donations/Endpoints/TestListDonations.php

+35-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ public function testShouldReturnListWithSameSize()
3333
$mockRequest->set_param('testMode', give_is_test_mode());
3434

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

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

39-
$this->assertSameSize($donations, $response->data['items']);
40+
$this->assertSame($expectedItems, $response->data['items']);
4041
}
4142

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

61-
$expectedItems = $this->getMockColumns($donations,$sortDirection);
62+
$expectedItems = $this->getMockColumns($donations, $sortDirection);
63+
64+
$listDonations = give(ListDonations::class);
65+
66+
$response = $listDonations->handleRequest($mockRequest);
67+
68+
$this->assertSame($expectedItems, $response->data['items']);
69+
}
70+
71+
/**
72+
* @unreleased
73+
*
74+
* @return void
75+
* @throws Exception
76+
*/
77+
public function testShouldReturnFilteredListByDonorId()
78+
{
79+
$donations = Donation::factory()->count(5)->create();
80+
$donorId = $donations[0]->donorId;
81+
82+
$mockRequest = $this->getMockRequest();
83+
// set_params
84+
$mockRequest->set_param('page', 1);
85+
$mockRequest->set_param('perPage', 30);
86+
$mockRequest->set_param('locale', 'us-US');
87+
$mockRequest->set_param('donor', (string)$donorId);
88+
$mockRequest->set_param('testMode', give_is_test_mode());
89+
90+
$expectedItems = $this->getMockColumns(
91+
array_filter($donations, function ($donation) use ($donorId) {
92+
return $donation->donorId === $donorId;
93+
})
94+
);
6295

6396
$listDonations = give(ListDonations::class);
6497

0 commit comments

Comments
 (0)