Skip to content

Commit 968d5b7

Browse files
committed
Started page creation / update property assembling test
1 parent 9e6350e commit 968d5b7

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

tests/EndpointPagesTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace FiveamCode\LaravelNotionApi\Tests;
44

5+
use FiveamCode\LaravelNotionApi\Entities\Properties\Checkbox;
6+
use FiveamCode\LaravelNotionApi\Entities\Properties\Date;
7+
use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichDate;
58
use Notion;
69
use Carbon\Carbon;
710
use Illuminate\Support\Facades\Http;
@@ -87,6 +90,69 @@ public function it_throws_a_notion_exception_not_found()
8790
Notion::pages()->find('b55c9c91-384d-452b-81db-d1ef79372b79');
8891
}
8992

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+
90156

91157
// /** @test */
92158
// public function it_throws_a_handling_exception_not_implemented_for_create()

tests/NotionApiTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace FiveamCode\LaravelNotionApi\Tests;
44

55
use Orchestra\Testbench\TestCase;
6+
use Illuminate\Support\Collection;
67
use FiveamCode\LaravelNotionApi\Notion;
78
use FiveamCode\LaravelNotionApi\NotionFacade;
89
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
@@ -37,6 +38,15 @@ protected function getPackageAliases($app): array
3738
];
3839
}
3940

41+
protected function assertContainsInstanceOf(string $class, Collection|array $haystack): bool {
42+
43+
foreach($haystack as $item) {
44+
if(get_class($item) === $class) return true;
45+
}
46+
47+
return false;
48+
}
49+
4050
/** @test */
4151
public function it_asserts_true()
4252
{

0 commit comments

Comments
 (0)