Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Endpoints/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,15 @@ public function filterBy(Collection $filter): Database
}

/**
* @param Collection|Sorting $sorts
* @param Collection|Sorting $sorts
* @return Database $this
*
* @throws HandlingException
*
*/
public function sortBy(Sorting|Collection $sorts): Database
{
$sortInstance = get_class($sorts);
switch($sortInstance) {
switch ($sortInstance) {
case Sorting::class:
$this->sorts->push($sorts);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/Query/Sorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function sortQuery(Sorting|Collection $sortings): array
{
$querySortings = new Collection();

if($sortings instanceof Collection) {
if ($sortings instanceof Collection) {
$sortings->each(function (Sorting $sorting) use ($querySortings) {
$querySortings->push($sorting->toArray());
});
Expand Down
1 change: 1 addition & 0 deletions tests/NotionApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use FiveamCode\LaravelNotionApi\NotionFacade;
use Illuminate\Support\Collection;
use Orchestra\Testbench\TestCase as Orchestra;

/**
* Class EndpointPageTest.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

use FiveamCode\LaravelNotionApi\Tests\NotionApiTest;

uses(NotionApiTest::class)->in(__DIR__);
uses(NotionApiTest::class)->in(__DIR__);
12 changes: 6 additions & 6 deletions tests/SortingTest.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php

use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
use FiveamCode\LaravelNotionApi\Query\Sorting;
use Illuminate\Support\Collection;

it('can sort by a single property', function () {
$expectedSortQuery = '[{"property":"Birth year","direction":"ascending"}]';

$sortBy = Sorting::propertySort("Birth year", "ascending");
$this->assertEquals($expectedSortQuery, json_encode(Sorting::sortQuery($sortBy)));});
$sortBy = Sorting::propertySort('Birth year', 'ascending');
$this->assertEquals($expectedSortQuery, json_encode(Sorting::sortQuery($sortBy)));
});

it('can sort by multiple properties', function () {
$expectedSortQuery = '[{"timestamp":"created_time","direction":"ascending"},{"property":"Birth year","direction":"ascending"}]';

$sortings = new Collection();

$sortings->add(Sorting::timestampSort("created_time", "ascending"));
$sortings->add(Sorting::propertySort("Birth year", "ascending"));
$sortings->add(Sorting::timestampSort('created_time', 'ascending'));
$sortings->add(Sorting::propertySort('Birth year', 'ascending'));

$this->assertEquals($expectedSortQuery, json_encode(Sorting::sortQuery($sortings)));
});
Expand All @@ -27,4 +27,4 @@
Notion::database('8284f3ff77e24d4a939d19459e4d6bdc')
->sortBy(new stdClass())
->query();
});
});