-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ghonijee/development
Update sorted by relation field & Pagination test
- Loading branch information
Showing
3 changed files
with
57 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
<?php | ||
|
||
use GhoniJee\DxAdapter\DxAdapter; | ||
use GhoniJee\DxAdapter\Models\TestComment; | ||
use GhoniJee\DxAdapter\Models\TestModel; | ||
use Illuminate\Http\Request; | ||
|
||
beforeEach(function () { | ||
$this->request = Request::create('/test'); | ||
}); | ||
|
||
test('can build query get data with pagination', function () { | ||
$sort = ['desc' => false, 'selector' => 'name']; | ||
test('can build query get data with pagination with sortBy', function () { | ||
$sort = ['desc' => false, 'selector' => 'comment']; | ||
|
||
$this->request->replace(['sort' => $sort, 'skip' => 2, "take" => 2]); | ||
|
||
$this->request->replace(['sort' => $sort]); | ||
$query = DxAdapter::for(TestComment::class, $this->request)->paginate(2); | ||
$queryExpectation = TestComment::orderBy('comment')->paginate(2); | ||
|
||
expect($this->request->all())->toHaveKey('page', 2); | ||
expect($query)->toEqual($queryExpectation); | ||
}); | ||
|
||
test('can build query get data with pagination', function () { | ||
$this->request->replace(['skip' => 2, "take" => 2]); | ||
|
||
$query = DxAdapter::for(TestModel::class, $this->request)->paginate(); | ||
$queryExpectation = TestModel::orderBy('name')->paginate(); | ||
$query = DxAdapter::for(TestComment::class, $this->request)->paginate(2); | ||
$queryExpectation = TestComment::paginate(2); | ||
|
||
expect($this->request->all())->toHaveKey('page', 2); | ||
expect($query)->toEqual($queryExpectation); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters