|
1 | 1 | <?php
|
2 | 2 |
|
| 3 | +use FiveamCode\LaravelNotionApi\Entities\Entity; |
3 | 4 | use FiveamCode\LaravelNotionApi\Entities\NotionParent;
|
| 5 | +use FiveamCode\LaravelNotionApi\Entities\User; |
4 | 6 | use Illuminate\Support\Facades\Http;
|
5 | 7 |
|
6 | 8 | $httpRecorder = null;
|
|
73 | 75 | expect($pageParent)->toBeInstanceOf(\FiveamCode\LaravelNotionApi\Entities\Page::class);
|
74 | 76 | expect($pageParent->getId())->toBe('d946d011-966d-4b14-973f-dc5580f5b024');
|
75 | 77 | 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'); |
76 | 83 | });
|
77 | 84 |
|
78 | 85 | it('should throw a handling exception when unknown parent type', function () {
|
79 | 86 | expect(fn () => new NotionParent(['object' => 'unknown', 'id' => '1234']))->toThrow('invalid json-array: the given object is not a valid parent');
|
80 | 87 | });
|
81 | 88 |
|
| 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 | + |
82 | 94 | it('should resolve the pages of a database relation', function () {
|
83 | 95 | $page = Notion::pages()->find('1c56e2ad3d95458c935dae6d57769037');
|
84 | 96 |
|
|
91 | 103 | expect($relationPages->first()->getId())->toBe('cfb10a19-30cc-43a9-8db0-04c43f8cf315');
|
92 | 104 | expect($relationPages->first()->getTitle())->toBe('test 1');
|
93 | 105 | });
|
| 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