Skip to content

Commit 0cbd9de

Browse files
committed
add additional tests for resolve endpoint
1 parent b01fc99 commit 0cbd9de

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/RecordedEndpointResolveTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3+
use FiveamCode\LaravelNotionApi\Entities\Entity;
34
use FiveamCode\LaravelNotionApi\Entities\NotionParent;
5+
use FiveamCode\LaravelNotionApi\Entities\User;
46
use Illuminate\Support\Facades\Http;
57

68
$httpRecorder = null;
@@ -73,12 +75,22 @@
7375
expect($pageParent)->toBeInstanceOf(\FiveamCode\LaravelNotionApi\Entities\Page::class);
7476
expect($pageParent->getId())->toBe('d946d011-966d-4b14-973f-dc5580f5b024');
7577
expect($pageParent->getTitle())->toBe('Page for Block Parent Resolve Testing');
78+
79+
$pageParent = Notion::resolve()->parentOf($block);
80+
expect($pageParent)->toBeInstanceOf(\FiveamCode\LaravelNotionApi\Entities\Page::class);
81+
expect($pageParent->getId())->toBe('d946d011-966d-4b14-973f-dc5580f5b024');
82+
expect($pageParent->getTitle())->toBe('Page for Block Parent Resolve Testing');
7683
});
7784

7885
it('should throw a handling exception when unknown parent type', function () {
7986
expect(fn () => new NotionParent(['object' => 'unknown', 'id' => '1234']))->toThrow('invalid json-array: the given object is not a valid parent');
8087
});
8188

89+
it('should throw a handling exception when entity without parent', function () {
90+
$entityWithoutParent = new User(['object' => 'user', 'id' => '1234']);
91+
expect(fn () => Notion::resolve()->parentOf($entityWithoutParent))->toThrow("The given entity 'user' does not have a parent.");
92+
});
93+
8294
it('should resolve the pages of a database relation', function () {
8395
$page = Notion::pages()->find('1c56e2ad3d95458c935dae6d57769037');
8496

@@ -91,3 +103,16 @@
91103
expect($relationPages->first()->getId())->toBe('cfb10a19-30cc-43a9-8db0-04c43f8cf315');
92104
expect($relationPages->first()->getTitle())->toBe('test 1');
93105
});
106+
107+
it('should resolve the page titles of a database relation', function () {
108+
$page = Notion::pages()->find('1c56e2ad3d95458c935dae6d57769037');
109+
110+
$relationPropertyItems = $page->getProperty('Parent Relation Database');
111+
$relationPageTitles = Notion::resolve()->relations($relationPropertyItems, true);
112+
113+
expect($relationPageTitles)->toBeInstanceOf(\Illuminate\Support\Collection::class);
114+
expect($relationPageTitles->count())->toBe(3);
115+
expect($relationPageTitles->first())->toBeString();
116+
expect($relationPageTitles->first())->toBe('test 1');
117+
});
118+

0 commit comments

Comments
 (0)