Skip to content

Commit b102261

Browse files
committed
added test for using model instance
1 parent e676d79 commit b102261

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/DatatableTest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
it('can get data with empty filters', function () {
88

99
$users = User::factory()->count(5)->create();
10-
1110
$query = User::query();
1211

1312
$requestParameters = [
@@ -29,6 +28,33 @@
2928
->toBe(5);
3029

3130

31+
});
32+
33+
it('can get data using model instance instead of query builder', function () {
34+
35+
$users = User::factory()->count(5)->create();
36+
37+
$userModel = new User();
38+
39+
$requestParameters = [
40+
'start' => 0,
41+
'size' => 10,
42+
'filters' => [],
43+
'sorting' => []
44+
];
45+
46+
$data = (new Datatable())->run(
47+
$userModel,
48+
$requestParameters
49+
);
50+
51+
expect($data['data'])
52+
->toEqual($users->toArray());
53+
54+
expect($data['meta']['totalRowCount'])
55+
->toBe(5);
56+
57+
3258
});
3359

3460
it('can get correct data with providing start and size arguments', function () {

0 commit comments

Comments
 (0)