|
4 | 4 |
|
5 | 5 | namespace Bavix\Wallet\Test\Units\Domain; |
6 | 6 |
|
| 7 | +use Bavix\Wallet\Internal\Service\DatabaseServiceInterface; |
| 8 | +use Bavix\Wallet\Models\Transaction; |
7 | 9 | use Bavix\Wallet\Test\Infra\Factories\BuyerFactory; |
8 | 10 | use Bavix\Wallet\Test\Infra\Models\Buyer; |
9 | 11 | use Bavix\Wallet\Test\Infra\TestCase; |
@@ -98,4 +100,35 @@ public function testTransferMeta(): void |
98 | 100 | self::assertSame(1, $credits1); |
99 | 101 | self::assertSame(1, $credits2); |
100 | 102 | } |
| 103 | + |
| 104 | + public function testPagination(): void |
| 105 | + { |
| 106 | + /** @var Buyer $buyer */ |
| 107 | + $buyer = BuyerFactory::new()->create(); |
| 108 | + $db = app(DatabaseServiceInterface::class); |
| 109 | + $db->transaction(function () use ($buyer): void { |
| 110 | + foreach (range(1, 21) as $item) { |
| 111 | + $buyer->deposit($item); |
| 112 | + } |
| 113 | + }); |
| 114 | + |
| 115 | + self::assertSame(21, $buyer->transactions()->count()); |
| 116 | + |
| 117 | + $query = Transaction::with('wallet') |
| 118 | + ->where('payable_id', $buyer->getKey()) |
| 119 | + ->orderBy('created_at', 'desc') |
| 120 | + ; |
| 121 | + |
| 122 | + $page1 = (clone $query)->paginate(10, page: 1); |
| 123 | + self::assertCount(10, $page1->items()); |
| 124 | + self::assertTrue($page1->hasMorePages()); |
| 125 | + |
| 126 | + $page2 = (clone $query)->paginate(10, page: 2); |
| 127 | + self::assertCount(10, $page2->items()); |
| 128 | + self::assertTrue($page2->hasMorePages()); |
| 129 | + |
| 130 | + $page3 = (clone $query)->paginate(10, page: 3); |
| 131 | + self::assertCount(1, $page3->items()); |
| 132 | + self::assertFalse($page3->hasMorePages()); |
| 133 | + } |
101 | 134 | } |
0 commit comments