|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -namespace Laracon\Inventory\Tests\Feature\Controllers; |
4 |
| - |
| 3 | +use Illuminate\Testing\Fluent\AssertableJson; |
5 | 4 | use Laracon\Inventory\Domain\Models\Product;
|
6 |
| -use Tests\TestCase; |
7 | 5 |
|
8 |
| -class ProductControllerTest extends TestCase |
9 |
| -{ |
10 |
| - /** @test */ |
11 |
| - public function index_returns_paginated_response() |
12 |
| - { |
13 |
| - Product::factory(30)->create(); |
| 6 | +use function Pest\Laravel\getJson; |
| 7 | + |
| 8 | +uses(Tests\TestCase::class); |
14 | 9 |
|
15 |
| - $response = $this->getJson('/products?page=2') |
16 |
| - ->assertStatus(200) |
17 |
| - ->assertJsonCount(10, 'data') |
18 |
| - ->assertJsonStructure([ |
19 |
| - 'data', |
20 |
| - 'links', |
21 |
| - 'meta' |
22 |
| - ])->decodeResponseJson(); |
| 10 | +test('index returns paginated response', function () { |
| 11 | + Product::factory(30)->create(); |
23 | 12 |
|
24 |
| - $meta = $response['meta']; |
25 |
| - $this->assertEquals(10, $meta['per_page']); |
26 |
| - $this->assertEquals(2, $meta['current_page']); |
27 |
| - $this->assertEquals(3, $meta['last_page']); |
28 |
| - $this->assertEquals(11, $meta['from']); |
29 |
| - $this->assertEquals(20, $meta['to']); |
30 |
| - $this->assertEquals(30, $meta['total']); |
31 |
| - } |
32 |
| -} |
| 13 | + getJson('/inventory-module/products?page=2') |
| 14 | + ->assertOk() |
| 15 | + ->assertJson(fn (AssertableJson $json) => |
| 16 | + $json->has('data', 10) |
| 17 | + ->has('links') |
| 18 | + ->has('meta') |
| 19 | + ->where('meta.per_page', 10) |
| 20 | + ->where('meta.current_page', 2) |
| 21 | + ->where('meta.last_page', 3) |
| 22 | + ->where('meta.from', 11) |
| 23 | + ->where('meta.to', 20) |
| 24 | + ->where('meta.total', 30) |
| 25 | + ); |
| 26 | +}); |
0 commit comments