From 8f9837505a7d1e9cc8d125d6e0b3cbc962260557 Mon Sep 17 00:00:00 2001 From: johguentner Date: Fri, 21 Jul 2023 09:13:35 -0500 Subject: [PATCH 01/11] implementation for retreiving page property items - incl. some tests --- src/Endpoints/Page.php | 51 ++++++++++++++++++++++++++++ src/Entities/Properties/Property.php | 2 +- src/Macros/PestHttpRecorder.php | 10 +++--- src/Notion.php | 13 ++++++- tests/RecordedEndpointPageTest.php | 40 ++++++++++++++++++++++ 5 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 src/Endpoints/Page.php create mode 100644 tests/RecordedEndpointPageTest.php diff --git a/src/Endpoints/Page.php b/src/Endpoints/Page.php new file mode 100644 index 0000000..959a236 --- /dev/null +++ b/src/Endpoints/Page.php @@ -0,0 +1,51 @@ +pageId = $pageId; + } + + /** + * Retrieve a page property item + * + * @url https://api.notion.com/{version}/pages/{page_id}/properties/{property_id} [get] + * + * @reference https://developers.notion.com/reference/retrieve-a-page-property. + * + * @param string $propertyId + * @return Page + * + * @throws HandlingException + * @throws NotionException + */ + public function property(string $propertyId): Property + { + $response = $this->get( + $this->url(Endpoint::PAGES . '/' . $this->pageId . '/' . 'properties' . '/' . urlencode($propertyId)) + ); + + return Property::fromResponse( + propertyKey: null, + rawContent: $response->json() + ); + } +} diff --git a/src/Entities/Properties/Property.php b/src/Entities/Properties/Property.php index ed3cf44..396644b 100644 --- a/src/Entities/Properties/Property.php +++ b/src/Entities/Properties/Property.php @@ -166,7 +166,7 @@ public function getContent() * * @throws HandlingException */ - public static function fromResponse(string $propertyKey, $rawContent): Property + public static function fromResponse(?string $propertyKey, $rawContent): Property { $propertyClass = self::mapTypeToClass($rawContent['type']); $property = new $propertyClass($propertyKey); diff --git a/src/Macros/PestHttpRecorder.php b/src/Macros/PestHttpRecorder.php index ee0d064..f4452e7 100644 --- a/src/Macros/PestHttpRecorder.php +++ b/src/Macros/PestHttpRecorder.php @@ -14,7 +14,7 @@ class PestHttpRecorder public static function register() { Http::macro('recordAndFakeLater', function (array|string $urls = ['*']) { - if (! is_array($urls)) { + if (!is_array($urls)) { $urls = [$urls]; } @@ -71,16 +71,18 @@ public function handle(Request $request) $method = Str::lower($request->method()); $name = Str::slug(Str::replace('/', '-', $urlInfo['path'])); $payload = ($method === 'get') ? ($urlInfo['query'] ?? null) : $request->body(); - $queryName = array_pop($this->requestNames) ?? hash('adler32', $payload); + $queryName = array_pop($this->requestNames) ?? ($payload ? hash('adler32', $payload) : ''); - $fileName = "{$method}_{$name}_{$queryName}.json"; + if ($queryName != '') $queryName = '_' . $queryName; + + $fileName = "{$method}_{$name}{$queryName}.json"; $directoryPath = "tests/{$this->snapshotDirectory}"; $filePath = "{$directoryPath}/{$fileName}"; // filter out Notion API Token Header $header = Arr::except($header, ['Authorization']); - if ($forceRecording || ! File::exists($filePath)) { + if ($forceRecording || !File::exists($filePath)) { File::makeDirectory($directoryPath, 0744, true, true); $client = new Client(); diff --git a/src/Notion.php b/src/Notion.php index 9d8f7ba..e4ad88b 100644 --- a/src/Notion.php +++ b/src/Notion.php @@ -7,6 +7,7 @@ use FiveamCode\LaravelNotionApi\Endpoints\Database; use FiveamCode\LaravelNotionApi\Endpoints\Databases; use FiveamCode\LaravelNotionApi\Endpoints\Endpoint; +use FiveamCode\LaravelNotionApi\Endpoints\Page; use FiveamCode\LaravelNotionApi\Endpoints\Pages; use FiveamCode\LaravelNotionApi\Endpoints\Resolve; use FiveamCode\LaravelNotionApi\Endpoints\Search; @@ -152,6 +153,16 @@ public function pages(): Pages return new Pages($this); } + /** + * @return Page + * + * @throws HandlingException + */ + public function page(string $pageId): Page + { + return new Page($this, $pageId); + } + /** * @param string $blockId * @return Block @@ -227,7 +238,7 @@ public function getConnection(): ?PendingRequest */ public function checkValidVersion(string $version): void { - if (! $this->validVersions->contains($version)) { + if (!$this->validVersions->contains($version)) { throw HandlingException::instance('Invalid version for Notion-API endpoint', ['invalidVersion' => $version]); } } diff --git a/tests/RecordedEndpointPageTest.php b/tests/RecordedEndpointPageTest.php new file mode 100644 index 0000000..cc07b3e --- /dev/null +++ b/tests/RecordedEndpointPageTest.php @@ -0,0 +1,40 @@ +httpRecorder = Http::recordAndFakeLater([ + 'https://api.notion.com/v1/pages*', + 'https://api.notion.com/v1/databases*', + ])->storeIn('snapshots/page-property-items'); +}); + +it('should fetch specific property items of a page', function () { + + $this->httpRecorder->nameForNextRequest('database-for-properties'); + $databaseStructure = \Notion::databases()->find('cdd4befe814144f7b1eecb9c123bd4fb'); + + $propertyKeys = $databaseStructure->getProperties()->map(fn ($o) => $o->getTitle()); + + foreach ($propertyKeys as $propertyKey) { + try { + + if ($propertyKey == 'Rollup' || $propertyKey == 'Person' || $propertyKey == 'Name') continue; + $id = $databaseStructure->getProperty($propertyKey)->getId(); + $property = \Notion::page('f1884dca3885460e93f52bf4da7cce8e')->property($id); + + expect($property)->toBeInstanceOf(Property::class); + } catch (\Exception $e) { + // dd($id); + dd($propertyKey, $e->getMessage()); + } + } +}); From c9fe4c67cf2e619c1a7e16459b17b6d00a531f57 Mon Sep 17 00:00:00 2001 From: Di Date: Fri, 21 Jul 2023 09:13:52 -0500 Subject: [PATCH 02/11] Apply fixes from StyleCI (#165) --- src/Endpoints/Page.php | 9 ++++----- src/Macros/PestHttpRecorder.php | 8 +++++--- src/Notion.php | 2 +- tests/RecordedEndpointPageTest.php | 11 +++-------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/Endpoints/Page.php b/src/Endpoints/Page.php index 959a236..75b4749 100644 --- a/src/Endpoints/Page.php +++ b/src/Endpoints/Page.php @@ -12,7 +12,6 @@ */ class Page extends Endpoint { - /** * @var ?string */ @@ -25,12 +24,12 @@ public function __construct(Notion $notion, string $pageId) } /** - * Retrieve a page property item - * + * Retrieve a page property item. + * * @url https://api.notion.com/{version}/pages/{page_id}/properties/{property_id} [get] * * @reference https://developers.notion.com/reference/retrieve-a-page-property. - * + * * @param string $propertyId * @return Page * @@ -40,7 +39,7 @@ public function __construct(Notion $notion, string $pageId) public function property(string $propertyId): Property { $response = $this->get( - $this->url(Endpoint::PAGES . '/' . $this->pageId . '/' . 'properties' . '/' . urlencode($propertyId)) + $this->url(Endpoint::PAGES.'/'.$this->pageId.'/'.'properties'.'/'.urlencode($propertyId)) ); return Property::fromResponse( diff --git a/src/Macros/PestHttpRecorder.php b/src/Macros/PestHttpRecorder.php index f4452e7..cdc5266 100644 --- a/src/Macros/PestHttpRecorder.php +++ b/src/Macros/PestHttpRecorder.php @@ -14,7 +14,7 @@ class PestHttpRecorder public static function register() { Http::macro('recordAndFakeLater', function (array|string $urls = ['*']) { - if (!is_array($urls)) { + if (! is_array($urls)) { $urls = [$urls]; } @@ -73,7 +73,9 @@ public function handle(Request $request) $payload = ($method === 'get') ? ($urlInfo['query'] ?? null) : $request->body(); $queryName = array_pop($this->requestNames) ?? ($payload ? hash('adler32', $payload) : ''); - if ($queryName != '') $queryName = '_' . $queryName; + if ($queryName != '') { + $queryName = '_'.$queryName; + } $fileName = "{$method}_{$name}{$queryName}.json"; $directoryPath = "tests/{$this->snapshotDirectory}"; @@ -82,7 +84,7 @@ public function handle(Request $request) // filter out Notion API Token Header $header = Arr::except($header, ['Authorization']); - if ($forceRecording || !File::exists($filePath)) { + if ($forceRecording || ! File::exists($filePath)) { File::makeDirectory($directoryPath, 0744, true, true); $client = new Client(); diff --git a/src/Notion.php b/src/Notion.php index e4ad88b..8082671 100644 --- a/src/Notion.php +++ b/src/Notion.php @@ -238,7 +238,7 @@ public function getConnection(): ?PendingRequest */ public function checkValidVersion(string $version): void { - if (!$this->validVersions->contains($version)) { + if (! $this->validVersions->contains($version)) { throw HandlingException::instance('Invalid version for Notion-API endpoint', ['invalidVersion' => $version]); } } diff --git a/tests/RecordedEndpointPageTest.php b/tests/RecordedEndpointPageTest.php index cc07b3e..d869661 100644 --- a/tests/RecordedEndpointPageTest.php +++ b/tests/RecordedEndpointPageTest.php @@ -1,11 +1,6 @@ httpRecorder->nameForNextRequest('database-for-properties'); $databaseStructure = \Notion::databases()->find('cdd4befe814144f7b1eecb9c123bd4fb'); @@ -26,8 +20,9 @@ foreach ($propertyKeys as $propertyKey) { try { - - if ($propertyKey == 'Rollup' || $propertyKey == 'Person' || $propertyKey == 'Name') continue; + if ($propertyKey == 'Rollup' || $propertyKey == 'Person' || $propertyKey == 'Name') { + continue; + } $id = $databaseStructure->getProperty($propertyKey)->getId(); $property = \Notion::page('f1884dca3885460e93f52bf4da7cce8e')->property($id); From 6e7134187bf96e38c797537f2bfd4d5652d4dc1b Mon Sep 17 00:00:00 2001 From: johguentner Date: Tue, 6 Feb 2024 13:26:16 +0100 Subject: [PATCH 03/11] fix small tpyo --- src/Entities/Properties/People.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entities/Properties/People.php b/src/Entities/Properties/People.php index 12c57d0..b327d23 100644 --- a/src/Entities/Properties/People.php +++ b/src/Entities/Properties/People.php @@ -37,7 +37,7 @@ protected function fillFromRaw(): void { parent::fillFromRaw(); if (! is_array($this->rawContent)) { - throw HandlingException::instance('The property-type is people, however the raw data-structure does not reprecent this type (= array of items). Please check the raw response-data.'); + throw HandlingException::instance('The property-type is people, however the raw data-structure does not represent this type (= array of items). Please check the raw response-data.'); } $this->content = new Collection(); From c696191e21309bf8d9326708eaf9f675979b3518 Mon Sep 17 00:00:00 2001 From: johguentner Date: Tue, 6 Feb 2024 13:26:59 +0100 Subject: [PATCH 04/11] fix: ignore people outer layer of fetched rawdata for user --- src/Entities/Collections/UserCollection.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Entities/Collections/UserCollection.php b/src/Entities/Collections/UserCollection.php index f25f966..2e36ff5 100644 --- a/src/Entities/Collections/UserCollection.php +++ b/src/Entities/Collections/UserCollection.php @@ -14,6 +14,12 @@ protected function collectChildren(): void { $this->collection = new Collection(); foreach ($this->rawResults as $userChild) { + + //TODO: create a new type for 'people' (outer layer for user) + if($userChild['type'] === 'people') { + $userChild = $userChild['people']; + } + $this->collection->add(new User($userChild)); } } From 601b82da6a267502889cc062130d0461da80f942 Mon Sep 17 00:00:00 2001 From: johguentner Date: Tue, 6 Feb 2024 13:28:50 +0100 Subject: [PATCH 05/11] various polishes for the `Property::class` (base-)entity --- src/Entities/Properties/Property.php | 73 +++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/src/Entities/Properties/Property.php b/src/Entities/Properties/Property.php index 396644b..386081f 100644 --- a/src/Entities/Properties/Property.php +++ b/src/Entities/Properties/Property.php @@ -74,8 +74,22 @@ public function __construct(string $title = null) */ protected function setResponseData(array $responseData): void { - if (! Arr::exists($responseData, 'id')) { - throw HandlingException::instance('invalid json-array: no id provided'); + if (!Arr::exists($responseData, 'id')) { + throw HandlingException::instance('invalid json-array for property: no id provided'); + } + $this->responseData = $responseData; + $this->fillFromRaw(); + } + + /** + * @param array $responseData + * + * @throws HandlingException + */ + protected function setObjectResponseData(array $responseData): void + { + if (!Arr::exists($responseData, 'object') || !Arr::exists($responseData, 'id')) { + throw HandlingException::instance('invalid json-array for property: no object or id provided'); } $this->responseData = $responseData; $this->fillFromRaw(); @@ -90,9 +104,7 @@ protected function fillFromRaw(): void private function fillType(): void { - if (Arr::exists($this->responseData, 'type')) { - $this->type = $this->responseData['type']; - } + $this->type = self::extractType($this->responseData); } private function fillContent(): void @@ -100,6 +112,13 @@ private function fillContent(): void if (Arr::exists($this->responseData, $this->getType())) { $this->rawContent = $this->responseData[$this->getType()]; $this->content = $this->rawContent; + return; + } + + if (Arr::exists($this->responseData, 'object') && Arr::exists($this->responseData, $this->getObjectType())) { + $this->rawContent = $this->responseData[$this->getObjectType()]; + $this->content = $this->rawContent; + return; } } @@ -166,7 +185,7 @@ public function getContent() * * @throws HandlingException */ - public static function fromResponse(?string $propertyKey, $rawContent): Property + public static function fromResponse(?string $propertyKey, array $rawContent): Property { $propertyClass = self::mapTypeToClass($rawContent['type']); $property = new $propertyClass($propertyKey); @@ -176,6 +195,46 @@ public static function fromResponse(?string $propertyKey, $rawContent): Property return $property; } + /** + * @param string $id + * @param $rawContent + * @return Property + * + * @throws HandlingException + */ + public static function fromObjectResponse(string $id, array $rawContent): Property|EntityCollection + { + $propertyClass = self::mapTypeToClass(self::extractType($rawContent)); + $property = new $propertyClass(); + $rawContent['id'] = $id; + + $property->setObjectResponseData($rawContent); + + return $property; + } + + // private static function + + public static function extractType(array $rawContent) + { + if (Arr::exists($rawContent, 'type')) { + return $rawContent['type']; + } + + if ( + Arr::exists($rawContent, 'object') + && $rawContent['object'] == 'list' + && Arr::exists($rawContent, 'results') + && is_array($rawContent['results']) + && count($rawContent['results']) > 0 + && Arr::exists($rawContent['results'][0], 'type') + ) { + return $rawContent['results'][0]['type']; + } + + return null; + } + /** * Maps the type of a property to the corresponding package class by converting the type name. * @@ -205,7 +264,7 @@ private static function mapTypeToClass(string $type): string case 'relation': $class = str_replace('_', '', ucwords($type, '_')); - return 'FiveamCode\\LaravelNotionApi\\Entities\\Properties\\'.$class; + return 'FiveamCode\\LaravelNotionApi\\Entities\\Properties\\' . $class; case 'text': case 'rich_text': // TODO: Depending on the Notion API version. From 48648c24c192f8904ccee24f5f8e49fc3bb3c1f5 Mon Sep 17 00:00:00 2001 From: johguentner Date: Tue, 6 Feb 2024 13:30:58 +0100 Subject: [PATCH 06/11] add handling for paginated properties incl tests --- src/Endpoints/Page.php | 25 ++++++++++++++++++++----- tests/RecordedEndpointPageTest.php | 15 +++++++-------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/Endpoints/Page.php b/src/Endpoints/Page.php index 959a236..49aea19 100644 --- a/src/Endpoints/Page.php +++ b/src/Endpoints/Page.php @@ -2,6 +2,8 @@ namespace FiveamCode\LaravelNotionApi\Endpoints; +use FiveamCode\LaravelNotionApi\Entities\Collections\EntityCollection; +use FiveamCode\LaravelNotionApi\Entities\Collections\UserCollection; use FiveamCode\LaravelNotionApi\Entities\Properties\Property; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; use FiveamCode\LaravelNotionApi\Exceptions\NotionException; @@ -37,15 +39,28 @@ public function __construct(Notion $notion, string $pageId) * @throws HandlingException * @throws NotionException */ - public function property(string $propertyId): Property + public function property(string $propertyId): Property|EntityCollection { $response = $this->get( - $this->url(Endpoint::PAGES . '/' . $this->pageId . '/' . 'properties' . '/' . urlencode($propertyId)) + $this->url(Endpoint::PAGES . '/' . $this->pageId . '/' . 'properties' . '/' . rawurlencode(rawurldecode($propertyId))) ); - return Property::fromResponse( - propertyKey: null, - rawContent: $response->json() + $rawContent = $response->json(); + + if($rawContent['object'] === 'list'){ + if(count($rawContent['results']) === 0) return new EntityCollection(); + + $type = $rawContent['results'][0]['type']; + + return match($type){ + 'people' => new UserCollection($rawContent), + default => new EntityCollection($rawContent) + }; + } + + return Property::fromObjectResponse( + id: $propertyId, + rawContent: $rawContent ); } } diff --git a/tests/RecordedEndpointPageTest.php b/tests/RecordedEndpointPageTest.php index cc07b3e..814def8 100644 --- a/tests/RecordedEndpointPageTest.php +++ b/tests/RecordedEndpointPageTest.php @@ -2,7 +2,9 @@ use Carbon\Carbon; use FiveamCode\LaravelNotionApi\Entities\Collections\CommentCollection; +use FiveamCode\LaravelNotionApi\Entities\Collections\EntityCollection; use FiveamCode\LaravelNotionApi\Entities\Comment; +use FiveamCode\LaravelNotionApi\Entities\Entity; use FiveamCode\LaravelNotionApi\Entities\Properties\Property; use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; use FiveamCode\LaravelNotionApi\Exceptions\NotionException; @@ -25,16 +27,13 @@ $propertyKeys = $databaseStructure->getProperties()->map(fn ($o) => $o->getTitle()); foreach ($propertyKeys as $propertyKey) { - try { - - if ($propertyKey == 'Rollup' || $propertyKey == 'Person' || $propertyKey == 'Name') continue; - $id = $databaseStructure->getProperty($propertyKey)->getId(); - $property = \Notion::page('f1884dca3885460e93f52bf4da7cce8e')->property($id); + $id = $databaseStructure->getProperty($propertyKey)->getId(); + $property = \Notion::page('f1884dca3885460e93f52bf4da7cce8e')->property($id); + if ($propertyKey == 'Rollup' || $propertyKey == 'Person' || $propertyKey == 'Name') { + expect($property)->toBeInstanceOf(EntityCollection::class); + } else { expect($property)->toBeInstanceOf(Property::class); - } catch (\Exception $e) { - // dd($id); - dd($propertyKey, $e->getMessage()); } } }); From cc67cb01aa79ce05ce25d12b0d246456389c19c4 Mon Sep 17 00:00:00 2001 From: johguentner Date: Tue, 6 Feb 2024 13:31:28 +0100 Subject: [PATCH 07/11] rerun snapshots for optimized file-naming --- ... get_v1-blocks-0971ac1a-b6f2-4acc-b706-f5f2ed16ffd6.json} | 3 ++- ...n => get_v1-blocks-d5f9419b44204c909501b1e2b7569503.json} | 3 ++- ...t_v1-databases-8a0ef209-8c8a-4fd1-a21c-db7ab327e870.json} | 3 ++- ...> get_v1-pages-05b473e4-d38f-484b-a74b-d3273932e9b4.json} | 3 ++- ...on => get_v1-pages-1c56e2ad3d95458c935dae6d57769037.json} | 3 ++- ...on => get_v1-pages-415d9b6c6e454f42aab2b6e13804cfe9.json} | 3 ++- ...> get_v1-pages-5ac149b9-d8f1-4d8d-ac05-facefc16ebf7.json} | 5 +++-- ...on => get_v1-pages-91f70932ee6347b59bc243e09b4cc9b0.json} | 5 +++-- ...on => get_v1-pages-a652fac351cc4cc79f5b17eb702793ed.json} | 3 ++- ...> get_v1-pages-cfb10a19-30cc-43a9-8db0-04c43f8cf315.json} | 3 ++- ...> get_v1-pages-d946d011-966d-4b14-973f-dc5580f5b024.json} | 3 ++- ...> get_v1-pages-e226b338-0118-461d-a9ed-09c9a6f1e4e2.json} | 3 ++- ...> get_v1-users-455aad58-7aec-4a39-8c0f-37cab3ca38f5.json} | 3 ++- 13 files changed, 28 insertions(+), 15 deletions(-) rename tests/snapshots/resolve/{get_v1-blocks-0971ac1a-b6f2-4acc-b706-f5f2ed16ffd6_00000001.json => get_v1-blocks-0971ac1a-b6f2-4acc-b706-f5f2ed16ffd6.json} (95%) rename tests/snapshots/resolve/{get_v1-blocks-d5f9419b44204c909501b1e2b7569503_00000001.json => get_v1-blocks-d5f9419b44204c909501b1e2b7569503.json} (95%) rename tests/snapshots/resolve/{get_v1-databases-8a0ef209-8c8a-4fd1-a21c-db7ab327e870_00000001.json => get_v1-databases-8a0ef209-8c8a-4fd1-a21c-db7ab327e870.json} (96%) rename tests/snapshots/resolve/{get_v1-pages-05b473e4-d38f-484b-a74b-d3273932e9b4_00000001.json => get_v1-pages-05b473e4-d38f-484b-a74b-d3273932e9b4.json} (96%) rename tests/snapshots/resolve/{get_v1-pages-1c56e2ad3d95458c935dae6d57769037_00000001.json => get_v1-pages-1c56e2ad3d95458c935dae6d57769037.json} (96%) rename tests/snapshots/resolve/{get_v1-pages-415d9b6c6e454f42aab2b6e13804cfe9_00000001.json => get_v1-pages-415d9b6c6e454f42aab2b6e13804cfe9.json} (95%) rename tests/snapshots/resolve/{get_v1-pages-5ac149b9-d8f1-4d8d-ac05-facefc16ebf7_00000001.json => get_v1-pages-5ac149b9-d8f1-4d8d-ac05-facefc16ebf7.json} (93%) rename tests/snapshots/resolve/{get_v1-pages-91f70932ee6347b59bc243e09b4cc9b0_00000001.json => get_v1-pages-91f70932ee6347b59bc243e09b4cc9b0.json} (93%) rename tests/snapshots/resolve/{get_v1-pages-a652fac351cc4cc79f5b17eb702793ed_00000001.json => get_v1-pages-a652fac351cc4cc79f5b17eb702793ed.json} (95%) rename tests/snapshots/resolve/{get_v1-pages-cfb10a19-30cc-43a9-8db0-04c43f8cf315_00000001.json => get_v1-pages-cfb10a19-30cc-43a9-8db0-04c43f8cf315.json} (96%) rename tests/snapshots/resolve/{get_v1-pages-d946d011-966d-4b14-973f-dc5580f5b024_00000001.json => get_v1-pages-d946d011-966d-4b14-973f-dc5580f5b024.json} (95%) rename tests/snapshots/resolve/{get_v1-pages-e226b338-0118-461d-a9ed-09c9a6f1e4e2_00000001.json => get_v1-pages-e226b338-0118-461d-a9ed-09c9a6f1e4e2.json} (96%) rename tests/snapshots/resolve/{get_v1-users-455aad58-7aec-4a39-8c0f-37cab3ca38f5_00000001.json => get_v1-users-455aad58-7aec-4a39-8c0f-37cab3ca38f5.json} (88%) diff --git a/tests/snapshots/resolve/get_v1-blocks-0971ac1a-b6f2-4acc-b706-f5f2ed16ffd6_00000001.json b/tests/snapshots/resolve/get_v1-blocks-0971ac1a-b6f2-4acc-b706-f5f2ed16ffd6.json similarity index 95% rename from tests/snapshots/resolve/get_v1-blocks-0971ac1a-b6f2-4acc-b706-f5f2ed16ffd6_00000001.json rename to tests/snapshots/resolve/get_v1-blocks-0971ac1a-b6f2-4acc-b706-f5f2ed16ffd6.json index 6feb7cd..afdde4f 100644 --- a/tests/snapshots/resolve/get_v1-blocks-0971ac1a-b6f2-4acc-b706-f5f2ed16ffd6_00000001.json +++ b/tests/snapshots/resolve/get_v1-blocks-0971ac1a-b6f2-4acc-b706-f5f2ed16ffd6.json @@ -54,6 +54,7 @@ "href": null } ] - } + }, + "request_id": "71c3d068-5bf6-4bc9-8f03-1d28ac82bf59" } } \ No newline at end of file diff --git a/tests/snapshots/resolve/get_v1-blocks-d5f9419b44204c909501b1e2b7569503_00000001.json b/tests/snapshots/resolve/get_v1-blocks-d5f9419b44204c909501b1e2b7569503.json similarity index 95% rename from tests/snapshots/resolve/get_v1-blocks-d5f9419b44204c909501b1e2b7569503_00000001.json rename to tests/snapshots/resolve/get_v1-blocks-d5f9419b44204c909501b1e2b7569503.json index 66bc60c..0dacb71 100644 --- a/tests/snapshots/resolve/get_v1-blocks-d5f9419b44204c909501b1e2b7569503_00000001.json +++ b/tests/snapshots/resolve/get_v1-blocks-d5f9419b44204c909501b1e2b7569503.json @@ -54,6 +54,7 @@ "href": null } ] - } + }, + "request_id": "72a8be9c-d9ba-45c2-b14b-625c15bb4368" } } \ No newline at end of file diff --git a/tests/snapshots/resolve/get_v1-databases-8a0ef209-8c8a-4fd1-a21c-db7ab327e870_00000001.json b/tests/snapshots/resolve/get_v1-databases-8a0ef209-8c8a-4fd1-a21c-db7ab327e870.json similarity index 96% rename from tests/snapshots/resolve/get_v1-databases-8a0ef209-8c8a-4fd1-a21c-db7ab327e870_00000001.json rename to tests/snapshots/resolve/get_v1-databases-8a0ef209-8c8a-4fd1-a21c-db7ab327e870.json index 485076f..6f8644e 100644 --- a/tests/snapshots/resolve/get_v1-databases-8a0ef209-8c8a-4fd1-a21c-db7ab327e870_00000001.json +++ b/tests/snapshots/resolve/get_v1-databases-8a0ef209-8c8a-4fd1-a21c-db7ab327e870.json @@ -76,6 +76,7 @@ }, "url": "https:\/\/www.notion.so\/8a0ef2098c8a4fd1a21cdb7ab327e870", "public_url": null, - "archived": false + "archived": false, + "request_id": "eda62b6a-53a4-4c8c-8fc8-1cd636ec7a0f" } } \ No newline at end of file diff --git a/tests/snapshots/resolve/get_v1-pages-05b473e4-d38f-484b-a74b-d3273932e9b4_00000001.json b/tests/snapshots/resolve/get_v1-pages-05b473e4-d38f-484b-a74b-d3273932e9b4.json similarity index 96% rename from tests/snapshots/resolve/get_v1-pages-05b473e4-d38f-484b-a74b-d3273932e9b4_00000001.json rename to tests/snapshots/resolve/get_v1-pages-05b473e4-d38f-484b-a74b-d3273932e9b4.json index 21e6075..f6d8f97 100644 --- a/tests/snapshots/resolve/get_v1-pages-05b473e4-d38f-484b-a74b-d3273932e9b4_00000001.json +++ b/tests/snapshots/resolve/get_v1-pages-05b473e4-d38f-484b-a74b-d3273932e9b4.json @@ -69,6 +69,7 @@ } }, "url": "https:\/\/www.notion.so\/test-3-05b473e4d38f484ba74bd3273932e9b4", - "public_url": null + "public_url": null, + "request_id": "4f72d166-90f2-48fa-84a2-e90954ce3b07" } } \ No newline at end of file diff --git a/tests/snapshots/resolve/get_v1-pages-1c56e2ad3d95458c935dae6d57769037_00000001.json b/tests/snapshots/resolve/get_v1-pages-1c56e2ad3d95458c935dae6d57769037.json similarity index 96% rename from tests/snapshots/resolve/get_v1-pages-1c56e2ad3d95458c935dae6d57769037_00000001.json rename to tests/snapshots/resolve/get_v1-pages-1c56e2ad3d95458c935dae6d57769037.json index f2517d6..3cf29a2 100644 --- a/tests/snapshots/resolve/get_v1-pages-1c56e2ad3d95458c935dae6d57769037_00000001.json +++ b/tests/snapshots/resolve/get_v1-pages-1c56e2ad3d95458c935dae6d57769037.json @@ -75,6 +75,7 @@ } }, "url": "https:\/\/www.notion.so\/Origin-Relation-Page-1c56e2ad3d95458c935dae6d57769037", - "public_url": null + "public_url": null, + "request_id": "4f0dd018-73a2-4d99-9d5d-fce187da4dde" } } \ No newline at end of file diff --git a/tests/snapshots/resolve/get_v1-pages-415d9b6c6e454f42aab2b6e13804cfe9_00000001.json b/tests/snapshots/resolve/get_v1-pages-415d9b6c6e454f42aab2b6e13804cfe9.json similarity index 95% rename from tests/snapshots/resolve/get_v1-pages-415d9b6c6e454f42aab2b6e13804cfe9_00000001.json rename to tests/snapshots/resolve/get_v1-pages-415d9b6c6e454f42aab2b6e13804cfe9.json index d9436d9..4f8d859 100644 --- a/tests/snapshots/resolve/get_v1-pages-415d9b6c6e454f42aab2b6e13804cfe9_00000001.json +++ b/tests/snapshots/resolve/get_v1-pages-415d9b6c6e454f42aab2b6e13804cfe9.json @@ -64,6 +64,7 @@ } }, "url": "https:\/\/www.notion.so\/Child-Page-415d9b6c6e454f42aab2b6e13804cfe9", - "public_url": null + "public_url": null, + "request_id": "2d7abd6d-d63d-4447-aab3-8228fcc1d305" } } \ No newline at end of file diff --git a/tests/snapshots/resolve/get_v1-pages-5ac149b9-d8f1-4d8d-ac05-facefc16ebf7_00000001.json b/tests/snapshots/resolve/get_v1-pages-5ac149b9-d8f1-4d8d-ac05-facefc16ebf7.json similarity index 93% rename from tests/snapshots/resolve/get_v1-pages-5ac149b9-d8f1-4d8d-ac05-facefc16ebf7_00000001.json rename to tests/snapshots/resolve/get_v1-pages-5ac149b9-d8f1-4d8d-ac05-facefc16ebf7.json index 4099414..b8f3654 100644 --- a/tests/snapshots/resolve/get_v1-pages-5ac149b9-d8f1-4d8d-ac05-facefc16ebf7_00000001.json +++ b/tests/snapshots/resolve/get_v1-pages-5ac149b9-d8f1-4d8d-ac05-facefc16ebf7.json @@ -17,7 +17,7 @@ "object": "page", "id": "5ac149b9-d8f1-4d8d-ac05-facefc16ebf7", "created_time": "2023-05-03T00:06:00.000Z", - "last_edited_time": "2023-06-09T16:49:00.000Z", + "last_edited_time": "2023-06-09T19:08:00.000Z", "created_by": { "object": "user", "id": "04536682-603a-4531-a18f-4fa89fdfb4a8" @@ -64,6 +64,7 @@ } }, "url": "https:\/\/www.notion.so\/Resolve-Endpoint-Testing-Suite-5ac149b9d8f14d8dac05facefc16ebf7", - "public_url": null + "public_url": null, + "request_id": "f75801b5-3249-421b-8ed7-c221441bf37b" } } \ No newline at end of file diff --git a/tests/snapshots/resolve/get_v1-pages-91f70932ee6347b59bc243e09b4cc9b0_00000001.json b/tests/snapshots/resolve/get_v1-pages-91f70932ee6347b59bc243e09b4cc9b0.json similarity index 93% rename from tests/snapshots/resolve/get_v1-pages-91f70932ee6347b59bc243e09b4cc9b0_00000001.json rename to tests/snapshots/resolve/get_v1-pages-91f70932ee6347b59bc243e09b4cc9b0.json index 0c6e22e..ef3bf36 100644 --- a/tests/snapshots/resolve/get_v1-pages-91f70932ee6347b59bc243e09b4cc9b0_00000001.json +++ b/tests/snapshots/resolve/get_v1-pages-91f70932ee6347b59bc243e09b4cc9b0.json @@ -17,7 +17,7 @@ "object": "page", "id": "91f70932-ee63-47b5-9bc2-43e09b4cc9b0", "created_time": "2021-06-12T16:36:00.000Z", - "last_edited_time": "2023-05-03T00:06:00.000Z", + "last_edited_time": "2023-07-20T02:20:00.000Z", "created_by": { "object": "user", "id": "04536682-603a-4531-a18f-4fa89fdfb4a8" @@ -64,6 +64,7 @@ } }, "url": "https:\/\/www.notion.so\/Testing-Suite-Content-91f70932ee6347b59bc243e09b4cc9b0", - "public_url": null + "public_url": null, + "request_id": "6f4875cb-6ca3-4ecf-81f1-f5690de3d878" } } \ No newline at end of file diff --git a/tests/snapshots/resolve/get_v1-pages-a652fac351cc4cc79f5b17eb702793ed_00000001.json b/tests/snapshots/resolve/get_v1-pages-a652fac351cc4cc79f5b17eb702793ed.json similarity index 95% rename from tests/snapshots/resolve/get_v1-pages-a652fac351cc4cc79f5b17eb702793ed_00000001.json rename to tests/snapshots/resolve/get_v1-pages-a652fac351cc4cc79f5b17eb702793ed.json index df4f764..1e6e8e2 100644 --- a/tests/snapshots/resolve/get_v1-pages-a652fac351cc4cc79f5b17eb702793ed_00000001.json +++ b/tests/snapshots/resolve/get_v1-pages-a652fac351cc4cc79f5b17eb702793ed.json @@ -64,6 +64,7 @@ } }, "url": "https:\/\/www.notion.so\/Page-for-Page-Parent-Resolve-Testing-a652fac351cc4cc79f5b17eb702793ed", - "public_url": null + "public_url": null, + "request_id": "748fc4ad-fdc4-4896-ae98-2f679168c098" } } \ No newline at end of file diff --git a/tests/snapshots/resolve/get_v1-pages-cfb10a19-30cc-43a9-8db0-04c43f8cf315_00000001.json b/tests/snapshots/resolve/get_v1-pages-cfb10a19-30cc-43a9-8db0-04c43f8cf315.json similarity index 96% rename from tests/snapshots/resolve/get_v1-pages-cfb10a19-30cc-43a9-8db0-04c43f8cf315_00000001.json rename to tests/snapshots/resolve/get_v1-pages-cfb10a19-30cc-43a9-8db0-04c43f8cf315.json index cce5b53..65e33b9 100644 --- a/tests/snapshots/resolve/get_v1-pages-cfb10a19-30cc-43a9-8db0-04c43f8cf315_00000001.json +++ b/tests/snapshots/resolve/get_v1-pages-cfb10a19-30cc-43a9-8db0-04c43f8cf315.json @@ -69,6 +69,7 @@ } }, "url": "https:\/\/www.notion.so\/test-1-cfb10a1930cc43a98db004c43f8cf315", - "public_url": null + "public_url": null, + "request_id": "99a79ee6-c669-4dad-9cac-aaff7be5c1c2" } } \ No newline at end of file diff --git a/tests/snapshots/resolve/get_v1-pages-d946d011-966d-4b14-973f-dc5580f5b024_00000001.json b/tests/snapshots/resolve/get_v1-pages-d946d011-966d-4b14-973f-dc5580f5b024.json similarity index 95% rename from tests/snapshots/resolve/get_v1-pages-d946d011-966d-4b14-973f-dc5580f5b024_00000001.json rename to tests/snapshots/resolve/get_v1-pages-d946d011-966d-4b14-973f-dc5580f5b024.json index e71edcb..da4edd0 100644 --- a/tests/snapshots/resolve/get_v1-pages-d946d011-966d-4b14-973f-dc5580f5b024_00000001.json +++ b/tests/snapshots/resolve/get_v1-pages-d946d011-966d-4b14-973f-dc5580f5b024.json @@ -64,6 +64,7 @@ } }, "url": "https:\/\/www.notion.so\/Page-for-Block-Parent-Resolve-Testing-d946d011966d4b14973fdc5580f5b024", - "public_url": null + "public_url": null, + "request_id": "c58ad0da-1b15-42cb-b704-f4306322c616" } } \ No newline at end of file diff --git a/tests/snapshots/resolve/get_v1-pages-e226b338-0118-461d-a9ed-09c9a6f1e4e2_00000001.json b/tests/snapshots/resolve/get_v1-pages-e226b338-0118-461d-a9ed-09c9a6f1e4e2.json similarity index 96% rename from tests/snapshots/resolve/get_v1-pages-e226b338-0118-461d-a9ed-09c9a6f1e4e2_00000001.json rename to tests/snapshots/resolve/get_v1-pages-e226b338-0118-461d-a9ed-09c9a6f1e4e2.json index 5e245fd..2ba081b 100644 --- a/tests/snapshots/resolve/get_v1-pages-e226b338-0118-461d-a9ed-09c9a6f1e4e2_00000001.json +++ b/tests/snapshots/resolve/get_v1-pages-e226b338-0118-461d-a9ed-09c9a6f1e4e2.json @@ -69,6 +69,7 @@ } }, "url": "https:\/\/www.notion.so\/test-2-e226b3380118461da9ed09c9a6f1e4e2", - "public_url": null + "public_url": null, + "request_id": "d2cc1925-05e4-4631-9a6e-811690a2b80a" } } \ No newline at end of file diff --git a/tests/snapshots/resolve/get_v1-users-455aad58-7aec-4a39-8c0f-37cab3ca38f5_00000001.json b/tests/snapshots/resolve/get_v1-users-455aad58-7aec-4a39-8c0f-37cab3ca38f5.json similarity index 88% rename from tests/snapshots/resolve/get_v1-users-455aad58-7aec-4a39-8c0f-37cab3ca38f5_00000001.json rename to tests/snapshots/resolve/get_v1-users-455aad58-7aec-4a39-8c0f-37cab3ca38f5.json index 0d2daf2..46e5bed 100644 --- a/tests/snapshots/resolve/get_v1-users-455aad58-7aec-4a39-8c0f-37cab3ca38f5_00000001.json +++ b/tests/snapshots/resolve/get_v1-users-455aad58-7aec-4a39-8c0f-37cab3ca38f5.json @@ -21,6 +21,7 @@ "type": "person", "person": { "email": "testuser@5amco.de" - } + }, + "request_id": "0f768f61-2b53-46b7-a04a-32c3862edab3" } } \ No newline at end of file From c53c86d72f8b69cabfaf4374c6d0e1760fc6077d Mon Sep 17 00:00:00 2001 From: johguentner Date: Tue, 6 Feb 2024 13:31:53 +0100 Subject: [PATCH 08/11] create snapshots for the property endpoint --- ...ecb9c123bd4fb_database-for-properties.json | 228 ++++++++++++++++++ ...0e93f52bf4da7cce8e-properties-3b40y5b.json | 22 ++ ...460e93f52bf4da7cce8e-properties-3bjqz.json | 25 ++ ...0e93f52bf4da7cce8e-properties-5bb3b7b.json | 30 +++ ...60e93f52bf4da7cce8e-properties-5cqh60.json | 22 ++ ...460e93f52bf4da7cce8e-properties-ao7ba.json | 51 ++++ ...460e93f52bf4da7cce8e-properties-dm7bv.json | 23 ++ ...5460e93f52bf4da7cce8e-properties-dsfk.json | 38 +++ ...5460e93f52bf4da7cce8e-properties-erjn.json | 23 ++ ...60e93f52bf4da7cce8e-properties-ev5d3a.json | 28 +++ ...60e93f52bf4da7cce8e-properties-l3fc5b.json | 26 ++ ...85460e93f52bf4da7cce8e-properties-pkn.json | 23 ++ ...85460e93f52bf4da7cce8e-properties-pya.json | 23 ++ ...5460e93f52bf4da7cce8e-properties-rtnv.json | 27 +++ ...460e93f52bf4da7cce8e-properties-t40qq.json | 26 ++ ...460e93f52bf4da7cce8e-properties-title.json | 46 ++++ ...460e93f52bf4da7cce8e-properties-w3eqr.json | 22 ++ ...ages-f1884dca3885460e93f52bf4da7cce8e.json | 216 +++++++++++++++++ 18 files changed, 899 insertions(+) create mode 100644 tests/snapshots/page-property-items/get_v1-databases-cdd4befe814144f7b1eecb9c123bd4fb_database-for-properties.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-3b40y5b.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-3bjqz.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-5bb3b7b.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-5cqh60.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-ao7ba.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-dm7bv.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-dsfk.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-erjn.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-ev5d3a.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-l3fc5b.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-pkn.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-pya.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-rtnv.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-t40qq.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-title.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-w3eqr.json create mode 100644 tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e.json diff --git a/tests/snapshots/page-property-items/get_v1-databases-cdd4befe814144f7b1eecb9c123bd4fb_database-for-properties.json b/tests/snapshots/page-property-items/get_v1-databases-cdd4befe814144f7b1eecb9c123bd4fb_database-for-properties.json new file mode 100644 index 0000000..9173273 --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-databases-cdd4befe814144f7b1eecb9c123bd4fb_database-for-properties.json @@ -0,0 +1,228 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "database", + "id": "cdd4befe-8141-44f7-b1ee-cb9c123bd4fb", + "cover": null, + "icon": null, + "created_time": "2023-07-20T02:20:00.000Z", + "created_by": { + "object": "user", + "id": "04536682-603a-4531-a18f-4fa89fdfb4a8" + }, + "last_edited_by": { + "object": "user", + "id": "04536682-603a-4531-a18f-4fa89fdfb4a8" + }, + "last_edited_time": "2023-07-20T02:37:00.000Z", + "title": [ + { + "type": "text", + "text": { + "content": "Test", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "Test", + "href": null + } + ], + "description": [], + "is_inline": true, + "properties": { + "Created time": { + "id": ";@Y[", + "name": "Created time", + "type": "created_time", + "created_time": [] + }, + "Formula": { + "id": ";JqZ", + "name": "Formula", + "type": "formula", + "formula": { + "expression": "prop(\"Number\")" + } + }, + "Rollup": { + "id": "AO{a", + "name": "Rollup", + "type": "rollup", + "rollup": { + "rollup_property_name": "Name", + "relation_property_name": "Relation Table (For Test)", + "rollup_property_id": "title", + "relation_property_id": "t\\Xe", + "function": "show_original" + } + }, + "Multi-select": { + "id": "EV]:", + "name": "Multi-select", + "type": "multi_select", + "multi_select": { + "options": [ + { + "id": "c3ab655e-551b-446b-9232-284d4de68b34", + "name": "test", + "color": "green" + } + ] + } + }, + "Select": { + "id": "L?C[", + "name": "Select", + "type": "select", + "select": { + "options": [ + { + "id": "77ea5ae6-261e-4c6e-8b38-7a8a0c200ea0", + "name": "test", + "color": "green" + } + ] + } + }, + "Date": { + "id": "T@qq", + "name": "Date", + "type": "date", + "date": [] + }, + "URL": { + "id": "W>qr", + "name": "URL", + "type": "url", + "url": [] + }, + "Files & media": { + "id": "[B;{", + "name": "Files & media", + "type": "files", + "files": [] + }, + "Email": { + "id": "\\qH`", + "name": "Email", + "type": "email", + "email": [] + }, + "Person": { + "id": "dSFK", + "name": "Person", + "type": "people", + "people": [] + }, + "Checkbox": { + "id": "dm{v", + "name": "Checkbox", + "type": "checkbox", + "checkbox": [] + }, + "Number": { + "id": "eRJN", + "name": "Number", + "type": "number", + "number": { + "format": "number" + } + }, + "Phone": { + "id": "pKn~", + "name": "Phone", + "type": "phone_number", + "phone_number": [] + }, + "Last edited time": { + "id": "p~Ya", + "name": "Last edited time", + "type": "last_edited_time", + "last_edited_time": [] + }, + "Status": { + "id": "rTnV", + "name": "Status", + "type": "status", + "status": { + "options": [ + { + "id": "0fc5097a-2f00-41a5-95fb-ea07226adee2", + "name": "Not started", + "color": "default" + }, + { + "id": "539c1819-4ac4-4339-9ce7-4b6166a20416", + "name": "In progress", + "color": "blue" + }, + { + "id": "d8f79ee8-3cb8-4dd1-b850-28b541c45886", + "name": "Done", + "color": "green" + } + ], + "groups": [ + { + "id": "8c469bf2-d0d5-4774-ada2-3bbfa91297c5", + "name": "To-do", + "color": "gray", + "option_ids": [ + "0fc5097a-2f00-41a5-95fb-ea07226adee2" + ] + }, + { + "id": "4f0384e5-4313-4cde-aac5-d71fea8e2546", + "name": "In progress", + "color": "blue", + "option_ids": [ + "539c1819-4ac4-4339-9ce7-4b6166a20416" + ] + }, + { + "id": "5025c777-d32f-4577-b68d-6749161572f9", + "name": "Complete", + "color": "green", + "option_ids": [ + "d8f79ee8-3cb8-4dd1-b850-28b541c45886" + ] + } + ] + } + }, + "Name": { + "id": "title", + "name": "Name", + "type": "title", + "title": [] + } + }, + "parent": { + "type": "page_id", + "page_id": "827758e2-7a19-43a7-99d5-96ce582eaa7f" + }, + "url": "https:\/\/www.notion.so\/cdd4befe814144f7b1eecb9c123bd4fb", + "public_url": null, + "archived": false + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-3b40y5b.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-3b40y5b.json new file mode 100644 index 0000000..3ec50b9 --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-3b40y5b.json @@ -0,0 +1,22 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "created_time", + "id": "%3B%40Y%5B", + "created_time": "2023-07-20T02:20:00.000Z" + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-3bjqz.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-3bjqz.json new file mode 100644 index 0000000..b5685e9be --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-3bjqz.json @@ -0,0 +1,25 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "formula", + "id": "%3BJqZ", + "formula": { + "type": "number", + "number": 1234 + } + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-5bb3b7b.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-5bb3b7b.json new file mode 100644 index 0000000..d9a6918 --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-5bb3b7b.json @@ -0,0 +1,30 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "files", + "id": "%5BB%3B%7B", + "files": [ + { + "name": "notion.so", + "type": "external", + "external": { + "url": "notion.so" + } + } + ] + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-5cqh60.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-5cqh60.json new file mode 100644 index 0000000..428def7 --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-5cqh60.json @@ -0,0 +1,22 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "email", + "id": "%5CqH%60", + "email": "test@test.de" + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-ao7ba.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-ao7ba.json new file mode 100644 index 0000000..aae992b --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-ao7ba.json @@ -0,0 +1,51 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "list", + "next_cursor": null, + "has_more": false, + "results": [ + { + "object": "property_item", + "type": "title", + "id": "title", + "title": { + "type": "text", + "text": { + "content": "test", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "test", + "href": null + } + } + ], + "type": "rollup", + "rollup": { + "type": "array", + "array": [], + "function": "show_original" + } + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-dm7bv.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-dm7bv.json new file mode 100644 index 0000000..c8ce2d2 --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-dm7bv.json @@ -0,0 +1,23 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "checkbox", + "id": "dm%7Bv", + "checkbox": true, + "request_id": "c4076c1c-9a32-4782-90c6-4c8c473edc21" + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-dsfk.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-dsfk.json new file mode 100644 index 0000000..ecffe6e --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-dsfk.json @@ -0,0 +1,38 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "list", + "results": [ + { + "object": "property_item", + "type": "people", + "id": "dSFK", + "people": { + "object": "user", + "id": "455aad58-7aec-4a39-8c0f-37cab3ca38f5", + "name": "TestUser for NotionForLaravel", + "avatar_url": null, + "type": "person", + "person": { + "email": "testuser@5amco.de" + } + } + } + ], + "next_cursor": null, + "has_more": false + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-erjn.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-erjn.json new file mode 100644 index 0000000..40a3d4c --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-erjn.json @@ -0,0 +1,23 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "number", + "id": "eRJN", + "number": 1234, + "request_id": "2232f1fa-f6cb-4995-b3b5-270da6c555a3" + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-ev5d3a.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-ev5d3a.json new file mode 100644 index 0000000..cbce1c0 --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-ev5d3a.json @@ -0,0 +1,28 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "multi_select", + "id": "EV%5D%3A", + "multi_select": [ + { + "id": "c3ab655e-551b-446b-9232-284d4de68b34", + "name": "test", + "color": "green" + } + ] + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-l3fc5b.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-l3fc5b.json new file mode 100644 index 0000000..1e6bd27 --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-l3fc5b.json @@ -0,0 +1,26 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "select", + "id": "L%3FC%5B", + "select": { + "id": "77ea5ae6-261e-4c6e-8b38-7a8a0c200ea0", + "name": "test", + "color": "green" + } + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-pkn.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-pkn.json new file mode 100644 index 0000000..904b98a --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-pkn.json @@ -0,0 +1,23 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "phone_number", + "id": "pKn~", + "phone_number": "123456789", + "request_id": "d1a10a58-faa3-45ac-97c4-34c8e9347564" + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-pya.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-pya.json new file mode 100644 index 0000000..e855788 --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-pya.json @@ -0,0 +1,23 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "last_edited_time", + "id": "p~Ya", + "last_edited_time": "2023-07-20T02:37:00.000Z", + "request_id": "b3d8f803-8ac2-46b2-96ed-5c87dbc10a92" + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-rtnv.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-rtnv.json new file mode 100644 index 0000000..96cb219 --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-rtnv.json @@ -0,0 +1,27 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "status", + "id": "rTnV", + "status": { + "id": "0fc5097a-2f00-41a5-95fb-ea07226adee2", + "name": "Not started", + "color": "default" + }, + "request_id": "9df8d789-26f6-46c6-9038-06de23a20c69" + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-t40qq.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-t40qq.json new file mode 100644 index 0000000..c62896b --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-t40qq.json @@ -0,0 +1,26 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "date", + "id": "T%40qq", + "date": { + "start": "2023-07-19", + "end": null, + "time_zone": null + } + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-title.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-title.json new file mode 100644 index 0000000..d88dd84 --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-title.json @@ -0,0 +1,46 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "list", + "results": [ + { + "object": "property_item", + "type": "title", + "id": "title", + "title": { + "type": "text", + "text": { + "content": "Testpage", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "Testpage", + "href": null + } + } + ], + "next_cursor": null, + "has_more": false, + "request_id": "bff15ba9-7c9c-4f90-984b-42791c5a76cb" + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-w3eqr.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-w3eqr.json new file mode 100644 index 0000000..50c99ea --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e-properties-w3eqr.json @@ -0,0 +1,22 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "property_item", + "type": "url", + "id": "W%3Eqr", + "url": "notion.so" + } +} \ No newline at end of file diff --git a/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e.json b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e.json new file mode 100644 index 0000000..36ff6fc --- /dev/null +++ b/tests/snapshots/page-property-items/get_v1-pages-f1884dca3885460e93f52bf4da7cce8e.json @@ -0,0 +1,216 @@ +{ + "header": { + "User-Agent": [ + "GuzzleHttp\/7" + ], + "Host": [ + "api.notion.com" + ], + "Notion-Version": [ + "2021-05-13" + ] + }, + "method": "get", + "status": 200, + "payload": null, + "data": { + "object": "page", + "id": "f1884dca-3885-460e-93f5-2bf4da7cce8e", + "created_time": "2023-07-20T02:20:00.000Z", + "last_edited_time": "2023-07-20T02:37:00.000Z", + "created_by": { + "object": "user", + "id": "04536682-603a-4531-a18f-4fa89fdfb4a8" + }, + "last_edited_by": { + "object": "user", + "id": "04536682-603a-4531-a18f-4fa89fdfb4a8" + }, + "cover": null, + "icon": null, + "parent": { + "type": "database_id", + "database_id": "cdd4befe-8141-44f7-b1ee-cb9c123bd4fb" + }, + "archived": false, + "properties": { + "Created time": { + "id": ";@Y[", + "type": "created_time", + "created_time": "2023-07-20T02:20:00.000Z" + }, + "Formula": { + "id": ";JqZ", + "type": "formula", + "formula": { + "type": "number", + "number": 1234 + } + }, + "Rollup": { + "id": "AO{a", + "type": "rollup", + "rollup": { + "type": "array", + "array": [ + { + "type": "title", + "title": [ + { + "type": "text", + "text": { + "content": "test", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "test", + "href": null + } + ] + } + ], + "function": "show_original" + } + }, + "Multi-select": { + "id": "EV]:", + "type": "multi_select", + "multi_select": [ + { + "id": "c3ab655e-551b-446b-9232-284d4de68b34", + "name": "test", + "color": "green" + } + ] + }, + "Select": { + "id": "L?C[", + "type": "select", + "select": { + "id": "77ea5ae6-261e-4c6e-8b38-7a8a0c200ea0", + "name": "test", + "color": "green" + } + }, + "Date": { + "id": "T@qq", + "type": "date", + "date": { + "start": "2023-07-19", + "end": null, + "time_zone": null + } + }, + "URL": { + "id": "W>qr", + "type": "url", + "url": "notion.so" + }, + "Files & media": { + "id": "[B;{", + "type": "files", + "files": [ + { + "name": "notion.so", + "type": "external", + "external": { + "url": "notion.so" + } + } + ] + }, + "Email": { + "id": "\\qH`", + "type": "email", + "email": "test@test.de" + }, + "Person": { + "id": "dSFK", + "type": "people", + "people": [ + { + "object": "user", + "id": "455aad58-7aec-4a39-8c0f-37cab3ca38f5", + "name": "TestUser for NotionForLaravel", + "avatar_url": null, + "type": "person", + "person": { + "email": "testuser@5amco.de" + } + } + ] + }, + "Checkbox": { + "id": "dm{v", + "type": "checkbox", + "checkbox": true + }, + "Number": { + "id": "eRJN", + "type": "number", + "number": 1234 + }, + "Phone": { + "id": "pKn~", + "type": "phone_number", + "phone_number": "123456789" + }, + "Last edited time": { + "id": "p~Ya", + "type": "last_edited_time", + "last_edited_time": "2023-07-20T02:37:00.000Z" + }, + "Status": { + "id": "rTnV", + "type": "status", + "status": { + "id": "0fc5097a-2f00-41a5-95fb-ea07226adee2", + "name": "Not started", + "color": "default" + } + }, + "Relation Table (For Test)": { + "id": "t\\Xe", + "type": "relation", + "relation": [ + { + "id": "15e7d13c-ac20-48cf-959c-a82f5631e8b0" + } + ], + "has_more": false + }, + "Name": { + "id": "title", + "type": "title", + "title": [ + { + "type": "text", + "text": { + "content": "Testpage", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "Testpage", + "href": null + } + ] + } + }, + "url": "https:\/\/www.notion.so\/Testpage-f1884dca3885460e93f52bf4da7cce8e", + "public_url": null + } +} \ No newline at end of file From 6a6ba49d7ef7d3041047a55e16e1fe44e6fd7db2 Mon Sep 17 00:00:00 2001 From: Di Date: Tue, 6 Feb 2024 13:32:58 +0100 Subject: [PATCH 09/11] Apply fixes from StyleCI (#170) --- src/Endpoints/Page.php | 10 ++++++---- src/Entities/Collections/UserCollection.php | 3 +-- src/Entities/Properties/Property.php | 8 +++++--- tests/RecordedEndpointPageTest.php | 4 ---- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Endpoints/Page.php b/src/Endpoints/Page.php index 6918295..50278a6 100644 --- a/src/Endpoints/Page.php +++ b/src/Endpoints/Page.php @@ -41,17 +41,19 @@ public function __construct(Notion $notion, string $pageId) public function property(string $propertyId): Property|EntityCollection { $response = $this->get( - $this->url(Endpoint::PAGES . '/' . $this->pageId . '/' . 'properties' . '/' . rawurlencode(rawurldecode($propertyId))) + $this->url(Endpoint::PAGES.'/'.$this->pageId.'/'.'properties'.'/'.rawurlencode(rawurldecode($propertyId))) ); $rawContent = $response->json(); - if($rawContent['object'] === 'list'){ - if(count($rawContent['results']) === 0) return new EntityCollection(); + if ($rawContent['object'] === 'list') { + if (count($rawContent['results']) === 0) { + return new EntityCollection(); + } $type = $rawContent['results'][0]['type']; - return match($type){ + return match ($type) { 'people' => new UserCollection($rawContent), default => new EntityCollection($rawContent) }; diff --git a/src/Entities/Collections/UserCollection.php b/src/Entities/Collections/UserCollection.php index 2e36ff5..2f364a3 100644 --- a/src/Entities/Collections/UserCollection.php +++ b/src/Entities/Collections/UserCollection.php @@ -14,9 +14,8 @@ protected function collectChildren(): void { $this->collection = new Collection(); foreach ($this->rawResults as $userChild) { - //TODO: create a new type for 'people' (outer layer for user) - if($userChild['type'] === 'people') { + if ($userChild['type'] === 'people') { $userChild = $userChild['people']; } diff --git a/src/Entities/Properties/Property.php b/src/Entities/Properties/Property.php index 386081f..e86687b 100644 --- a/src/Entities/Properties/Property.php +++ b/src/Entities/Properties/Property.php @@ -74,7 +74,7 @@ public function __construct(string $title = null) */ protected function setResponseData(array $responseData): void { - if (!Arr::exists($responseData, 'id')) { + if (! Arr::exists($responseData, 'id')) { throw HandlingException::instance('invalid json-array for property: no id provided'); } $this->responseData = $responseData; @@ -88,7 +88,7 @@ protected function setResponseData(array $responseData): void */ protected function setObjectResponseData(array $responseData): void { - if (!Arr::exists($responseData, 'object') || !Arr::exists($responseData, 'id')) { + if (! Arr::exists($responseData, 'object') || ! Arr::exists($responseData, 'id')) { throw HandlingException::instance('invalid json-array for property: no object or id provided'); } $this->responseData = $responseData; @@ -112,12 +112,14 @@ private function fillContent(): void if (Arr::exists($this->responseData, $this->getType())) { $this->rawContent = $this->responseData[$this->getType()]; $this->content = $this->rawContent; + return; } if (Arr::exists($this->responseData, 'object') && Arr::exists($this->responseData, $this->getObjectType())) { $this->rawContent = $this->responseData[$this->getObjectType()]; $this->content = $this->rawContent; + return; } } @@ -264,7 +266,7 @@ private static function mapTypeToClass(string $type): string case 'relation': $class = str_replace('_', '', ucwords($type, '_')); - return 'FiveamCode\\LaravelNotionApi\\Entities\\Properties\\' . $class; + return 'FiveamCode\\LaravelNotionApi\\Entities\\Properties\\'.$class; case 'text': case 'rich_text': // TODO: Depending on the Notion API version. diff --git a/tests/RecordedEndpointPageTest.php b/tests/RecordedEndpointPageTest.php index f538425..5205111 100644 --- a/tests/RecordedEndpointPageTest.php +++ b/tests/RecordedEndpointPageTest.php @@ -1,10 +1,6 @@ Date: Sun, 5 May 2024 12:54:45 +0900 Subject: [PATCH 10/11] start implementation of tests --- src/Endpoints/Page.php | 11 +++++++++-- tests/RecordedEndpointPageTest.php | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Endpoints/Page.php b/src/Endpoints/Page.php index 50278a6..e2ea3c0 100644 --- a/src/Endpoints/Page.php +++ b/src/Endpoints/Page.php @@ -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) }; } diff --git a/tests/RecordedEndpointPageTest.php b/tests/RecordedEndpointPageTest.php index 5205111..e1b966a 100644 --- a/tests/RecordedEndpointPageTest.php +++ b/tests/RecordedEndpointPageTest.php @@ -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; @@ -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 { From 6beb946a5ea26616625d54be6cae9e72b7e0c67a Mon Sep 17 00:00:00 2001 From: Di Date: Sun, 5 May 2024 12:55:07 +0900 Subject: [PATCH 11/11] Apply fixes from StyleCI (#173) --- tests/RecordedEndpointPageTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/RecordedEndpointPageTest.php b/tests/RecordedEndpointPageTest.php index e1b966a..a28d574 100644 --- a/tests/RecordedEndpointPageTest.php +++ b/tests/RecordedEndpointPageTest.php @@ -24,14 +24,14 @@ 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){ + match ($propertyKey) { 'Rollup' => dd($property->asCollection()) && expect($property->asCollection()->first())->toBeInstanceOf(Rollup::class), // default => throw new \Exception('Unknown property key') default => null