Skip to content

Commit

Permalink
test: fix tests CI (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariosimao committed Dec 31, 2023
1 parent 28e3366 commit cf794d4
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
on:
pull_request_target:
pull_request:
push:
branches:
- main
Expand Down
25 changes: 18 additions & 7 deletions src/Users/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
* @psalm-import-type BotJson from Bot
*
* @psalm-type UserJson = array{
* object: "user",
* id: string,
* name: string|null,
* avatar_url: string|null,
* type: "person"|"bot",
* name?: string,
* avatar_url?: string,
* type?: "person"|"bot",
* person?: PersonJson,
* bot?: BotJson,
* }
Expand Down Expand Up @@ -53,12 +54,22 @@ public static function fromArray(array $array): self
public function toArray(): array
{
$array = [
"id" => $this->id,
"name" => $this->name,
"avatar_url" => $this->avatarUrl,
"type" => $this->type->value,
"object" => "user",
"id" => $this->id,
];

if ($this->type !== null) {
$array["type"] = $this->type->value;
}

if ($this->name !== null) {
$array["name"] = $this->name;
}

if ($this->avatarUrl !== null) {
$array["avatar_url"] = $this->avatarUrl;
}

if ($this->isPerson()) {
$array["person"] = $this->person->toArray();
}
Expand Down
6 changes: 5 additions & 1 deletion tests/Integration/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Notion\Test\Integration;

use Exception;
use Notion\Configuration;
use Notion\Notion;
use Notion\Pages\Page;
use Notion\Pages\PageParent;
Expand All @@ -16,7 +17,10 @@ public static function client(): Notion
throw new Exception("Notion token is required to run integration tests.");
}

return Notion::create($token);
$config = Configuration::create($token)
->enableRetryOnConflict(10);

return Notion::createFromConfig($config);
}

public static function testPageId(): string
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Common/MentionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function test_mention_database(): void
public function test_mention_user(): void
{
$user = User::fromArray([
"object" => "user",
"id" => "b0688871-85db-4637-8fc9-043a240fcaec",
"name" => "Mario Simao",
"avatar_url" => "http://example.com",
Expand Down Expand Up @@ -80,6 +81,7 @@ public function test_user_array_conversion(): void
$array = [
"type" => "user",
"user" => [
"object" => "user",
"id" => "b0688871-85db-4637-8fc9-043a240fcaec",
"name" => "Mario Simao",
"avatar_url" => "http://example.com",
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Databases/Query/CompoundFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function test_and(): void
],
[
"timestamp" => "created_time",
"date" => [ "past_week" => new stdClass() ],
"created_time" => [ "past_week" => new stdClass() ],
],
],
];
Expand All @@ -48,7 +48,7 @@ public function test_or(): void
],
[
"timestamp" => "created_time",
"date" => [ "past_week" => new stdClass() ],
"created_time" => [ "past_week" => new stdClass() ],
],
],
];
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Databases/Query/DateFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function test_equals(): void

$expected = [
"timestamp" => "created_time",
"date" => [ "equals" => "2022-02-13" ],
"created_time" => [ "equals" => "2022-02-13" ],
];
$this->assertSame($expected, $filter->toArray());
}
Expand All @@ -58,7 +58,7 @@ public function test_before(): void

$expected = [
"timestamp" => "created_time",
"date" => [ "before" => "2021-05-10T12:00:00" ],
"created_time" => [ "before" => "2021-05-10T12:00:00" ],
];
$this->assertSame($expected, $filter->toArray());
}
Expand All @@ -70,7 +70,7 @@ public function test_after(): void

$expected = [
"timestamp" => "created_time",
"date" => [ "after" => "2021-05-10T12:00:00" ],
"created_time" => [ "after" => "2021-05-10T12:00:00" ],
];
$this->assertSame($expected, $filter->toArray());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Pages/Properties/CreatedByTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function test_array_conversion(): void
"id" => "abc",
"type" => "created_by",
"created_by" => [
"object" => "user",
"id" => "62e1fd10-8b04-41eb-97c1-d2deddd160d4",
"name" => "Mario",
"avatar_url" => null,
"type" => "person",
"person" => [ "email" => "mario@domain.com" ],
],
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Pages/Properties/LastEditedByTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function test_array_conversion(): void
"id" => "abc",
"type" => "last_edited_by",
"last_edited_by" => [
"object" => "user",
"id" => "62e1fd10-8b04-41eb-97c1-d2deddd160d4",
"name" => "Mario",
"avatar_url" => null,
"type" => "person",
"person" => [ "email" => "mario@domain.com" ],
],
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Pages/Properties/PeopleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public function test_array_conversion(): void
private function user1(): User
{
return User::fromArray([
"object" => "user",
"id" => "f98bfb6a-08b3-4e65-861b-6f68fb0c7a48",
"name" => "Mario",
"avatar_url" => null,
"type" => "person",
"person" => [ "email" => "mario@website.domain" ],
]);
Expand All @@ -83,9 +83,9 @@ private function user1(): User
private function user2(): User
{
return User::fromArray([
"object" => "user",
"id" => "f98bfb6a-08b3-4e65-861b-6f68fb0c7a48",
"name" => "Luigi",
"avatar_url" => null,
"type" => "person",
"person" => [ "email" => "luigi@website.domain" ],
]);
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Users/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class UserTest extends TestCase
public function test_person_from_array(): void
{
$array = [
"object" => "user",
"id" => "b0688871-85db-4637-8fc9-043a240fcaec",
"name" => "Mario Simao",
"avatar_url" => "http://example.com",
Expand All @@ -31,9 +32,9 @@ public function test_person_from_array(): void
public function test_bot_from_array(): void
{
$array = [
"object" => "user",
"id" => "b0688871-85db-4637-8fc9-043a240fcaec",
"name" => "Notion Bot",
"avatar_url" => null,
"type" => "bot",
"bot" => [],
];
Expand All @@ -49,9 +50,9 @@ public function test_bot_from_array(): void
public function test_invalid_type_from_array(): void
{
$array = [
"object" => "user",
"id" => "b0688871-85db-4637-8fc9-043a240fcaec",
"name" => "Invalid user",
"avatar_url" => null,
"type" => "wrong-type",
];

Expand Down

0 comments on commit cf794d4

Please sign in to comment.