22
33namespace FiveamCode \LaravelNotionApi \Tests ;
44
5+ use FiveamCode \LaravelNotionApi \Entities \PropertyItems \RichText ;
56use Notion ;
67use Illuminate \Support \Facades \Http ;
78use FiveamCode \LaravelNotionApi \Entities \Blocks \Block ;
@@ -54,7 +55,7 @@ public function it_returns_block_collection_with_children()
5455 Http::fake ([
5556 'https://api.notion.com/v1/blocks/b55c9c91-384d-452b-81db-d1ef79372b76/children* '
5657 => Http::response (
57- json_decode (file_get_contents ('tests/stubs/endpoints/blocks/response_specific_200 .json ' ), true ),
58+ json_decode (file_get_contents ('tests/stubs/endpoints/blocks/response_specific_block_children_200 .json ' ), true ),
5859 200 ,
5960 ['Headers ' ]
6061 )
@@ -79,85 +80,85 @@ public function it_returns_block_collection_with_children()
7980 $ this ->assertEquals ('Lacinato kale ' , $ blockChild ->getRawContent ()['text ' ][0 ]['plain_text ' ]);
8081 }
8182
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- }
83+ /** @test */
84+ public function it_returns_block_collection_with_children_as_correct_instances ()
85+ {
86+ // successful /v1/blocks/BLOCK_DOES_EXIST/children
87+ Http::fake ([
88+ 'https://api.notion.com/v1/blocks/1d719dd1-563b-4387-b74f-20da92b827fb/children* '
89+ => Http::response (
90+ json_decode (file_get_contents ('tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json ' ), true ),
91+ 200 ,
92+ ['Headers ' ]
93+ )
94+ ]);
95+
96+ $ blockChildren = Notion::block ('1d719dd1-563b-4387-b74f-20da92b827fb ' )->children ();
97+ $ this ->assertInstanceOf (BlockCollection::class, $ blockChildren );
98+
99+ # check collection
100+ $ blockChildrenCollection = $ blockChildren ->asCollection ();
101+ $ this ->assertContainsOnly (Block::class, $ blockChildrenCollection );
102+ $ this ->assertIsIterable ($ blockChildrenCollection );
103+ $ this ->assertCount (8 , $ blockChildrenCollection );
104+
105+ # check paragraph
106+ $ blockChild = $ blockChildrenCollection [0 ];
107+ $ this ->assertInstanceOf (Paragraph::class, $ blockChild );
108+ $ this ->assertEquals ('paragraph ' , $ blockChild ->getType ());
109+ $ this ->assertFalse ($ blockChild ->hasChildren ());
110+ $ this ->assertEquals ('paragraph_block ' , $ blockChild ->getContent ()->getPlainText ());
111+
112+ # check heading_1
113+ $ blockChild = $ blockChildrenCollection [1 ];
114+ $ this ->assertInstanceOf (HeadingOne::class, $ blockChild );
115+ $ this ->assertEquals ('heading_1 ' , $ blockChild ->getType ());
116+ $ this ->assertFalse ($ blockChild ->hasChildren ());
117+ $ this ->assertEquals ('heading_one_block ' , $ blockChild ->getContent ()->getPlainText ());
118+
119+ # check heading_2
120+ $ blockChild = $ blockChildrenCollection [2 ];
121+ $ this ->assertInstanceOf (HeadingTwo::class, $ blockChild );
122+ $ this ->assertEquals ('heading_2 ' , $ blockChild ->getType ());
123+ $ this ->assertFalse ($ blockChild ->hasChildren ());
124+ $ this ->assertEquals ('heading_two_block ' , $ blockChild ->getContent ()->getPlainText ());
125+
126+ # check heading_3
127+ $ blockChild = $ blockChildrenCollection [3 ];
128+ $ this ->assertInstanceOf (HeadingThree::class, $ blockChild );
129+ $ this ->assertEquals ('heading_3 ' , $ blockChild ->getType ());
130+ $ this ->assertFalse ($ blockChild ->hasChildren ());
131+ $ this ->assertEquals ('heading_three_block ' , $ blockChild ->getContent ()->getPlainText ());
132+
133+ # check bulleted_list_item
134+ $ blockChild = $ blockChildrenCollection [4 ];
135+ $ this ->assertInstanceOf (BulletedListItem::class, $ blockChild );
136+ $ this ->assertEquals ('bulleted_list_item ' , $ blockChild ->getType ());
137+ $ this ->assertFalse ($ blockChild ->hasChildren ());
138+ $ this ->assertEquals ('bulleted_list_item_block ' , $ blockChild ->getContent ()->getPlainText ());
139+
140+ # check numbered_list_item
141+ $ blockChild = $ blockChildrenCollection [5 ];
142+ $ this ->assertInstanceOf (NumberedListItem::class, $ blockChild );
143+ $ this ->assertEquals ('numbered_list_item ' , $ blockChild ->getType ());
144+ $ this ->assertFalse ($ blockChild ->hasChildren ());
145+ $ this ->assertEquals ('numbered_list_item_block ' , $ blockChild ->getContent ()->getPlainText ());
146+
147+ # check to_do
148+ $ blockChild = $ blockChildrenCollection [6 ];
149+ $ this ->assertInstanceOf (ToDo::class, $ blockChild );
150+ $ this ->assertEquals ('to_do ' , $ blockChild ->getType ());
151+ $ this ->assertFalse ($ blockChild ->hasChildren ());
152+ $ this ->assertEquals ('to_do_block ' , $ blockChild ->getContent ()->getPlainText ());
153+
154+ # check toggle
155+ $ blockChild = $ blockChildrenCollection [7 ];
156+ $ this ->assertInstanceOf (Toggle::class, $ blockChild );
157+ $ this ->assertEquals ('toggle ' , $ blockChild ->getType ());
158+ $ this ->assertFalse ($ blockChild ->hasChildren ());
159+ $ this ->assertEquals ('toggle_block ' , $ blockChild ->getContent ()->getPlainText ());
160+
161+ }
161162
162163 /** @test */
163164 public function it_throws_a_notion_exception_not_found ()
@@ -188,4 +189,23 @@ public function it_throws_a_handling_exception_not_implemented()
188189 Notion::block ('' )->create ();
189190 }
190191
192+ /** @test */
193+ public function it_retrieves_a_single_block ()
194+ {
195+ // successful /v1/blocks/BLOCK_DOES_EXIST
196+ Http::fake ([
197+ 'https://api.notion.com/v1/blocks/a6f8ebe8d5df4ffab543bcd54d1c3bad '
198+ => Http::response (
199+ json_decode (file_get_contents ('tests/stubs/endpoints/blocks/response_specific_block_200.json ' ), true ),
200+ 200 ,
201+ ['Headers ' ]
202+ )
203+ ]);
204+
205+ $ block = \Notion::block ("a6f8ebe8d5df4ffab543bcd54d1c3bad " )->retrieve ();
206+
207+ $ this ->assertInstanceOf (Block::class, $ block );
208+ $ this ->assertInstanceOf (Paragraph::class, $ block );
209+ }
210+
191211}
0 commit comments