feat(purchase): add filtering for multiple statuses in purchase index and order by status then date
This commit is contained in:
@@ -1230,6 +1230,52 @@ class StorePurchaseTest extends TestCase
|
||||
->assertJsonPath('data.0.total', '100.00');
|
||||
}
|
||||
|
||||
public function test_purchase_index_filters_multiple_comma_separated_statuses_and_orders_by_status_ascending_then_date(): void
|
||||
{
|
||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||
$user = User::factory()->create();
|
||||
|
||||
$olderPaid = Purchase::query()->create([
|
||||
'tenant_codigo' => 'sonder',
|
||||
'user_id' => $user->id,
|
||||
'status' => Purchase::STATUS_PAID,
|
||||
'total' => '10.00',
|
||||
]);
|
||||
$newerInReview = Purchase::query()->create([
|
||||
'tenant_codigo' => 'sonder',
|
||||
'user_id' => $user->id,
|
||||
'status' => Purchase::STATUS_IN_REVIEW,
|
||||
'total' => '20.00',
|
||||
]);
|
||||
$newerPaid = Purchase::query()->create([
|
||||
'tenant_codigo' => 'sonder',
|
||||
'user_id' => $user->id,
|
||||
'status' => Purchase::STATUS_PAID,
|
||||
'total' => '30.00',
|
||||
]);
|
||||
Purchase::query()->create([
|
||||
'tenant_codigo' => 'sonder',
|
||||
'user_id' => $user->id,
|
||||
'status' => Purchase::STATUS_CANCELLED,
|
||||
'total' => '40.00',
|
||||
]);
|
||||
|
||||
$olderPaid->forceFill(['created_at' => now()->subDays(3)])->saveQuietly();
|
||||
$newerInReview->forceFill(['created_at' => now()])->saveQuietly();
|
||||
$newerPaid->forceFill(['created_at' => now()->subDay()])->saveQuietly();
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->getJson('/api/tenants/sonder/compras?status=paid,%20in_review,paid')
|
||||
->assertOk()
|
||||
->assertJsonCount(3, 'data')
|
||||
->assertJsonPath('data.0.id', $newerInReview->id)
|
||||
->assertJsonPath('data.0.status', Purchase::STATUS_IN_REVIEW)
|
||||
->assertJsonPath('data.1.id', $newerPaid->id)
|
||||
->assertJsonPath('data.1.status', Purchase::STATUS_PAID)
|
||||
->assertJsonPath('data.2.id', $olderPaid->id)
|
||||
->assertJsonPath('data.2.status', Purchase::STATUS_PAID);
|
||||
}
|
||||
|
||||
public function test_it_rejects_a_cart_from_another_user(): void
|
||||
{
|
||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||
|
||||
Reference in New Issue
Block a user