Skip to content

Commit fd0fc5d

Browse files
committed
added notionapitest class for service provider mocking
1 parent 0222835 commit fd0fc5d

File tree

5 files changed

+117
-40
lines changed

5 files changed

+117
-40
lines changed

tests/EndpointBlocksTest.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace FiveamCode\LaravelNotionApi\Tests;
4+
5+
use Carbon\Carbon;
6+
use FiveamCode\LaravelNotionApi\Entities\Page;
7+
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
8+
use Illuminate\Support\Facades\Http;
9+
10+
/**
11+
* Class EndpointPageTest
12+
*
13+
* The fake API responses are based on our test environment (since the current Notion examples do not match with the actual calls).
14+
* @see https://developers.notion.com/reference/get-page
15+
*
16+
* @package FiveamCode\LaravelNotionApi\Tests
17+
*/
18+
class EndpointBlocksTest extends NotionApiTest
19+
{
20+
21+
/** @test */
22+
public function it_throws_a_notion_exception_bad_request()
23+
{
24+
// failing /v1/databases
25+
Http::fake([
26+
'https://api.notion.com/v1/pages*'
27+
=> Http::response(
28+
json_decode('{}', true),
29+
400,
30+
['Headers']
31+
)
32+
]);
33+
34+
$this->expectException(NotionException::class);
35+
$this->expectExceptionMessage("Bad Request");
36+
37+
\Notion::pages()->find("afd5f6fb-1cbd-41d1-a108-a22ae0d9bac8");
38+
}
39+
40+
/** @test */
41+
public function it_returns_page_entity_with_filled_properties()
42+
{
43+
// successful /v1/pages/PAGE_DOES_EXIST
44+
Http::fake([
45+
'https://api.notion.com/v1/pages/afd5f6fb-1cbd-41d1-a108-a22ae0d9bac8'
46+
=> Http::response(
47+
json_decode(file_get_contents('tests/stubs/endpoints/pages/response_specific_200.json'), true),
48+
200,
49+
['Headers']
50+
)
51+
]);
52+
53+
$pageResult = \Notion::pages()->find("afd5f6fb-1cbd-41d1-a108-a22ae0d9bac8");
54+
55+
$this->assertInstanceOf(Page::class, $pageResult);
56+
57+
// check properties
58+
$this->assertSame("Notion Is Awesome", $pageResult->getTitle());
59+
$this->assertSame("page", $pageResult->getObjectType());
60+
61+
$this->assertCount(6, $pageResult->getRawProperties());
62+
63+
$this->assertInstanceOf(Carbon::class, $pageResult->getCreatedTime());
64+
$this->assertInstanceOf(Carbon::class, $pageResult->getLastEditedTime());
65+
}
66+
67+
/** @test */
68+
public function it_throws_a_notion_exception_not_found()
69+
{
70+
// failing /v1/pages/PAGE_DOES_NOT_EXIST
71+
Http::fake([
72+
'https://api.notion.com/v1/pages/b55c9c91-384d-452b-81db-d1ef79372b79'
73+
=> Http::response(
74+
json_decode(file_get_contents('tests/stubs/endpoints/pages/response_specific_404.json'), true),
75+
200,
76+
['Headers']
77+
)
78+
]);
79+
80+
$this->expectException(NotionException::class);
81+
$this->expectExceptionMessage("Not found");
82+
83+
\Notion::pages()->find("b55c9c91-384d-452b-81db-d1ef79372b79");
84+
}
85+
86+
}

tests/EndpointDatabaseTest.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use FiveamCode\LaravelNotionApi\Entities\Database;
77
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
88
use Illuminate\Support\Facades\Http;
9-
use Orchestra\Testbench\TestCase;
109

1110
/**
1211
* Class EndpointDatabaseTest
@@ -16,21 +15,9 @@
1615
*
1716
* @package FiveamCode\LaravelNotionApi\Tests
1817
*/
19-
class EndpointDatabaseTest extends TestCase
18+
class EndpointDatabaseTest extends NotionApiTest
2019
{
2120

22-
protected function getPackageProviders($app)
23-
{
24-
return ['FiveamCode\LaravelNotionApi\LaravelNotionApiServiceProvider'];
25-
}
26-
27-
protected function getPackageAliases($app)
28-
{
29-
return [
30-
'Notion' => \FiveamCode\LaravelNotionApi\NotionFacade::class
31-
];
32-
}
33-
3421
/** @test */
3522
public function it_returns_a_list_of_database_objects()
3623
{

tests/EndpointPageTest.php renamed to tests/EndpointPagesTest.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,9 @@
1717
*
1818
* @package FiveamCode\LaravelNotionApi\Tests
1919
*/
20-
class EndpointPageTest extends TestCase
20+
class EndpointPagesTest extends NotionApiTest
2121
{
2222

23-
protected function getPackageProviders($app)
24-
{
25-
return ['FiveamCode\LaravelNotionApi\LaravelNotionApiServiceProvider'];
26-
}
27-
28-
protected function getPackageAliases($app)
29-
{
30-
return [
31-
'Notion' => \FiveamCode\LaravelNotionApi\NotionFacade::class
32-
];
33-
}
34-
3523
/** @test */
3624
public function it_throws_a_notion_exception_bad_request()
3725
{

tests/NotionApiTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace FiveamCode\LaravelNotionApi\Tests;
4+
5+
use Orchestra\Testbench\TestCase;
6+
7+
/**
8+
* Class EndpointPageTest
9+
*
10+
* The fake API responses are based on our test environment (since the current Notion examples do not match with the actual calls).
11+
* @see https://developers.notion.com/reference/get-page
12+
*
13+
* @package FiveamCode\LaravelNotionApi\Tests
14+
*/
15+
class NotionApiTest extends TestCase
16+
{
17+
protected function getPackageProviders($app)
18+
{
19+
return ['FiveamCode\LaravelNotionApi\LaravelNotionApiServiceProvider'];
20+
}
21+
22+
protected function getPackageAliases($app)
23+
{
24+
return [
25+
'Notion' => \FiveamCode\LaravelNotionApi\NotionFacade::class
26+
];
27+
}
28+
}

tests/EnpointPagePropertyTest.php renamed to tests/PagePropertyTest.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,9 @@
2222
*
2323
* @package FiveamCode\LaravelNotionApi\Tests
2424
*/
25-
class EnpointPagePropertyTest extends TestCase
25+
class PagePropertyTest extends NotionApiTest
2626
{
2727

28-
protected function getPackageProviders($app)
29-
{
30-
return ['FiveamCode\LaravelNotionApi\LaravelNotionApiServiceProvider'];
31-
}
32-
33-
protected function getPackageAliases($app)
34-
{
35-
return [
36-
'Notion' => \FiveamCode\LaravelNotionApi\NotionFacade::class
37-
];
38-
}
39-
4028
/** @test */
4129
public function it_checks_if_specific_page_property_is_a_valid_multi_select_property()
4230
{

0 commit comments

Comments
 (0)