Skip to content

Commit 96342d4

Browse files
committed
improved tests
1 parent c0c4b7f commit 96342d4

File tree

6 files changed

+46
-14
lines changed

6 files changed

+46
-14
lines changed

src/Endpoints/Block.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

5+
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
56
use FiveamCode\LaravelNotionApi\Notion;
67
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
78
use FiveamCode\LaravelNotionApi\Entities\Collections\BlockCollection;
@@ -29,15 +30,11 @@ public function children(): BlockCollection
2930
$this->url(Endpoint::BLOCKS . "/" . $this->blockId . "/children" . "?{$this->buildPaginationQuery()}")
3031
);
3132

32-
if ($response->failed())
33-
throw NotionException::fromResponse($response);
34-
3533
return new BlockCollection($response->json());
3634
}
3735

3836
public function create(): array
3937
{
40-
//toDo
41-
throw new \Exception("not implemented yet");
38+
throw new HandlingException("Not implemented");
4239
}
4340
}

src/Endpoints/Pages.php

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

55
use FiveamCode\LaravelNotionApi\Entities\Page;
6+
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
67
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
78

89
class Pages extends Endpoint implements EndpointInterface
@@ -22,22 +23,19 @@ public function find(string $pageId): Page
2223
$this->url(Endpoint::PAGES . "/" . $pageId)
2324
);
2425

25-
if ($response->failed())
26-
throw NotionException::fromResponse($response);
27-
2826
return new Page($response->json());
2927
}
3028

3129
public function create(): array
3230
{
3331
//toDo
34-
throw new \Exception("not implemented yet");
32+
throw new HandlingException("Not implemented");
3533
}
3634

3735

3836
public function updateProperties(): array
3937
{
4038
//toDo
41-
throw new \Exception("not implemented yet");
39+
throw new HandlingException("Not implemented");
4240
}
4341
}

src/Endpoints/Users.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ public function find(string $userId): User
3838
$this->url(Endpoint::USERS . "/" . $userId)
3939
);
4040

41-
if ($response->failed())
42-
throw NotionException::fromResponse($response);
43-
44-
4541
return new User($response->json());
4642
}
4743
}

tests/EndpointBlocksTest.php

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

33
namespace FiveamCode\LaravelNotionApi\Tests;
44

5+
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
56
use Illuminate\Support\Facades\Http;
67
use FiveamCode\LaravelNotionApi\Entities\Blocks\Block;
78
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
@@ -88,4 +89,13 @@ public function it_throws_a_notion_exception_not_found()
8889
\Notion::block("b55c9c91-384d-452b-81db-d1ef79372b11")->children();
8990
}
9091

92+
/** @test */
93+
public function it_throws_a_handling_exception_not_implemented() {
94+
95+
$this->expectException(HandlingException::class);
96+
$this->expectExceptionMessage("Not implemented");
97+
98+
\Notion::block("")->create();
99+
}
100+
91101
}

tests/EndpointPagesTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Carbon\Carbon;
66
use FiveamCode\LaravelNotionApi\Entities\Page;
7+
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
78
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
89
use Illuminate\Support\Facades\Http;
910
use Orchestra\Testbench\TestCase;
@@ -86,4 +87,23 @@ public function it_throws_a_notion_exception_not_found()
8687
\Notion::pages()->find("b55c9c91-384d-452b-81db-d1ef79372b79");
8788
}
8889

90+
91+
/** @test */
92+
public function it_throws_a_handling_exception_not_implemented_for_create() {
93+
94+
$this->expectException(HandlingException::class);
95+
$this->expectExceptionMessage("Not implemented");
96+
97+
\Notion::pages()->create();
98+
}
99+
100+
/** @test */
101+
public function it_throws_a_handling_exception_not_implemented_for_update_properties() {
102+
103+
$this->expectException(HandlingException::class);
104+
$this->expectExceptionMessage("Not implemented");
105+
106+
\Notion::pages()->updateProperties();
107+
}
108+
89109
}

tests/NotionApiTest.php

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

33
namespace FiveamCode\LaravelNotionApi\Tests;
44

5+
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
56
use FiveamCode\LaravelNotionApi\Notion;
67
use Orchestra\Testbench\TestCase;
78

@@ -37,4 +38,14 @@ public function it_returns_notion_instance_with_set_token_and_connection()
3738
$this->assertInstanceOf(Notion::class, $notion);
3839
$this->assertNotEmpty($notion->getConnection());
3940
}
41+
42+
43+
/** @test */
44+
public function it_throws_a_handling_exception_invalid_version()
45+
{
46+
$this->expectException(HandlingException::class);
47+
$this->expectExceptionMessage("invalid version for notion-api");
48+
49+
$notion = new Notion("secret_*", "v-does-not-exist");
50+
}
4051
}

0 commit comments

Comments
 (0)