Skip to content

Commit f9e1947

Browse files
committed
implemented tests for blocks-endpoint
check if correct instance is added to collection (depending on block type) check if content of blocks is correctly retreived
1 parent f4ca7a4 commit f9e1947

File tree

2 files changed

+328
-0
lines changed

2 files changed

+328
-0
lines changed

tests/EndpointBlocksTest.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
use Notion;
66
use Illuminate\Support\Facades\Http;
77
use FiveamCode\LaravelNotionApi\Entities\Blocks\Block;
8+
use FiveamCode\LaravelNotionApi\Entities\Blocks\BulletedListItem;
9+
use FiveamCode\LaravelNotionApi\Entities\Blocks\HeadingOne;
10+
use FiveamCode\LaravelNotionApi\Entities\Blocks\HeadingThree;
11+
use FiveamCode\LaravelNotionApi\Entities\Blocks\HeadingTwo;
12+
use FiveamCode\LaravelNotionApi\Entities\Blocks\NumberedListItem;
13+
use FiveamCode\LaravelNotionApi\Entities\Blocks\Paragraph;
14+
use FiveamCode\LaravelNotionApi\Entities\Blocks\ToDo;
15+
use FiveamCode\LaravelNotionApi\Entities\Blocks\Toggle;
816
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
917
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
1018
use FiveamCode\LaravelNotionApi\Entities\Collections\BlockCollection;
@@ -71,6 +79,86 @@ public function it_returns_block_collection_with_children()
7179
$this->assertEquals('Lacinato kale', $blockChild->getRawContent()['text'][0]['plain_text']);
7280
}
7381

