-
-
Notifications
You must be signed in to change notification settings - Fork 52
Feature/notion models and commands #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Draft
Changes from 25 commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
4f06203
very prototypical implementation for NotionModels
johguentner 1a52591
Apply fixes from StyleCI (#101)
mechelon 2ff9739
Merge branch 'dev' into feature/notion-models-and-commands
johguentner b828f88
Merge branch 'feature/notion-models-and-commands' of https://github.c...
johguentner bba2098
fix: after merge of filter-changes
johguentner c3d4b48
add the ability to resolve users and parents
johguentner 31bd869
Apply fixes from StyleCI (#115)
mechelon 27f4fe9
Merge branch 'dev' into feature/resolve
johguentner 9a3dbb3
fix: modify changed method within `NotionParent`
johguentner cf07ff9
add `asText` override to title and text property
johguentner 8c53b2a
polish notion model creation and usage
johguentner ea5cc25
Apply fixes from StyleCI (#120)
mechelon 9fe5ae3
Merge branch 'dev' into feature/notion-models-and-commands
johguentner 18240e4
Merge branch 'feature/notion-models-and-commands' of https://github.c...
johguentner bbaa2a9
fix: remove duplicated `asText`
johguentner 4cbdff9
Apply fixes from StyleCI (#122)
mechelon 911d8c6
polish: exclude `$page` of `NotionModel`
johguentner 99c2523
Merge branch 'feature/notion-models-and-commands' of https://github.c...
johguentner 516ccc7
Merge branch 'feature/resolve' into feature/notion-models-and-commands
johguentner f828d7d
Apply fixes from StyleCI (#123)
mechelon 3c9c845
add prototypical relation resolving
johguentner 0f180a9
Merge branch 'feature/resolve' into feature/notion-models-and-commands
johguentner 29c991a
Apply fixes from StyleCI (#124)
mechelon 27620d3
Apply fixes from StyleCI (#125)
mechelon c7a5bf2
create trait for title attribute
johguentner f19db04
add property type names within `Property::class`
johguentner 8963193
add comment for clarification
johguentner 29d56f5
add `HasTitle` traidMapping of `Entity::class`
johguentner 8356792
implementation: start with database-building
johguentner 0deaee7
Apply fixes from StyleCI (#134)
mechelon 44aee37
implement further and polish database creation
johguentner 766c7ab
Merge branch 'feature/database-creation' of https://github.com/5am-co...
johguentner 589455a
Apply fixes from StyleCI (#136)
mechelon 478f224
add further database attributes
johguentner b9f3eda
Merge branch 'feature/database-creation' of https://github.com/5am-co...
johguentner 667928e
Apply fixes from StyleCI (#137)
mechelon 85190f9
Merge branch 'dev' into feature/database-creation
johguentner 2e70438
fix: in `HttpRecorder`, allow query to be empty
johguentner f6c870d
fix: missing default name for status properties
johguentner 97be981
add tests for db creation in databases endpoint
johguentner 53c15fb
polish `PestHttpRecorder::class`
johguentner 2edd4ea
add query names to `RecordedEndpoint` tests
johguentner 039f8f9
update existing snapshots
johguentner ad5d85d
Apply fixes from StyleCI (#141)
mechelon 39d981d
add no-title-property test
johguentner 71416dc
update current snapshots (database creation)
johguentner 5ef1f93
Apply fixes from StyleCI (#142)
mechelon 04f9be6
Merge branch 'dev' into feature/database-creation
johguentner 68cb62f
Merge branch 'dev' into feature/resolve
johguentner fe961c8
add and polish phpdocs
johguentner fe0707c
Apply fixes from StyleCI (#144)
mechelon 1e4f0ff
Merge branch 'dev' into feature/resolve
johguentner 246396f
polish phpdocs of comment endpoint
johguentner d27f4ff
Apply fixes from StyleCI (#145)
mechelon 9a3730b
polish: add newline to improve readability
johguentner 69e15bd
Merge branch 'feature/resolve' of https://github.com/5am-code/laravel...
johguentner 55fe958
Apply fixes from StyleCI (#146)
mechelon 4244807
git
johguentner 2b11b70
add `parentOf` to access parents easily
johguentner a82ebeb
Apply fixes from StyleCI (#147)
mechelon eb7b39b
polish `PestHttpRecorder::class`
johguentner c83c9b1
Merge branch 'feature/resolve' of https://github.com/5am-code/laravel...
johguentner cd8116d
Apply fixes from StyleCI (#148)
mechelon e73207a
add tests for `Notion::resolve()`; polish record
johguentner 13a560d
build snapshots for resolve and
johguentner 1c27736
Merge branch 'feature/resolve' of https://github.com/5am-code/laravel...
johguentner 44626bb
Apply fixes from StyleCI (#152)
mechelon b01fc99
add simple phpdbg code coverage (cmd)
johguentner 0cbd9de
add additional tests for resolve endpoint
johguentner 1f6aa11
Apply fixes from StyleCI (#153)
mechelon 54f10a3
Merge branch 'feature/resolve' into feature/database-creation
johguentner a389879
add missing properties for database creation test
johguentner 9d2e153
updated snapshots (database creation)
johguentner fe76f73
Apply fixes from StyleCI (#154)
mechelon f3aa549
fix type for workspace in `NotionParent::class`
johguentner 7b7395b
add resolve/parent tests regarding NotionParent
johguentner 016009e
add snapshot for parent testing
johguentner f945728
Apply fixes from StyleCI (#155)
mechelon 4418da5
Merge branch 'feature/resolve' into feature/notion-models-and-commands
johguentner 8dff823
Merge branch 'feature/database-creation' into feature/notion-models-a...
johguentner 8f80b4a
move make-notion-model content to blade
johguentner 4a17d50
Apply fixes from StyleCI (#157)
mechelon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ vendor | |
| .phpunit.result.cache | ||
| coverage/ | ||
| .phpunit.cache/ | ||
| .env* | ||
| .env* | ||
| coverage-report | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
133 changes: 133 additions & 0 deletions
tests/RecordedEndpointResolveTest.php
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| <?php | ||
|
|
||
| use FiveamCode\LaravelNotionApi\Entities\NotionParent; | ||
| use FiveamCode\LaravelNotionApi\Entities\User; | ||
| use Illuminate\Support\Facades\Http; | ||
|
|
||
| $httpRecorder = null; | ||
|
|
||
| beforeEach(function () { | ||
| $this->httpRecorder = Http::recordAndFakeLater([ | ||
| 'https://api.notion.com/v1/databases*', | ||
| 'https://api.notion.com/v1/pages*', | ||
| 'https://api.notion.com/v1/blocks*', | ||
| 'https://api.notion.com/v1/users*', | ||
| ])->storeIn('snapshots/resolve'); | ||
| }); | ||
|
|
||
| it('should resolve the users of specific page properties', function () { | ||
| $this->httpRecorder->nameForNextRequest('for-user-resolve'); | ||
| $page = Notion::pages()->find('8890c263e97c45339ef5616d5e75360e'); | ||
|
|
||
| $createdBy = $page->getProperty('Created by'); | ||
| $lastEditedBy = $page->getProperty('Last edited by'); | ||
| $person = $page->getProperty('Person'); | ||
|
|
||
| $createdByUser = Notion::resolve()->user($createdBy->getUser()); | ||
| $lastEditedByUser = Notion::resolve()->user($lastEditedBy->getUser()); | ||
| $personUser = Notion::resolve()->user($person->getPeople()->first()); | ||
|
|
||
| expect($createdByUser)->toBeInstanceOf(\FiveamCode\LaravelNotionApi\Entities\User::class); | ||
| expect($createdByUser->getName())->toBe('TestUser for NotionForLaravel'); | ||
| expect($createdByUser->getId())->toBe('455aad58-7aec-4a39-8c0f-37cab3ca38f5'); | ||
|
|
||
| expect($lastEditedByUser)->toBeInstanceOf(\FiveamCode\LaravelNotionApi\Entities\User::class); | ||
| expect($lastEditedByUser->getName())->toBe('TestUser for NotionForLaravel'); | ||
| expect($lastEditedByUser->getId())->toBe('455aad58-7aec-4a39-8c0f-37cab3ca38f5'); | ||
|
|
||
| expect($personUser)->toBeInstanceOf(\FiveamCode\LaravelNotionApi\Entities\User::class); | ||
| expect($personUser->getName())->toBe('TestUser for NotionForLaravel'); | ||
| expect($personUser->getId())->toBe('455aad58-7aec-4a39-8c0f-37cab3ca38f5'); | ||
| }); | ||
|
|
||
| it('should resolve the page parent of a page', function () { | ||
| $page = Notion::pages()->find('a652fac351cc4cc79f5b17eb702793ed'); | ||
| $parentPage = Notion::resolve()->parent($page->getParent()); | ||
|
|
||
| expect($page->getParent()->isPage())->toBeTrue(); | ||
|
|
||
| expect($parentPage)->toBeInstanceOf(\FiveamCode\LaravelNotionApi\Entities\Page::class); | ||
| expect($parentPage->getId())->toBe('5ac149b9-d8f1-4d8d-ac05-facefc16ebf7'); | ||
| expect($parentPage->getTitle())->toBe('Resolve Endpoint - Testing Suite'); | ||
| }); | ||
|
|
||
| it('should return the workspace parent of a page without resolving it', function () { | ||
| $page = Notion::pages()->find('91f70932ee6347b59bc243e09b4cc9b0'); | ||
| $parentWorkspace = Notion::resolve()->parent($page->getParent()); | ||
|
|
||
| expect($page->getParent()->isWorkspace())->toBeTrue(); | ||
|
|
||
| expect($parentWorkspace)->toBeInstanceOf(NotionParent::class); | ||
| expect($parentWorkspace->getId())->toBe('1'); | ||
| expect($parentWorkspace->getObjectType())->toBe('workspace'); | ||
| }); | ||
|
|
||
| it('should resolve the database parent of a page', function () { | ||
| $page = Notion::pages()->find('415d9b6c6e454f42aab2b6e13804cfe9'); | ||
|
|
||
| expect($page->getParent()->isDatabase())->toBeTrue(); | ||
|
|
||
| $database = Notion::resolve()->parent($page->getParent()); | ||
| expect($database)->toBeInstanceOf(\FiveamCode\LaravelNotionApi\Entities\Database::class); | ||
| expect($database->getId())->toBe('8a0ef209-8c8a-4fd1-a21c-db7ab327e870'); | ||
| expect($database->getTitle())->toBe('Test Table as Parent'); | ||
| }); | ||
|
|
||
| it('should resolve the block parent of a block', function () { | ||
| $block = Notion::block('d5f9419b44204c909501b1e2b7569503')->retrieve(); | ||
|
|
||
| expect($block->getParent()->isBlock())->toBeTrue(); | ||
|
|
||
| $parentBlock = Notion::resolve()->parent($block->getParent()); | ||
| expect($parentBlock)->toBeInstanceOf(\FiveamCode\LaravelNotionApi\Entities\Blocks\Block::class); | ||
| expect($parentBlock->getId())->toBe('0971ac1a-b6f2-4acc-b706-f5f2ed16ffd6'); | ||
| expect($parentBlock->getType())->toBe('paragraph'); | ||
| }); | ||
|
|
||
| it('should resolve the page parent of a block', function () { | ||
| $block = Notion::block('0971ac1a-b6f2-4acc-b706-f5f2ed16ffd6')->retrieve(); | ||
|
|
||
| $pageParent = Notion::resolve()->parent($block->getParent()); | ||
| expect($pageParent)->toBeInstanceOf(\FiveamCode\LaravelNotionApi\Entities\Page::class); | ||
| expect($pageParent->getId())->toBe('d946d011-966d-4b14-973f-dc5580f5b024'); | ||
| expect($pageParent->getTitle())->toBe('Page for Block Parent Resolve Testing'); | ||
|
|
||
| $pageParent = Notion::resolve()->parentOf($block); | ||
| expect($pageParent)->toBeInstanceOf(\FiveamCode\LaravelNotionApi\Entities\Page::class); | ||
| expect($pageParent->getId())->toBe('d946d011-966d-4b14-973f-dc5580f5b024'); | ||
| expect($pageParent->getTitle())->toBe('Page for Block Parent Resolve Testing'); | ||
| }); | ||
|
|
||
| it('should throw a handling exception when unknown parent type', function () { | ||
| expect(fn () => new NotionParent(['object' => 'unknown', 'id' => '1234']))->toThrow('invalid json-array: the given object is not a valid parent'); | ||
| }); | ||
|
|
||
| it('should throw a handling exception when entity without parent', function () { | ||
| $entityWithoutParent = new User(['object' => 'user', 'id' => '1234']); | ||
| expect(fn () => Notion::resolve()->parentOf($entityWithoutParent))->toThrow("The given entity 'user' does not have a parent."); | ||
| }); | ||
|
|
||
| it('should resolve the pages of a database relation', function () { | ||
| $page = Notion::pages()->find('1c56e2ad3d95458c935dae6d57769037'); | ||
|
|
||
| $relationPropertyItems = $page->getProperty('Parent Relation Database'); | ||
| $relationPages = Notion::resolve()->relations($relationPropertyItems); | ||
|
|
||
| expect($relationPages)->toBeInstanceOf(\Illuminate\Support\Collection::class); | ||
| expect($relationPages->count())->toBe(3); | ||
| expect($relationPages->first())->toBeInstanceOf(\FiveamCode\LaravelNotionApi\Entities\Page::class); | ||
| expect($relationPages->first()->getId())->toBe('cfb10a19-30cc-43a9-8db0-04c43f8cf315'); | ||
| expect($relationPages->first()->getTitle())->toBe('test 1'); | ||
| }); | ||
|
|
||
| it('should resolve the page titles of a database relation', function () { | ||
| $page = Notion::pages()->find('1c56e2ad3d95458c935dae6d57769037'); | ||
|
|
||
| $relationPropertyItems = $page->getProperty('Parent Relation Database'); | ||
| $relationPageTitles = Notion::resolve()->relations($relationPropertyItems, true); | ||
|
|
||
| expect($relationPageTitles)->toBeInstanceOf(\Illuminate\Support\Collection::class); | ||
| expect($relationPageTitles->count())->toBe(3); | ||
| expect($relationPageTitles->first())->toBeString(); | ||
| expect($relationPageTitles->first())->toBe('test 1'); | ||
| }); |
13 changes: 13 additions & 0 deletions
...db4f2eac3db05446b8f5d9-page-size-100.json → ...ts/comments/get_v1-comments_1c611225.json
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.