Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2bfcee4
fix: check if content is set for rollup properties
johguentner Jul 9, 2022
2507d0f
Apply fixes from StyleCI (#67)
mechelon Jul 9, 2022
7a9da2d
polish/fix: control over 'includeTime' of Date
johguentner Jul 9, 2022
8111720
add: test for edge case of empty Select in Rollup
johguentner Jul 9, 2022
32fbfc6
Apply fixes from StyleCI (#70)
mechelon Jul 9, 2022
0283feb
fix test: breaking-changes in Date prop handling
johguentner Jul 9, 2022
420c037
add tests: for Date Property with forced time
johguentner Jul 9, 2022
85a8ff8
Apply fixes from StyleCI (#71)
mechelon Jul 9, 2022
0fdd0c0
add: better pagination handling
johguentner Jul 10, 2022
5d11817
Apply fixes from StyleCI (#72)
mechelon Jul 10, 2022
dafd6de
polish: handling for empty next_cursor
johguentner Jul 10, 2022
e1b3aca
add tests for improved pagination handling
johguentner Jul 10, 2022
a64227c
Merge branch 'feature/better-pagination-handling' of https://github.c…
johguentner Jul 10, 2022
bc8a3e6
Apply fixes from StyleCI (#74)
mechelon Jul 10, 2022
c541080
polish/fix: read (fetch) hasTime in date property
johguentner Jul 11, 2022
0a07217
modify tests: evaluate 'hasTime' in date props
johguentner Jul 11, 2022
a77289e
clarify: move edge-case label to test method
johguentner Jul 11, 2022
9aa463a
Apply fixes from StyleCI (#75)
mechelon Jul 11, 2022
b935959
Merge pull request #68 from 5am-code/65-rollup-with-empty-select-fix
johguentner Jul 11, 2022
461b1dd
Merge pull request #69 from 5am-code/61-choose-time-format
johguentner Jul 11, 2022
66ca7af
Merge branch 'dev' into feature/better-pagination-handling
johguentner Jul 11, 2022
2451387
Apply fixes from StyleCI (#76)
mechelon Jul 11, 2022
f1e0af9
Merge pull request #73 from 5am-code/feature/better-pagination-handling
johguentner Jul 11, 2022
40ed8ac
fix: check if content is null in date property
johguentner Aug 1, 2022
1963906
Apply fixes from StyleCI (#78)
mechelon Aug 1, 2022
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
17 changes: 13 additions & 4 deletions src/Entities/Properties/Rollup.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function fillFromRaw(): void
break;
default:
throw new HandlingException("Unexpected rollupType {$this->rollupType}");
}
}
}
}

Expand Down Expand Up @@ -89,12 +89,21 @@ private function setRollupContentArray()
// TODO
$rollupPropertyItem['id'] = 'undefined';

$this->content->add(
Property::fromResponse('', $rollupPropertyItem)
);
if ($this->isRollupPropertyContentSet($rollupPropertyItem)) {
$this->content->add(
Property::fromResponse('', $rollupPropertyItem)
);
}
}
}

private function isRollupPropertyContentSet($rollupPropertyItem): bool
{
return Arr::exists($rollupPropertyItem, 'type')
&& Arr::exists($rollupPropertyItem, $rollupPropertyItem['type'])
&& ! is_null($rollupPropertyItem[$rollupPropertyItem['type']]);
}

private function setRollupContentDate()
{
$this->content = new RichDate();
Expand Down
29 changes: 29 additions & 0 deletions tests/EndpointDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,33 @@ public function it_throws_a_notion_exception_bad_request()

Notion::database('8284f3ff77e24d4a939d19459e4d6bdc')->query();
}

/**
* @test
* ! edge-case
*/
public function it_queries_a_database_with_a_rollup_property_with_empty_selects()
{
// success /v1/databases/DATABASE_DOES_EXIST/query
Http::fake([
'https://api.notion.com/v1/databases/11971214ce574df7a58389c1deda61d7/query*' => Http::response(
json_decode(file_get_contents('tests/stubs/endpoints/databases/response_query_rollup_empty_select_200.json'), true),
200,
['Headers']
),
]);

$result = Notion::database('11971214ce574df7a58389c1deda61d7')->query();

$this->assertInstanceOf(PageCollection::class, $result);

$resultCollection = $result->asCollection();

$this->assertIsIterable($resultCollection);
$this->assertContainsOnly(Page::class, $resultCollection);

// check page object
$page = $resultCollection->first();
$this->assertEquals(0, $page->getProperty('Rollup')->getContent()->count());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"object": "list",
"results": [
{
"object": "page",
"id": "1321e6b6-0771-48bb-9814-6501c2ec3c32",
"created_time": "2022-07-09T10:29:00.000Z",
"last_edited_time": "2022-07-09T10:45:00.000Z",
"created_by": {
"object": "user",
"id": "04536682-601a-4531-a18f-4fa89fdf14a8"
},
"last_edited_by": {
"object": "user",
"id": "04531682-603a-4531-a18f-1fa89fdfb4a8"
},
"cover": null,
"icon": null,
"parent": {
"type": "database_id",
"database_id": "15971224-ce57-4df1-a583-89c1deca63d7"
},
"archived": false,
"properties": {
"Test Rollup Problem": {
"id": "G|zT",
"type": "relation",
"relation": [
{
"id": "dcad104b-222c-4d63-b83e-852f22612f4a"
},
{
"id": "3611ce31-ae52-45dc-bc5a-10626ca19ab5"
}
]
},
"Rollup": {
"id": "JCh`",
"type": "rollup",
"rollup": {
"type": "array",
"array": [
{
"type": "select",
"select": null
}
],
"function": "show_original"
}
},
"Name": {
"id": "title",
"type": "title",
"title": []
}
},
"url": "https:\/\/www.notion.so\/132de616077648bb98146501c2ec3c32"
},
{
"object": "page",
"id": "43dd6b90-6bde-48ea-9f06-79fee96de99c",
"created_time": "2022-07-09T10:29:00.000Z",
"last_edited_time": "2022-07-09T10:29:00.000Z",
"created_by": {
"object": "user",
"id": "04d36682-603a-4531-a18f-4fa19fdfb4a8"
},
"last_edited_by": {
"object": "user",
"id": "04d36682-603a-4531-a18f-4fa891dfb4a8"
},
"cover": null,
"icon": null,
"parent": {
"type": "database_id",
"database_id": "1d9712d4-ce57-4df7-a583-89c1dedac3d7"
},
"archived": false,
"properties": {
"Test Rollup Problem": {
"id": "G|zT",
"type": "relation",
"relation": []
},
"Rollup": {
"id": "JCh`",
"type": "rollup",
"rollup": {
"type": "array",
"array": [],
"function": "show_original"
}
},
"Name": {
"id": "title",
"type": "title",
"title": []
}
},
"url": "https:\/\/www.notion.so\/430d6b9d6b9e48ea9f067cfee96de9d9"
},
{
"object": "page",
"id": "788c67fe-84d2-4cf8-aab6-6cd6448d98b2",
"created_time": "2022-07-09T10:29:00.000Z",
"last_edited_time": "2022-07-09T10:29:00.000Z",
"created_by": {
"object": "user",
"id": "04536682-613a-4531-a18f-4fd89fdfb4a8"
},
"last_edited_by": {
"object": "user",
"id": "04436622-603a-4531-a18f-4fa89fdfb4a8"
},
"cover": null,
"icon": null,
"parent": {
"type": "database_id",
"database_id": "15972224-ce57-4df7-a583-89c1de1a63dd"
},
"archived": false,
"properties": {
"Test Rollup Problem": {
"id": "G|zT",
"type": "relation",
"relation": []
},
"Rollup": {
"id": "JCh`",
"type": "rollup",
"rollup": {
"type": "array",
"array": [],
"function": "show_original"
}
},
"Name": {
"id": "title",
"type": "title",
"title": []
}
},
"url": "https:\/\/www.notion.so\/788c67de84d24cf8dab660d64c8998b2"
}
],
"next_cursor": null,
"has_more": false
}