Skip to content

Commit

Permalink
more generated model tests by sanitizing invalid example json + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vazaha-nl committed Aug 7, 2023
1 parent 4846659 commit 78751c8
Show file tree
Hide file tree
Showing 46 changed files with 3,261 additions and 2,565 deletions.
2 changes: 1 addition & 1 deletion src/Models/StatusEditModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class StatusEditModel extends Model
/**
* The account that published this revision.
*/
public string $account;
public AccountModel $account;

/**
* The current state of the poll options at this revision. Note that edits
Expand Down
108 changes: 56 additions & 52 deletions tests/Unit/Generated/Admin/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,58 @@ protected function setUp(): void
{
$this->json = <<<'JSON'
{
"id": "108965278956942133",
"username": "admin",
"domain": null,
"created_at": "2022-09-08T23:03:26.762Z",
"email": "[email protected]",
"ip": "192.168.42.1",
"role": {
"id": 3,
"name": "Owner",
"color": "",
"position": 1000,
"permissions": 1,
"highlighted": true,
"created_at": "2022-09-08T22:48:07.983Z",
"updated_at": "2022-09-08T22:48:07.983Z"
},
"confirmed": true,
"suspended": false,
"silenced": false,
"disabled": false,
"approved": true,
"locale": null,
"invite_request": null,
"ips": [
{
"ip": "192.168.42.1",
"used_at": "2022-09-15T01:38:58.851Z"
}
],
"account": {
"id": "108965278956942133",
"username": "admin",
"acct": "admin",
"display_name": "",
"locked": false,
"bot": false,
"discoverable": null,
"group": false,
"created_at": "2022-09-08T00:00:00.000Z",
"note": "",
"url": "http://mastodon.local/@admin",
"avatar": "http://mastodon.local/avatars/original/missing.png",
"avatar_static": "http://mastodon.local/avatars/original/missing.png",
"header": "http://mastodon.local/headers/original/missing.png",
"header_static": "http://mastodon.local/headers/original/missing.png",
"followers_count": 0,
"following_count": 0,
"statuses_count": 0,
"last_status_at": null,
"emojis": [],
"fields": []
}
"locale" : null,
"id" : "108965278956942133",
"created_at" : "2022-09-08T23:03:26.762Z",
"domain" : null,
"silenced" : false,
"role" : {
"permissions" : 1,
"position" : 1000,
"color" : "",
"id" : 3,
"created_at" : "2022-09-08T22:48:07.983Z",
"name" : "Owner",
"highlighted" : true,
"updated_at" : "2022-09-08T22:48:07.983Z"
},
"ips" : [
{
"ip" : "192.168.42.1",
"used_at" : "2022-09-15T01:38:58.851Z"
}
],
"disabled" : false,
"suspended" : false,
"approved" : true,
"ip" : "192.168.42.1",
"confirmed" : true,
"invite_request" : null,
"account" : {
"following_count" : 0,
"fields" : [],
"last_status_at" : null,
"url" : "http://mastodon.local/@admin",
"created_at" : "2022-09-08T00:00:00.000Z",
"id" : "108965278956942133",
"followers_count" : 0,
"header" : "http://mastodon.local/headers/original/missing.png",
"emojis" : [],
"avatar_static" : "http://mastodon.local/avatars/original/missing.png",
"note" : "",
"username" : "admin",
"statuses_count" : 0,
"locked" : false,
"display_name" : "",
"header_static" : "http://mastodon.local/headers/original/missing.png",
"avatar" : "http://mastodon.local/avatars/original/missing.png",
"group" : false,
"discoverable" : null,
"bot" : false,
"acct" : "admin"
},
"email" : "[email protected]",
"username" : "admin"
}

JSON;
Expand All @@ -86,6 +86,10 @@ public function testModelInstantation(): void
return;
}

if (array_is_list($array)) {
$array = $array[0] ?? [];
}

$model = AccountModel::fromArray($array);

foreach ($array as $property => $value) {
Expand Down
8 changes: 6 additions & 2 deletions tests/Unit/Generated/Admin/CanonicalEmailBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ protected function setUp(): void
{
$this->json = <<<'JSON'
{
"id": "2",
"canonical_email_hash": "b344e55d11b3fc25d0d53194e0475838bf17e9be67ce3e6469956222d9a34f9c"
"canonical_email_hash" : "b344e55d11b3fc25d0d53194e0475838bf17e9be67ce3e6469956222d9a34f9c",
"id" : "2"
}

JSON;
Expand All @@ -36,6 +36,10 @@ public function testModelInstantation(): void
return;
}

if (array_is_list($array)) {
$array = $array[0] ?? [];
}

$model = CanonicalEmailBlockModel::fromArray($array);

foreach ($array as $property => $value) {
Expand Down
10 changes: 7 additions & 3 deletions tests/Unit/Generated/Admin/DomainAllowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ protected function setUp(): void
{
$this->json = <<<'JSON'
{
"id": "1",
"domain": "mastodon.social",
"created_at": "2022-09-14T21:23:02.755Z"
"id" : "1",
"created_at" : "2022-09-14T21:23:02.755Z",
"domain" : "mastodon.social"
}

JSON;
Expand All @@ -37,6 +37,10 @@ public function testModelInstantation(): void
return;
}

if (array_is_list($array)) {
$array = $array[0] ?? [];
}

$model = DomainAllowModel::fromArray($array);

foreach ($array as $property => $value) {
Expand Down
22 changes: 13 additions & 9 deletions tests/Unit/Generated/Admin/DomainBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ protected function setUp(): void
{
$this->json = <<<'JSON'
{
"id": "1",
"domain": "example.com",
"created_at": "2022-11-16T08:15:34.238Z",
"severity": "noop",
"reject_media": false,
"reject_reports": false,
"private_comment": null,
"public_comment": null,
"obfuscate": false
"reject_media" : false,
"public_comment" : null,
"obfuscate" : false,
"reject_reports" : false,
"severity" : "noop",
"id" : "1",
"created_at" : "2022-11-16T08:15:34.238Z",
"domain" : "example.com",
"private_comment" : null
}

JSON;
Expand All @@ -43,6 +43,10 @@ public function testModelInstantation(): void
return;
}

if (array_is_list($array)) {
$array = $array[0] ?? [];
}

$model = DomainBlockModel::fromArray($array);

foreach ($array as $property => $value) {
Expand Down
84 changes: 44 additions & 40 deletions tests/Unit/Generated/Admin/EmailDomainBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,46 @@ protected function setUp(): void
{
$this->json = <<<'JSON'
{
"id": "1",
"domain": "foo",
"created_at": "2022-11-16T06:09:36.176Z",
"history": [
{
"day": "1668556800",
"accounts": "0",
"uses": "0"
},
{
"day": "1668470400",
"accounts": "0",
"uses": "0"
},
{
"day": "1668384000",
"accounts": "0",
"uses": "0"
},
{
"day": "1668297600",
"accounts": "0",
"uses": "0"
},
{
"day": "1668211200",
"accounts": "0",
"uses": "0"
},
{
"day": "1668124800",
"accounts": "0",
"uses": "0"
},
{
"day": "1668038400",
"accounts": "0",
"uses": "0"
}
]
"id" : "1",
"history" : [
{
"day" : "1668556800",
"uses" : "0",
"accounts" : "0"
},
{
"uses" : "0",
"accounts" : "0",
"day" : "1668470400"
},
{
"accounts" : "0",
"uses" : "0",
"day" : "1668384000"
},
{
"day" : "1668297600",
"uses" : "0",
"accounts" : "0"
},
{
"accounts" : "0",
"uses" : "0",
"day" : "1668211200"
},
{
"day" : "1668124800",
"accounts" : "0",
"uses" : "0"
},
{
"day" : "1668038400",
"accounts" : "0",
"uses" : "0"
}
],
"created_at" : "2022-11-16T06:09:36.176Z",
"domain" : "foo"
}

JSON;
Expand All @@ -74,6 +74,10 @@ public function testModelInstantation(): void
return;
}

if (array_is_list($array)) {
$array = $array[0] ?? [];
}

$model = EmailDomainBlockModel::fromArray($array);

foreach ($array as $property => $value) {
Expand Down
16 changes: 10 additions & 6 deletions tests/Unit/Generated/Admin/IpBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ protected function setUp(): void
{
$this->json = <<<'JSON'
{
"id": "1",
"ip": "8.8.8.8/32",
"severity": "no_access",
"comment": "",
"created_at": "2022-11-16T07:22:00.501Z",
"expires_at": null
"severity" : "no_access",
"created_at" : "2022-11-16T07:22:00.501Z",
"id" : "1",
"ip" : "8.8.8.8/32",
"expires_at" : null,
"comment" : ""
}

JSON;
Expand All @@ -40,6 +40,10 @@ public function testModelInstantation(): void
return;
}

if (array_is_list($array)) {
$array = $array[0] ?? [];
}

$model = IpBlockModel::fromArray($array);

foreach ($array as $property => $value) {
Expand Down
8 changes: 6 additions & 2 deletions tests/Unit/Generated/Admin/IpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ protected function setUp(): void
{
$this->json = <<<'JSON'
{
"ip": "192.168.42.1",
"used_at": "2022-09-15T01:38:58.851Z"
"used_at" : "2022-09-15T01:38:58.851Z",
"ip" : "192.168.42.1"
}

JSON;
Expand All @@ -36,6 +36,10 @@ public function testModelInstantation(): void
return;
}

if (array_is_list($array)) {
$array = $array[0] ?? [];
}

$model = IpModel::fromArray($array);

foreach ($array as $property => $value) {
Expand Down
Loading

0 comments on commit 78751c8

Please sign in to comment.