Skip to content

Commit

Permalink
start implementation of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johguentner committed May 5, 2024
1 parent 6a6ba49 commit 9ac1588
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Endpoints/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ public function property(string $propertyId): Property|EntityCollection
return new EntityCollection();
}

$type = $rawContent['results'][0]['type'];
$type = $rawContent['type'] ?? $rawContent['results'][0]['type'];

// if($type === 'rollup'){
// dd($rawContent['type']);
// }
// if($)
// dd("HI");

return match ($type) {
'people' => new UserCollection($rawContent),
default => new EntityCollection($rawContent)
// 'rollup' => new Collection
default => dd($rawContent) && new EntityCollection($rawContent)
};
}

Expand Down
14 changes: 14 additions & 0 deletions tests/RecordedEndpointPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use FiveamCode\LaravelNotionApi\Entities\Collections\EntityCollection;
use FiveamCode\LaravelNotionApi\Entities\Properties\Property;
use FiveamCode\LaravelNotionApi\Entities\Properties\Rollup;
use Illuminate\Support\Facades\Http;

$httpRecorder = null;
Expand All @@ -19,10 +20,23 @@

$propertyKeys = $databaseStructure->getProperties()->map(fn ($o) => $o->getTitle());

// dd($propertyKeys);

expect($propertyKeys)->toBeInstanceOf(\Illuminate\Support\Collection::class);
expect($propertyKeys)->toHaveCount(16);

// dd($propertyKeys);

foreach ($propertyKeys as $propertyKey) {
$id = $databaseStructure->getProperty($propertyKey)->getId();
$property = \Notion::page('f1884dca3885460e93f52bf4da7cce8e')->property($id);

match($propertyKey){
'Rollup' => dd($property->asCollection()) && expect($property->asCollection()->first())->toBeInstanceOf(Rollup::class),
// default => throw new \Exception('Unknown property key')
default => null
};

if ($propertyKey == 'Rollup' || $propertyKey == 'Person' || $propertyKey == 'Name') {
expect($property)->toBeInstanceOf(EntityCollection::class);
} else {
Expand Down

0 comments on commit 9ac1588

Please sign in to comment.