|
2 | 2 |
|
3 | 3 | namespace FiveamCode\LaravelNotionApi\Tests; |
4 | 4 |
|
| 5 | +use FiveamCode\LaravelNotionApi\Entities\Properties\Checkbox; |
| 6 | +use FiveamCode\LaravelNotionApi\Entities\Properties\Date; |
| 7 | +use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichDate; |
5 | 8 | use Notion; |
6 | 9 | use Carbon\Carbon; |
7 | 10 | use Illuminate\Support\Facades\Http; |
@@ -87,6 +90,69 @@ public function it_throws_a_notion_exception_not_found() |
87 | 90 | Notion::pages()->find('b55c9c91-384d-452b-81db-d1ef79372b79'); |
88 | 91 | } |
89 | 92 |
|
| 93 | + /** @test */ |
| 94 | + public function it_assembles_properties_for_a_new_page() { |
| 95 | + |
| 96 | + $pageId = "0349b883a1c64539b435289ea62b6eab"; |
| 97 | + $pageTitle = "I was updated from Tinkerwell"; |
| 98 | + |
| 99 | + $checkboxKey = "CheckboxProperty"; |
| 100 | + $checkboxValue = true; |
| 101 | + $dateRangeKey = "DateRangeProperty"; |
| 102 | + $dateRangeStartValue = Carbon::now()->toDateTime(); |
| 103 | + $dateRangeEndValue = Carbon::tomorrow()->toDateTime(); |
| 104 | + $dateKey = "DateProperty"; |
| 105 | + $dateValue = Carbon::yesterday()->toDateTime(); |
| 106 | + |
| 107 | + $page = new Page(); |
| 108 | + $page->setId($pageId); |
| 109 | + $page->setTitle("Name", $pageTitle); |
| 110 | + $page->setCheckbox($checkboxKey, $checkboxValue); |
| 111 | + $page->setDate($dateRangeKey, $dateRangeStartValue, $dateRangeEndValue); |
| 112 | + $page->setDate($dateKey, $dateValue); |
| 113 | + |
| 114 | + $properties = $page->getProperties(); |
| 115 | + |
| 116 | + $this->assertEquals($page->getId(), $pageId); |
| 117 | + $this->assertEquals($page->getTitle(), $pageTitle); |
| 118 | + |
| 119 | + # checkbox |
| 120 | + $this->assertTrue( |
| 121 | + $this->assertContainsInstanceOf(Checkbox::class, $properties) |
| 122 | + ); |
| 123 | + $checkboxProp = $page->getProperty($checkboxKey); |
| 124 | + $this->assertEquals($checkboxKey, $checkboxProp->getTitle()); |
| 125 | + $checkboxContent = $checkboxProp->getRawContent(); |
| 126 | + $this->assertArrayHasKey("checkbox", $checkboxContent); |
| 127 | + $this->assertEquals($checkboxContent["checkbox"], $checkboxValue); |
| 128 | + $this->assertEquals($checkboxProp->getContent(), $checkboxValue); |
| 129 | + $this->assertEquals($checkboxProp->asText(), $checkboxValue? "true" : "false"); |
| 130 | + |
| 131 | + # date range |
| 132 | + $this->assertTrue( |
| 133 | + $this->assertContainsInstanceOf(Date::class, $properties) |
| 134 | + ); |
| 135 | + $dateRangeProp = $page->getProperty($dateRangeKey); |
| 136 | + $this->assertEquals($dateRangeKey, $dateRangeProp->getTitle()); |
| 137 | + $this->assertInstanceOf(RichDate::class, $dateRangeProp->getContent()); |
| 138 | + $dateRangeContent = $dateRangeProp->getContent(); |
| 139 | + $this->assertTrue($dateRangeProp->isRange()); |
| 140 | + $this->assertEquals($dateRangeStartValue, $dateRangeProp->getStart()); |
| 141 | + $this->assertEquals($dateRangeEndValue, $dateRangeProp->getEnd()); |
| 142 | + |
| 143 | + # date |
| 144 | + $dateProp = $page->getProperty($dateKey); |
| 145 | + $this->assertEquals($dateKey, $dateProp->getTitle()); |
| 146 | + $this->assertInstanceOf(RichDate::class, $dateProp->getContent()); |
| 147 | + $dateContent = $dateProp->getContent(); |
| 148 | + $this->assertFalse($dateProp->isRange()); |
| 149 | + $this->assertEquals($dateValue, $dateProp->getStart()); |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + } |
| 155 | + |
90 | 156 |
|
91 | 157 | // /** @test */ |
92 | 158 | // public function it_throws_a_handling_exception_not_implemented_for_create() |
|
0 commit comments