Skip to content

Commit 8485afb

Browse files
committed
feat: improve role pagination and add sorting tests
1 parent e868439 commit 8485afb

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

contexts/Authorization/Application/Coordinators/RoleCoordinator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ public function getRoleList(GetRoleListDTO $data): LengthAwarePaginator
5555
new GlobalPermissionPolicy('role.list'),
5656
])->check();
5757

58-
return $this->repository->paginate($data->currentPage, $data->perPage, $data->toCriteria(), $data->toSorting());
58+
return $this->repository->paginate(
59+
$data->currentPage,
60+
$data->perPage,
61+
$data->toCriteria(),
62+
$data->toSorting()
63+
);
5964
}
6065

6166
public function updateRole(int $id, UpdateRoleDTO $data): Role

contexts/Authorization/Infrastructure/Records/RoleRecord.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Contexts\Shared\Infrastructure\Traits\HasSortingScopeTrait;
1414
use Illuminate\Database\Eloquent\Builder;
1515
use Illuminate\Database\Eloquent\Factories\Factory;
16+
use Illuminate\Database\Eloquent\Factories\HasFactory;
1617
use Illuminate\Support\Carbon;
1718

1819
/**
@@ -24,6 +25,7 @@
2425
*/
2526
class RoleRecord extends BaseRecord
2627
{
28+
use HasFactory;
2729
use HasSortingScopeTrait;
2830

2931
protected $table = 'roles';

contexts/Authorization/Tests/Feature/RoleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@
8080
$responseIds = collect($response->json('data'))->pluck('id')->all();
8181
$sortedIds = collect($responseIds)->sort()->values()->all();
8282
expect($responseIds)->toBe($sortedIds);
83+
84+
$response = $this->get('users?sorting=[{"id":"id","desc":true}]');
85+
$response->assertStatus(200);
86+
87+
$responseIds = collect($response->json('data'))->pluck('id')->all();
88+
$sortedIds = collect($responseIds)->sortDesc()->values()->all();
89+
expect($responseIds)->toBe($sortedIds);
8390
});
8491

8592
it('can search for roles via api', function () {

0 commit comments

Comments
 (0)