|
5 | 5 | use Notion;
|
6 | 6 | use Illuminate\Support\Facades\Http;
|
7 | 7 | 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; |
8 | 16 | use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
|
9 | 17 | use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
|
10 | 18 | use FiveamCode\LaravelNotionApi\Entities\Collections\BlockCollection;
|
@@ -71,6 +79,86 @@ public function it_returns_block_collection_with_children()
|
71 | 79 | $this->assertEquals('Lacinato kale', $blockChild->getRawContent()['text'][0]['plain_text']);
|
72 | 80 | }
|
73 | 81 |
|
| 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 | + |
74 | 162 | /** @test */
|
75 | 163 | public function it_throws_a_notion_exception_not_found()
|
76 | 164 | {
|
|
0 commit comments