Skip to content

Commit 09b278e

Browse files
committed
add new tests for properites title and number
1 parent 936fe50 commit 09b278e

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

tests/EndpointPagesTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ public function it_returns_page_entity_with_filled_properties()
5858
// check properties
5959
$this->assertSame("Notion Is Awesome", $pageResult->getTitle());
6060
$this->assertSame("page", $pageResult->getObjectType());
61+
$this->assertCount(7, $pageResult->getRawProperties());
62+
$this->assertCount(7, $pageResult->getProperties());
63+
$this->assertCount(7, $pageResult->getPropertyKeys());
6164

62-
$this->assertCount(6, $pageResult->getRawProperties());
6365

6466
$this->assertInstanceOf(Carbon::class, $pageResult->getCreatedTime());
6567
$this->assertInstanceOf(Carbon::class, $pageResult->getLastEditedTime());

tests/PagePropertyTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use FiveamCode\LaravelNotionApi\Entities\Page;
66
use FiveamCode\LaravelNotionApi\Entities\Properties\MultiSelect;
7+
use FiveamCode\LaravelNotionApi\Entities\Properties\Number;
78
use FiveamCode\LaravelNotionApi\Entities\Properties\Select;
89
use FiveamCode\LaravelNotionApi\Entities\Properties\Text;
10+
use FiveamCode\LaravelNotionApi\Entities\Properties\Title;
911
use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText;
1012
use FiveamCode\LaravelNotionApi\Entities\PropertyItems\SelectItem;
1113
use Illuminate\Support\Facades\Http;
@@ -108,4 +110,55 @@ public function it_checks_if_specific_page_property_is_a_valid_text_property()
108110
$this->assertSame("this is a nice Text :-)", $text->getRichText()->getPlainText());
109111
$this->assertCount(2, $text->getRichText()->getRaw());
110112
}
113+
114+
115+
/** @test */
116+
public function it_checks_if_specific_page_property_is_a_valid_number_property()
117+
{
118+
// successful /v1/pages/PAGE_DOES_EXIST
119+
Http::fake([
120+
'https://api.notion.com/v1/pages/afd5f6fb-1cbd-41d1-a108-a22ae0d9bac8'
121+
=> Http::response(
122+
json_decode(file_get_contents('tests/stubs/endpoints/pages/response_specific_200.json'), true),
123+
200,
124+
['Headers']
125+
)
126+
]);
127+
128+
$pageResult = \Notion::pages()->find("afd5f6fb-1cbd-41d1-a108-a22ae0d9bac8");
129+
$number = $pageResult->getProperty('NumberProp');
130+
131+
$this->assertInstanceOf(Page::class, $pageResult);
132+
133+
$this->assertInstanceOf(Number::class, $number);
134+
$this->assertSame('number', $number->getType());
135+
$this->assertSame(">d{N", $number->getId());
136+
$this->assertSame(500.0, $number->getNumber());
137+
$this->assertSame(500.0, $number->getContent());
138+
}
139+
140+
/** @test */
141+
public function it_checks_if_specific_page_property_is_a_valid_title_property()
142+
{
143+
// successful /v1/pages/PAGE_DOES_EXIST
144+
Http::fake([
145+
'https://api.notion.com/v1/pages/afd5f6fb-1cbd-41d1-a108-a22ae0d9bac8'
146+
=> Http::response(
147+
json_decode(file_get_contents('tests/stubs/endpoints/pages/response_specific_200.json'), true),
148+
200,
149+
['Headers']
150+
)
151+
]);
152+
153+
$pageResult = \Notion::pages()->find("afd5f6fb-1cbd-41d1-a108-a22ae0d9bac8");
154+
$title = $pageResult->getProperty('Name');
155+
156+
$this->assertInstanceOf(Page::class, $pageResult);
157+
$this->assertInstanceOf(Title::class, $title);
158+
$this->assertSame('title', $title->getType());
159+
$this->assertSame("title", $title->getId());
160+
$this->assertSame("Notion Is Awesome", $title->getPlainText());
161+
$this->assertInstanceOf(RichText::class, $title->getContent());
162+
$this->assertSame("Notion Is Awesome", $title->getContent()->getPlainText());
163+
}
111164
}

tests/stubs/endpoints/pages/response_specific_200.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
},
1010
"archived": false,
1111
"properties": {
12+
"NumberProp": {
13+
"id": ">d{N",
14+
"type": "number",
15+
"number": 500
16+
},
1217
"Last edit": {
1318
"id": "Jwcd",
1419
"type": "last_edited_time",

0 commit comments

Comments
 (0)