Skip to content

Commit

Permalink
Add page integration tests for API errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mariosimao committed Oct 26, 2021
1 parent c364859 commit 3fef6b2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Pages/Page.php
Expand Up @@ -168,6 +168,7 @@ public function cover(): File|null
return $this->cover;
}

/** @return array<string, PropertyInterface> */
public function properties(): array
{
return $this->properties;
Expand Down
59 changes: 55 additions & 4 deletions tests/Integration/PagesTest.php
Expand Up @@ -4,6 +4,7 @@

use Notion\Client;
use Notion\Common\Emoji;
use Notion\NotionException;
use Notion\Pages\Page;
use Notion\Pages\PageParent;
use PHPUnit\Framework\TestCase;
Expand All @@ -21,13 +22,63 @@ public function test_create_empty_page(): void
->withTitle("Empty page")
->withIcon(Emoji::create(""));

$pageAfterInsert = $client->pages()->create($page);
$page = $client->pages()->create($page);

$pageFound = $client->pages()->find($pageAfterInsert->id());
$pageFound = $client->pages()->find($page->id());

$this->assertEquals("Empty page", $pageAfterInsert->title()->toString());
$this->assertEquals("Empty page", $page->title()->toString());
$this->assertEquals("", $pageFound->icon()->emoji());

$client->pages()->delete($pageAfterInsert);
$client->pages()->delete($page);
}

public function test_find_page(): void
{
$token = getenv("NOTION_TOKEN");
$client = Client::create($token);

$page = $client->pages()->find("3f4c46dee17f43b79587094b61407a31");

$this->assertEquals("Integration Tests", $page->title()->toString());
$this->assertEquals("Integration Tests", $page->properties()["title"]->toString());
}

public function test_find_inexistent_page(): void
{
$token = getenv("NOTION_TOKEN");
$client = Client::create($token);

$this->expectException(NotionException::class);
$this->expectErrorMessage("Could not find page with ID: 60e79d42-4742-41ca-8d70-cc51660cbd3c.");
$client->pages()->find("60e79d42-4742-41ca-8d70-cc51660cbd3c");
}

public function test_create_with_inexistent_parent(): void
{
$token = getenv("NOTION_TOKEN");
$client = Client::create($token);

$page = Page::create(PageParent::page("60e79d42-4742-41ca-8d70-cc51660cbd3c"));

$this->expectException(NotionException::class);
$this->expectErrorMessage("Could not find page with ID: 60e79d42-4742-41ca-8d70-cc51660cbd3c.");
$client->pages()->create($page);
}

public function test_update_archived_page(): void
{
$token = getenv("NOTION_TOKEN");
$client = Client::create($token);

$page = Page::create(PageParent::page(self::DEFAULT_PARENT_ID))
->withTitle("Deleted page");

$page = $client->pages()->create($page);
$page = $client->pages()->delete($page);

$page = $page->withTitle("Title after deleted");

$this->expectException(NotionException::class);
$client->pages()->update($page);
}
}

0 comments on commit 3fef6b2

Please sign in to comment.