From 3ea3730f689c186a3884ef4b32854b5a8b37b0b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20S=2E=20Campos?= Date: Sat, 2 Dec 2023 19:28:30 -0500 Subject: [PATCH] feature: install spatie/laravel-json-api-paginate --- composer.json | 1 + composer.lock | 69 +++++++++++- config/json-api-paginate.php | 58 ++++++++++ .../Controllers/PublicQuotesController.php | 4 +- .../Queries/PublicQuoteIndexQuery.php | 1 + .../Quotes/Controllers/QuoteController.php | 4 +- .../Api/Quotes/Queries/IndexQuoteQuery.php | 1 + .../Ratings/Controllers/RatingController.php | 4 +- .../Api/Ratings/Queries/RatingIndexQuery.php | 1 + .../Api/Users/Controllers/UserController.php | 4 +- src/App/Api/Users/Queries/UserIndexQuery.php | 3 +- .../Controllers/ActivityController.php | 4 +- .../Users/Controllers/UserController.php | 4 +- .../ApiAdmin/Users/Queries/UserIndexQuery.php | 3 +- .../Web/Quotes/Queries/QuoteIndexQuery.php | 3 +- .../Api/PublicQuotes/IndexPublicQuoteTest.php | 101 +++++++++++++++--- tests/Feature/Api/Quotes/IndexQuoteTest.php | 2 +- .../Feature/Api/Ratings/IndexRatingsTest.php | 2 +- .../Api/Users/IndexUserControllerTest.php | 2 +- .../IndexActivityControllerTest.php | 4 +- .../Feature/ApiAdmin/Users/IndexUserTest.php | 2 +- 21 files changed, 248 insertions(+), 29 deletions(-) create mode 100644 config/json-api-paginate.php diff --git a/composer.json b/composer.json index a95c9ee..3debc99 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "rebing/graphql-laravel": "^9.1", "spatie/laravel-activitylog": "^4.7", "spatie/laravel-data": "^2.1", + "spatie/laravel-json-api-paginate": "^1.13", "spatie/laravel-model-states": "^2.3", "spatie/laravel-permission": "^5.9", "spatie/laravel-query-builder": "5.1.2", diff --git a/composer.lock b/composer.lock index 8baebb5..f68dec5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e878775ce451412fdc9a259532bc3b61", + "content-hash": "c7d64a8db14fa3038ac9da8df4753197", "packages": [ { "name": "aws/aws-crt-php", @@ -5761,6 +5761,71 @@ ], "time": "2023-01-24T08:23:58+00:00" }, + { + "name": "spatie/laravel-json-api-paginate", + "version": "1.13.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-json-api-paginate.git", + "reference": "e3cc9b9505e998da312ea87570e215ecd40a005b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-json-api-paginate/zipball/e3cc9b9505e998da312ea87570e215ecd40a005b", + "reference": "e3cc9b9505e998da312ea87570e215ecd40a005b", + "shasum": "" + }, + "require": { + "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0", + "php": "^7.3|^8.0" + }, + "require-dev": { + "orchestra/testbench": "^4.0|^5.0|^6.0|^7.0|^8.0", + "pestphp/pest": "^1.22", + "phpunit/phpunit": "^8.0|^9.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\JsonApiPaginate\\JsonApiPaginateServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Spatie\\JsonApiPaginate\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "A paginator that plays nice with the JSON API spec", + "homepage": "https://github.com/spatie/laravel-json-api-paginate", + "keywords": [ + "laravel-json-api-paginate", + "spatie" + ], + "support": { + "source": "https://github.com/spatie/laravel-json-api-paginate/tree/1.13.0" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + } + ], + "time": "2023-03-27T13:33:07+00:00" + }, { "name": "spatie/laravel-model-states", "version": "2.6.0", @@ -15267,5 +15332,5 @@ "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/config/json-api-paginate.php b/config/json-api-paginate.php new file mode 100644 index 0000000..f4ba1b0 --- /dev/null +++ b/config/json-api-paginate.php @@ -0,0 +1,58 @@ + 50, + + /* + * The default number of results that will be returned + * when using the JSON API paginator. + */ + 'default_size' => 20, + + /* + * The key of the page[x] query string parameter for page number. + */ + 'number_parameter' => 'number', + + /* + * The key of the page[x] query string parameter for page size. + */ + 'size_parameter' => 'size', + + /* + * The key of the page[x] query string parameter for cursor. + */ + 'cursor_parameter' => 'cursor', + + /* + * The name of the macro that is added to the Eloquent query builder. + */ + 'method_name' => 'jsonPaginate', + + /* + * If you only need to display Next and Previous links, you may use + * simple pagination to perform a more efficient query. + */ + 'use_simple_pagination' => false, + + /* + * If you want to use cursor pagination, set this to true. + * This would override use_simple_pagination. + */ + 'use_cursor_pagination' => false, + + /* + * Here you can override the base url to be used in the link items. + */ + 'base_url' => null, + + /* + * The name of the query parameter used for pagination + */ + 'pagination_parameter' => 'page', +]; diff --git a/src/App/Api/PublicQuotes/Controllers/PublicQuotesController.php b/src/App/Api/PublicQuotes/Controllers/PublicQuotesController.php index fec1c29..ba760a2 100644 --- a/src/App/Api/PublicQuotes/Controllers/PublicQuotesController.php +++ b/src/App/Api/PublicQuotes/Controllers/PublicQuotesController.php @@ -19,7 +19,9 @@ class PublicQuotesController extends Controller */ public function index(PublicQuoteIndexQuery $quoteQuery): AnonymousResourceCollection { - $quotes = $quoteQuery->paginate(); + $quotes = $quoteQuery + ->jsonPaginate() + ->withQueryString(); return PublicQuoteResource::collection($quotes); } diff --git a/src/App/Api/PublicQuotes/Queries/PublicQuoteIndexQuery.php b/src/App/Api/PublicQuotes/Queries/PublicQuoteIndexQuery.php index 366e6dc..70e0dc9 100644 --- a/src/App/Api/PublicQuotes/Queries/PublicQuoteIndexQuery.php +++ b/src/App/Api/PublicQuotes/Queries/PublicQuoteIndexQuery.php @@ -26,6 +26,7 @@ public function __construct(Request $request) $this->allowedFilters(['title', 'content', 'user_id']) ->allowedIncludes('user') + ->defaultSort('created_at') ->allowedSorts('id', 'title', 'created_at'); } } diff --git a/src/App/Api/Quotes/Controllers/QuoteController.php b/src/App/Api/Quotes/Controllers/QuoteController.php index 6d1d385..abf42f3 100644 --- a/src/App/Api/Quotes/Controllers/QuoteController.php +++ b/src/App/Api/Quotes/Controllers/QuoteController.php @@ -28,7 +28,9 @@ class QuoteController extends Controller */ public function index(IndexQuoteQuery $quoteQuery): AnonymousResourceCollection { - $quotes = $quoteQuery->paginate(); + $quotes = $quoteQuery + ->jsonPaginate() + ->withQueryString(); return QuoteResource::collection($quotes); } diff --git a/src/App/Api/Quotes/Queries/IndexQuoteQuery.php b/src/App/Api/Quotes/Queries/IndexQuoteQuery.php index c23751b..ad50ea2 100644 --- a/src/App/Api/Quotes/Queries/IndexQuoteQuery.php +++ b/src/App/Api/Quotes/Queries/IndexQuoteQuery.php @@ -29,6 +29,7 @@ public function __construct(Request $request) parent::__construct($query, $request); $this->allowedFilters(['title', 'content', 'state']) + ->defaultSort('created_at') ->allowedSorts('id', 'title', 'created_at'); } } diff --git a/src/App/Api/Ratings/Controllers/RatingController.php b/src/App/Api/Ratings/Controllers/RatingController.php index db18777..b1addea 100644 --- a/src/App/Api/Ratings/Controllers/RatingController.php +++ b/src/App/Api/Ratings/Controllers/RatingController.php @@ -28,7 +28,9 @@ class RatingController extends Controller */ public function index(RatingIndexQuery $quoteQuery): AnonymousResourceCollection { - $quotes = $quoteQuery->paginate(); + $quotes = $quoteQuery + ->jsonPaginate() + ->withQueryString(); return RatingResource::collection($quotes); } diff --git a/src/App/Api/Ratings/Queries/RatingIndexQuery.php b/src/App/Api/Ratings/Queries/RatingIndexQuery.php index aaec4ff..f04cb88 100644 --- a/src/App/Api/Ratings/Queries/RatingIndexQuery.php +++ b/src/App/Api/Ratings/Queries/RatingIndexQuery.php @@ -25,6 +25,7 @@ public function __construct(Request $request) $this->allowedFilters(['qualifier_type', 'rateable_type']) ->allowedIncludes(['qualifier', 'rateable']) + ->defaultSort('created_at') ->allowedSorts('id', 'created_at'); } } diff --git a/src/App/Api/Users/Controllers/UserController.php b/src/App/Api/Users/Controllers/UserController.php index b25e2b8..5cba766 100644 --- a/src/App/Api/Users/Controllers/UserController.php +++ b/src/App/Api/Users/Controllers/UserController.php @@ -19,7 +19,9 @@ class UserController extends Controller */ public function index(UserIndexQuery $userQuery): AnonymousResourceCollection { - $users = $userQuery->paginate(); + $users = $userQuery + ->jsonPaginate() + ->withQueryString(); return UserResource::collection($users); } diff --git a/src/App/Api/Users/Queries/UserIndexQuery.php b/src/App/Api/Users/Queries/UserIndexQuery.php index 37d6c99..28cd3ae 100644 --- a/src/App/Api/Users/Queries/UserIndexQuery.php +++ b/src/App/Api/Users/Queries/UserIndexQuery.php @@ -21,6 +21,7 @@ public function __construct(Request $request) $this->allowedFilters(['id', 'name']) ->allowedIncludes('quotes') - ->allowedSorts('id', 'name'); + ->defaultSort('created_at') + ->allowedSorts('id', 'name', 'created_at'); } } diff --git a/src/App/ApiAdmin/Activities/Controllers/ActivityController.php b/src/App/ApiAdmin/Activities/Controllers/ActivityController.php index 53ab35e..058a474 100644 --- a/src/App/ApiAdmin/Activities/Controllers/ActivityController.php +++ b/src/App/ApiAdmin/Activities/Controllers/ActivityController.php @@ -27,7 +27,9 @@ public function index(ActivityIndexQuery $activityQuery): AnonymousResourceColle { $this->authorize('viewAny', Activity::class); - $activities = $activityQuery->paginate(); + $activities = $activityQuery + ->jsonPaginate() + ->withQueryString(); return ActivityResource::collection($activities); } diff --git a/src/App/ApiAdmin/Users/Controllers/UserController.php b/src/App/ApiAdmin/Users/Controllers/UserController.php index 862f80f..4e2ad06 100644 --- a/src/App/ApiAdmin/Users/Controllers/UserController.php +++ b/src/App/ApiAdmin/Users/Controllers/UserController.php @@ -29,7 +29,9 @@ public function index(UserIndexQuery $userQuery): AnonymousResourceCollection { $this->authorize('viewAny', User::class); - $users = $userQuery->paginate(); + $users = $userQuery + ->jsonPaginate() + ->withQueryString(); return UserResource::collection($users); } diff --git a/src/App/ApiAdmin/Users/Queries/UserIndexQuery.php b/src/App/ApiAdmin/Users/Queries/UserIndexQuery.php index a7e4b51..a66860c 100644 --- a/src/App/ApiAdmin/Users/Queries/UserIndexQuery.php +++ b/src/App/ApiAdmin/Users/Queries/UserIndexQuery.php @@ -24,6 +24,7 @@ public function __construct(Request $request) $this->allowedFilters(['id', 'name', AllowedFilter::trashed()]) ->allowedIncludes(['permissions', 'roles']) - ->allowedSorts('id', 'name'); + ->defaultSort('created_at') + ->allowedSorts('id', 'name', 'created_at'); } } diff --git a/src/App/Web/Quotes/Queries/QuoteIndexQuery.php b/src/App/Web/Quotes/Queries/QuoteIndexQuery.php index c131c0a..e9c4163 100644 --- a/src/App/Web/Quotes/Queries/QuoteIndexQuery.php +++ b/src/App/Web/Quotes/Queries/QuoteIndexQuery.php @@ -19,6 +19,7 @@ public function __construct(Request $request) parent::__construct($query, $request); $this->allowedFilters(['title', 'content']) - ->allowedSorts('title'); + ->defaultSort('created_at') + ->allowedSorts('title', 'created_at'); } } diff --git a/tests/Feature/Api/PublicQuotes/IndexPublicQuoteTest.php b/tests/Feature/Api/PublicQuotes/IndexPublicQuoteTest.php index 0bfdff2..86be84e 100644 --- a/tests/Feature/Api/PublicQuotes/IndexPublicQuoteTest.php +++ b/tests/Feature/Api/PublicQuotes/IndexPublicQuoteTest.php @@ -7,10 +7,14 @@ use Illuminate\Support\Facades\DB; use Illuminate\Testing\Fluent\AssertableJson; use function Pest\Laravel\getJson; -use function PHPUnit\Framework\assertEquals; use function PHPUnit\Framework\assertLessThan; +/** + * Test chosen to test all query params as page[size], page[number] and metadata + */ beforeEach(function () { + config()->set('app.url', 'http://localhost'); + $this->user = User::factory()->create(); (new QuoteFactory)->setAmount(5)->withUser($this->user)->withState(Published::$name)->create(); @@ -21,17 +25,45 @@ it('can index', function () { getJson(route('api.public.quotes.index')) ->assertOk() - ->assertJsonStructure([ - 'data' => [ - '*' => ['id', 'title', 'content', 'state', 'average_rating', 'excerpt', 'created_at', 'updated_at']], - ]); + ->assertJson(function (AssertableJson $json) { + $json->has('data', 5) + ->has('data.0', function (AssertableJson $data) { + $data->whereAllType([ + 'id' => 'integer', + 'title' => 'string', + 'content' => 'string', + 'state' => 'string', + 'average_rating' => 'null', + 'excerpt' => 'string', + 'created_at' => 'string', + 'updated_at' => 'string', + ])->etc(); + }) + ->has('links', function (AssertableJson $links) { + $links->where('first', 'http://localhost/api/public/quotes?page%5Bnumber%5D=1') + ->where('last', 'http://localhost/api/public/quotes?page%5Bnumber%5D=1') + ->where('prev', null) + ->where('next', null); + }) + ->has('meta', function (AssertableJson $meta) { + $meta->where('current_page', 1) + ->where('from', 1) + ->where('last_page', 1) + ->has('links') + ->where('path', 'http://localhost/api/public/quotes') + ->where('per_page', 20) + ->where('to', 5) + ->where('total', 5); + }); + }); }); it('can filter by title', function () { /** @var Quote $quote */ - $quote = (new QuoteFactory)->withUser($this->user)->withState(Published::$name)->create([ - 'title' => 'Hamlet', - ]); + $quote = (new QuoteFactory) + ->withUser($this->user) + ->withState(Published::$name) + ->create(['title' => 'Hamlet']); getJson(route('api.public.quotes.index', ['filter[title]' => 'hamlet'])) ->assertJson(function (AssertableJson $json) use ($quote) { @@ -44,15 +76,19 @@ 'title' => 'string', ]) ->etc(); + }) + ->has('links', function (AssertableJson $links) { + $links->where('first', 'http://localhost/api/public/quotes?filter%5Btitle%5D=hamlet&page%5Bnumber%5D=1')->etc(); })->etc(); }); }); it('can filter by content', function () { /** @var Quote $quote */ - $quote = (new QuoteFactory)->withUser($this->user)->withState(Published::$name)->create([ - 'content' => 'Some text about something', - ]); + $quote = (new QuoteFactory) + ->withUser($this->user) + ->withState(Published::$name) + ->create(['content' => 'Some text about something']); getJson(route('api.public.quotes.index', ['filter[content]' => 'Some text about something'])) ->assertSuccessful() @@ -99,6 +135,9 @@ ->whereAllType([ 'user' => 'array', ])->etc(); + }) + ->has('links', function (AssertableJson $links) { + $links->where('first', 'http://localhost/api/public/quotes?include=user&page%5Bnumber%5D=1')->etc(); })->etc(); }); @@ -137,6 +176,44 @@ assertLessThan($responseDataTwo[0]['id'], $responseDataTwo[4]['id']); }); +it('can get by page size', function () { + (new QuoteFactory)->setAmount(5)->withUser($this->user)->withState(Published::$name)->create(); + + getJson(route('api.public.quotes.index', ['page[size]' => 5])) + ->assertOk() + ->assertJson(function (AssertableJson $json) { + $json->has('data', 5)->etc(); + }); + + getJson(route('api.public.quotes.index', ['page[size]' => 10])) + ->assertOk() + ->assertJson(function (AssertableJson $json) { + $json->has('data', 10)->etc(); + }); +}); + +it('can get by page number', function () { + (new QuoteFactory)->setAmount(18)->withUser($this->user)->withState(Published::$name)->create(); + + getJson(route('api.public.quotes.index', ['page[number]' => 1])) + ->assertOk() + ->assertJson(function (AssertableJson $json) { + $json->has('data', 20)->etc(); + }); + + getJson(route('api.public.quotes.index', ['page[number]' => 2])) + ->assertOk() + ->assertJson(function (AssertableJson $json) { + $json->has('data', 3)->etc(); + }); + + getJson(route('api.public.quotes.index', ['page' => 2])) // page is not valid param anymore + ->assertOk() + ->assertJson(function (AssertableJson $json) { + $json->has('data', 20)->etc(); + }); +}); + test('sql queries optimization test', function () { DB::enableQueryLog(); getJson(route('api.public.quotes.index'))->assertOk(); @@ -145,7 +222,7 @@ ->toHaveCount(2) ->sequence( fn ($query) => $query->toBe('select count(*) as aggregate from `quotes` where `state` = ?'), - fn ($query) => $query->toBe('select `id`, `title`, `content`, `state`, `average_score`, `user_id`, `created_at`, `updated_at` from `quotes` where `state` = ? limit 15 offset 0'), + fn ($query) => $query->toBe('select `id`, `title`, `content`, `state`, `average_score`, `user_id`, `created_at`, `updated_at` from `quotes` where `state` = ? order by `created_at` asc limit 20 offset 0'), ); DB::disableQueryLog(); diff --git a/tests/Feature/Api/Quotes/IndexQuoteTest.php b/tests/Feature/Api/Quotes/IndexQuoteTest.php index de9e54a..1e962da 100644 --- a/tests/Feature/Api/Quotes/IndexQuoteTest.php +++ b/tests/Feature/Api/Quotes/IndexQuoteTest.php @@ -125,7 +125,7 @@ ->toHaveCount(2) ->sequence( fn ($query) => $query->toBe('select count(*) as aggregate from `quotes` where `user_id` = ?'), - fn ($query) => $query->toBe('select `id`, `title`, `content`, `state`, `average_score`, `created_at`, `updated_at` from `quotes` where `user_id` = ? limit 15 offset 0'), + fn ($query) => $query->toBe('select `id`, `title`, `content`, `state`, `average_score`, `created_at`, `updated_at` from `quotes` where `user_id` = ? order by `created_at` asc limit 20 offset 0'), ); DB::disableQueryLog(); diff --git a/tests/Feature/Api/Ratings/IndexRatingsTest.php b/tests/Feature/Api/Ratings/IndexRatingsTest.php index 2b16663..b3cc54f 100644 --- a/tests/Feature/Api/Ratings/IndexRatingsTest.php +++ b/tests/Feature/Api/Ratings/IndexRatingsTest.php @@ -84,7 +84,7 @@ ->toHaveCount(2) ->sequence( fn ($query) => $query->toBe('select count(*) as aggregate from `ratings`'), - fn ($query) => $query->toBe('select `id`, `score`, `qualifier_id`, `qualifier_type`, `rateable_id`, `rateable_type`, `created_at`, `updated_at` from `ratings` limit 15 offset 0'), + fn ($query) => $query->toBe('select `id`, `score`, `qualifier_id`, `qualifier_type`, `rateable_id`, `rateable_type`, `created_at`, `updated_at` from `ratings` order by `created_at` asc limit 20 offset 0'), ); DB::disableQueryLog(); diff --git a/tests/Feature/Api/Users/IndexUserControllerTest.php b/tests/Feature/Api/Users/IndexUserControllerTest.php index 6e7bff2..d071d8f 100644 --- a/tests/Feature/Api/Users/IndexUserControllerTest.php +++ b/tests/Feature/Api/Users/IndexUserControllerTest.php @@ -108,7 +108,7 @@ ->toHaveCount(2) ->sequence( fn ($query) => $query->toBe('select count(*) as aggregate from `users` where `users`.`deleted_at` is null'), - fn ($query) => $query->toBe('select `id`, `name`, `email`, `created_at` from `users` where `users`.`deleted_at` is null limit 15 offset 0'), + fn ($query) => $query->toBe('select `id`, `name`, `email`, `created_at` from `users` where `users`.`deleted_at` is null order by `created_at` asc limit 20 offset 0'), ); DB::disableQueryLog(); diff --git a/tests/Feature/ApiAdmin/Activities/IndexActivityControllerTest.php b/tests/Feature/ApiAdmin/Activities/IndexActivityControllerTest.php index bd6554f..5c36d5c 100644 --- a/tests/Feature/ApiAdmin/Activities/IndexActivityControllerTest.php +++ b/tests/Feature/ApiAdmin/Activities/IndexActivityControllerTest.php @@ -72,10 +72,10 @@ fn ($query) => $query->toContain('select `roles`.*, `role_has_permissions`.`permission_id` as `pivot_permission_id`, `role_has_permissions`.`role_id` as `pivot_role_id` from `roles` inner join `role_has_permissions` on `roles`.`id` = `role_has_permissions`.`role_id` where `role_has_permissions`.`permission_id`'), fn ($query) => $query->toBe('select `permissions`.*, `model_has_permissions`.`model_id` as `pivot_model_id`, `model_has_permissions`.`permission_id` as `pivot_permission_id`, `model_has_permissions`.`model_type` as `pivot_model_type` from `permissions` inner join `model_has_permissions` on `permissions`.`id` = `model_has_permissions`.`permission_id` where `model_has_permissions`.`model_id` = ? and `model_has_permissions`.`model_type` = ?'), fn ($query) => $query->toBe('select count(*) as aggregate from `activity_log`'), - fn ($query) => $query->toBe('select `id`, `log_name`, `description`, `subject_type`, `subject_id`, `causer_type`, `causer_id`, `event`, `created_at`, `updated_at` from `activity_log` limit 15 offset 0'), + fn ($query) => $query->toBe('select `id`, `log_name`, `description`, `subject_type`, `subject_id`, `causer_type`, `causer_id`, `event`, `created_at`, `updated_at` from `activity_log` limit 20 offset 0'), // TODO: Validate cache in roles and permissions fn ($query) => $query->toBe('select count(*) as aggregate from `activity_log`'), - fn ($query) => $query->toBe('select `id`, `log_name`, `description`, `subject_type`, `subject_id`, `causer_type`, `causer_id`, `event`, `created_at`, `updated_at` from `activity_log` limit 15 offset 0'), + fn ($query) => $query->toBe('select `id`, `log_name`, `description`, `subject_type`, `subject_id`, `causer_type`, `causer_id`, `event`, `created_at`, `updated_at` from `activity_log` limit 20 offset 0'), ); DB::disableQueryLog(); diff --git a/tests/Feature/ApiAdmin/Users/IndexUserTest.php b/tests/Feature/ApiAdmin/Users/IndexUserTest.php index c6d5ad7..8875318 100644 --- a/tests/Feature/ApiAdmin/Users/IndexUserTest.php +++ b/tests/Feature/ApiAdmin/Users/IndexUserTest.php @@ -140,7 +140,7 @@ fn ($query) => $query->toContain('select `roles`.*, `role_has_permissions`.`permission_id` as `pivot_permission_id`, `role_has_permissions`.`role_id` as `pivot_role_id` from `roles` inner join `role_has_permissions` on `roles`.`id` = `role_has_permissions`.`role_id` where `role_has_permissions`.`permission_id` in'), fn ($query) => $query->toBe('select `permissions`.*, `model_has_permissions`.`model_id` as `pivot_model_id`, `model_has_permissions`.`permission_id` as `pivot_permission_id`, `model_has_permissions`.`model_type` as `pivot_model_type` from `permissions` inner join `model_has_permissions` on `permissions`.`id` = `model_has_permissions`.`permission_id` where `model_has_permissions`.`model_id` = ? and `model_has_permissions`.`model_type` = ?'), fn ($query) => $query->toBe('select count(*) as aggregate from `users` where `users`.`deleted_at` is null'), - fn ($query) => $query->toBe('select `id`, `name`, `email`, `deleted_at`, `created_at`, `updated_at` from `users` where `users`.`deleted_at` is null limit 15 offset 0'), + fn ($query) => $query->toBe('select `id`, `name`, `email`, `deleted_at`, `created_at`, `updated_at` from `users` where `users`.`deleted_at` is null order by `created_at` asc limit 20 offset 0'), ); DB::disableQueryLog();