82+
/** @test */
83+
public function it_returns_block_collection_with_children_as_correct_instances()
84+
{
85+
// successful /v1/blocks/BLOCK_DOES_EXIST/children
86+
Http::fake([
87+
'https://api.notion.com/v1/blocks/1d719dd1-563b-4387-b74f-20da92b827fb/children*'
88+
=> Http::response(
89+
json_decode(file_get_contents('tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json'), true),
90+
200,
91+
['Headers']
92+
)
93+
]);
94+
95+
$blockChildren = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->children();
96+
$this->assertInstanceOf(BlockCollection::class, $blockChildren);
97+
98+
# check collection
99+
$blockChildrenCollection = $blockChildren->asCollection();
100+
$this->assertContainsOnly(Block::class, $blockChildrenCollection);
101+
$this->assertIsIterable($blockChildrenCollection);
102+
$this->assertCount(8, $blockChildrenCollection);
103+
104+
# check paragraph
105+
$blockChild = $blockChildrenCollection[0];
106+
$this->assertInstanceOf(Paragraph::class, $blockChild);
107+
$this->assertEquals('paragraph', $blockChild->getType());
108+
$this->assertFalse($blockChild->hasChildren());
109+
$this->assertEquals('paragraph_block', $blockChild->getContent()->getPlainText());
110+
111+
# check heading_1
112+
$blockChild = $blockChildrenCollection[1];
113+
$this->assertInstanceOf(HeadingOne::class, $blockChild);
114+
$this->assertEquals('heading_1', $blockChild->getType());
115+
$this->assertFalse($blockChild->hasChildren());
116+
$this->assertEquals('heading_one_block', $blockChild->getContent()->getPlainText());
117+
118+
# check heading_2
119+
$blockChild = $blockChildrenCollection[2];
120+
$this->assertInstanceOf(HeadingTwo::class, $blockChild);
121+
$this->assertEquals('heading_2', $blockChild->getType());
122+
$this->assertFalse($blockChild->hasChildren());
123+
$this->assertEquals('heading_two_block', $blockChild->getContent()->getPlainText());
124+
125+
# check heading_3
126+
$blockChild = $blockChildrenCollection[3];
127+
$this->assertInstanceOf(HeadingThree::class, $blockChild);
128+
$this->assertEquals('heading_3', $blockChild->getType());
129+
$this->assertFalse($blockChild->hasChildren());
130+
$this->assertEquals('heading_three_block', $blockChild->getContent()->getPlainText());
131+
132+
# check bulleted_list_item
133+
$blockChild = $blockChildrenCollection[4];
134+
$this->assertInstanceOf(BulletedListItem::class, $blockChild);
135+
$this->assertEquals('bulleted_list_item', $blockChild->getType());
136+
$this->assertFalse($blockChild->hasChildren());
137+
$this->assertEquals('bulleted_list_item_block', $blockChild->getContent()->getPlainText());
138+
139+
# check numbered_list_item
140+
$blockChild = $blockChildrenCollection[5];
141+
$this->assertInstanceOf(NumberedListItem::class, $blockChild);
142+
$this->assertEquals('numbered_list_item', $blockChild->getType());
143+
$this->assertFalse($blockChild->hasChildren());
144+
$this->assertEquals('numbered_list_item_block', $blockChild->getContent()->getPlainText());
145+
146+
# check to_do
147+
$blockChild = $blockChildrenCollection[6];
148+
$this->assertInstanceOf(ToDo::class, $blockChild);
149+
$this->assertEquals('to_do', $blockChild->getType());
150+
$this->assertFalse($blockChild->hasChildren());
151+
$this->assertEquals('to_do_block', $blockChild->getContent()->getPlainText());
152+
153+
# check toggle
154+
$blockChild = $blockChildrenCollection[7];
155+
$this->assertInstanceOf(Toggle::class, $blockChild);
156+
$this->assertEquals('toggle', $blockChild->getType());
157+
$this->assertFalse($blockChild->hasChildren());
158+
$this->assertEquals('toggle_block', $blockChild->getContent()->getPlainText());
159+
160+
}
161+
74162
/** @test */
75163
public function it_throws_a_notion_exception_not_found()
76164
{
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
{
2+
"object": "list",
3+
"results": [
4+
{
5+
"object": "block",
6+
"id": "1d829dd4-563b-4387-b74f-20da92b827fb",
7+
"created_time": "2021-07-17T16:51:00.000Z",
8+
"last_edited_time": "2021-07-17T16:54:00.000Z",
9+
"has_children": false,
10+
"type": "paragraph",
11+
"paragraph": {
12+
"text": [
13+
{
14+
"type": "text",
15+
"text": {
16+
"content": "paragraph_block",
17+
"link": null
18+
},
19+
"annotations": {
20+
"bold": false,
21+
"italic": false,
22+
"strikethrough": false,
23+
"underline": false,
24+
"code": false,
25+
"color": "default"
26+
},
27+
"plain_text": "paragraph_block",
28+
"href": null
29+
}
30+
]
31+
}
32+
},
33+
{
34+
"object": "block",
35+
"id": "616fc310-6c27-48f4-8c7e-1bf2bbb851a8",
36+
"created_time": "2021-07-17T16:54:00.000Z",
37+
"last_edited_time": "2021-07-17T16:54:00.000Z",
38+
"has_children": false,
39+
"type": "heading_1",
40+
"heading_1": {
41+
"text": [
42+
{
43+
"type": "text",
44+
"text": {
45+
"content": "heading_one_block",
46+
"link": null
47+
},
48+
"annotations": {
49+
"bold": false,
50+
"italic": false,
51+
"strikethrough": false,
52+
"underline": false,
53+
"code": false,
54+
"color": "default"
55+
},
56+
"plain_text": "heading_one_block",
57+
"href": null
58+
}
59+
]
60+
}
61+
},
62+
{
63+
"object": "block",
64+
"id": "ad02c583-74bb-47a5-a00d-dc2b717051d5",
65+
"created_time": "2021-07-17T16:54:00.000Z",
66+
"last_edited_time": "2021-07-17T16:55:00.000Z",
67+
"has_children": false,
68+
"type": "heading_2",
69+
"heading_2": {
70+
"text": [
71+
{
72+
"type": "text",
73+
"text": {
74+
"content": "heading_two_block",
75+
"link": null
76+
},
77+
"annotations": {
78+
"bold": false,
79+
"italic": false,
80+
"strikethrough": false,
81+
"underline": false,
82+
"code": false,
83+
"color": "default"
84+
},
85+
"plain_text": "heading_two_block",
86+
"href": null
87+
}
88+
]
89+
}
90+
},
91+
{
92+
"object": "block",
93+
"id": "797d5bfd-b5fc-432e-ba2a-e14a93174e2c",
94+
"created_time": "2021-07-17T16:54:00.000Z",
95+
"last_edited_time": "2021-07-17T16:55:00.000Z",
96+
"has_children": false,
97+
"type": "heading_3",
98+
"heading_3": {
99+
"text": [
100+
{
101+
"type": "text",
102+
"text": {
103+
"content": "heading_three_block",
104+
"link": null
105+
},
106+
"annotations": {
107+
"bold": false,
108+
"italic": false,
109+
"strikethrough": false,
110+
"underline": false,
111+
"code": false,
112+
"color": "default"
113+
},
114+
"plain_text": "heading_three_block",
115+
"href": null
116+
}
117+
]
118+
}
119+
},
120+
{
121+
"object": "block",
122+
"id": "c4a0f595-7ad3-42c9-a2f0-dadf143b4c1e",
123+
"created_time": "2021-07-17T16:54:00.000Z",
124+
"last_edited_time": "2021-07-17T16:56:00.000Z",
125+
"has_children": false,
126+
"type": "bulleted_list_item",
127+
"bulleted_list_item": {
128+
"text": [
129+
{
130+
"type": "text",
131+
"text": {
132+
"content": "bulleted_list_item_block",
133+
"link": null
134+
},
135+
"annotations": {
136+
"bold": false,
137+
"italic": false,
138+
"strikethrough": false,
139+
"underline": false,
140+
"code": false,
141+
"color": "default"
142+
},
143+
"plain_text": "bulleted_list_item_block",
144+
"href": null
145+
}
146+
]
147+
}
148+
},
149+
{
150+
"object": "block",
151+
"id": "52eb7c2a-13ee-4b78-936e-9019dbdbf113",
152+
"created_time": "2021-07-17T16:55:00.000Z",
153+
"last_edited_time": "2021-07-17T16:56:00.000Z",
154+
"has_children": false,
155+
"type": "numbered_list_item",
156+
"numbered_list_item": {
157+
"text": [
158+
{
159+
"type": "text",
160+
"text": {
161+
"content": "numbered_list_item_block",
162+
"link": null
163+
},
164+
"annotations": {
165+
"bold": false,
166+
"italic": false,
167+
"strikethrough": false,
168+
"underline": false,
169+
"code": false,
170+
"color": "default"
171+
},
172+
"plain_text": "numbered_list_item_block",
173+
"href": null
174+
}
175+
]
176+
}
177+
},
178+
{
179+
"object": "block",
180+
"id": "2e58b063-5bb2-6c1c-8682-dbb6e26b153b",
181+
"created_time": "2021-07-17T16:55:00.000Z",
182+
"last_edited_time": "2021-07-17T17:03:00.000Z",
183+
"has_children": false,
184+
"type": "to_do",
185+
"to_do": {
186+
"text": [
187+
{
188+
"type": "text",
189+
"text": {
190+
"content": "to_do_block",
191+
"link": null
192+
},
193+
"annotations": {
194+
"bold": false,
195+
"italic": false,
196+
"strikethrough": false,
197+
"underline": false,
198+
"code": false,
199+
"color": "default"
200+
},
201+
"plain_text": "to_do_block",
202+
"href": null
203+
}
204+
],
205+
"checked": false
206+
}
207+
},
208+
{
209+
"object": "block",
210+
"id": "b96c259c-72b7-453f-9140-c6618af1fea3",
211+
"created_time": "2021-07-17T16:56:00.000Z",
212+
"last_edited_time": "2021-07-17T17:03:00.000Z",
213+
"has_children": false,
214+
"type": "toggle",
215+
"toggle": {
216+
"text": [
217+
{
218+
"type": "text",
219+
"text": {
220+
"content": "toggle_block",
221+
"link": null
222+
},
223+
"annotations": {
224+
"bold": false,
225+
"italic": false,
226+
"strikethrough": false,
227+
"underline": false,
228+
"code": false,
229+
"color": "default"
230+
},
231+
"plain_text": "toggle_block",
232+
"href": null
233+
}
234+
]
235+
}
236+
}
237+
],
238+
"next_cursor": null,
239+
"has_more": false
240+
}

0 commit comments

Comments
 (0)