From 2b475178a9a98c5a041ff580f53edf60da53eeb3 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Wed, 28 Jun 2023 14:29:46 +0100 Subject: [PATCH] Resource Tests - OPTIONS resource tests --- Tests/TestCase.php | 5 + Tests/View/Http/Controllers/ResourceTest.php | 80 +++ .../schema/options/resource-collection.json | 458 ++++++++++++++++++ 3 files changed, 543 insertions(+) create mode 100644 public/api/schema/options/resource-collection.json diff --git a/Tests/TestCase.php b/Tests/TestCase.php index f129acb7..b29cc749 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -703,6 +703,11 @@ protected function fetchOptionsForResource(array $parameters = []): TestResponse return $this->optionsRoute('resource.show.options', $parameters); } + protected function fetchOptionsForResourceCollection(array $parameters = []): TestResponse + { + return $this->optionsRoute('resource.list.options', $parameters); + } + protected function fetchOptionsForResourceType(array $parameters = []): TestResponse { return $this->optionsRoute('resource-type.show.options', $parameters); diff --git a/Tests/View/Http/Controllers/ResourceTest.php b/Tests/View/Http/Controllers/ResourceTest.php index 6ead527a..67998399 100644 --- a/Tests/View/Http/Controllers/ResourceTest.php +++ b/Tests/View/Http/Controllers/ResourceTest.php @@ -25,6 +25,22 @@ public function optionsRequestForAllocatedExpenseResource(): void $this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/options/resource.json'); } + /** @test */ + public function optionsRequestForAllocatedExpenseResourceCollection(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createAllocatedExpenseResourceType(); + + $response = $this->fetchOptionsForResourceCollection([ + 'resource_type_id' => $resource_type_id + ]); + $response->assertStatus(200); + + // Resource is the same for all types, we are testing the OPTIONS request for the different item types, until the resources differ later on. + $this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/options/resource-collection.json'); + } + /** @test */ public function optionsRequestForBudgetResource(): void { @@ -43,6 +59,22 @@ public function optionsRequestForBudgetResource(): void $this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/options/resource.json'); } + /** @test */ + public function optionsRequestForBudgetResourceCollection(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createBudgetResourceType(); + + $response = $this->fetchOptionsForResourceCollection([ + 'resource_type_id' => $resource_type_id + ]); + $response->assertStatus(200); + + // Resource is the same for all types, we are testing the OPTIONS request for the different item types, until the resources differ later on. + $this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/options/resource-collection.json'); + } + /** @test */ public function optionsRequestForBudgetProResource(): void { @@ -61,6 +93,22 @@ public function optionsRequestForBudgetProResource(): void $this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/options/resource.json'); } + /** @test */ + public function optionsRequestForBudgetProResourceCollection(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createBudgetProResourceType(); + + $response = $this->fetchOptionsForResourceCollection([ + 'resource_type_id' => $resource_type_id + ]); + $response->assertStatus(200); + + // Resource is the same for all types, we are testing the OPTIONS request for the different item types, until the resources differ later on. + $this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/options/resource-collection.json'); + } + /** @test */ public function optionsRequestForYahtzeeResource(): void { @@ -79,6 +127,22 @@ public function optionsRequestForYahtzeeResource(): void $this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/options/resource.json'); } + /** @test */ + public function optionsRequestForYahtzeeResourceCollection(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createGameResourceType(); + + $response = $this->fetchOptionsForResourceCollection([ + 'resource_type_id' => $resource_type_id + ]); + $response->assertStatus(200); + + // Resource is the same for all types, we are testing the OPTIONS request for the different item types, until the resources differ later on. + $this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/options/resource-collection.json'); + } + /** @test */ public function optionsRequestForYatzyResource(): void { @@ -96,4 +160,20 @@ public function optionsRequestForYatzyResource(): void // Resource is the same for all types, we are testing the OPTIONS request for the different item types, until the resources differ later on. $this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/options/resource.json'); } + + /** @test */ + public function optionsRequestForYatzyResourceCollection(): void + { + $this->actingAs(User::find(1)); + + $resource_type_id = $this->createGameResourceType(); + + $response = $this->fetchOptionsForResourceCollection([ + 'resource_type_id' => $resource_type_id + ]); + $response->assertStatus(200); + + // Resource is the same for all types, we are testing the OPTIONS request for the different item types, until the resources differ later on. + $this->assertProvidedJsonMatchesDefinedSchema($response->content(), 'api/schema/options/resource-collection.json'); + } } diff --git a/public/api/schema/options/resource-collection.json b/public/api/schema/options/resource-collection.json new file mode 100644 index 00000000..59dcacc9 --- /dev/null +++ b/public/api/schema/options/resource-collection.json @@ -0,0 +1,458 @@ +{ + "$id": "https://api.costs-to-expect.com/v2/api/schema/options/resource-collection.json", + "type": "object", + "properties": { + "GET": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "authentication": { + "type": "object", + "properties": { + "required": { + "type": "boolean" + }, + "authenticated": { + "type": "boolean" + } + }, + "required": [ + "required", + "authenticated" + ] + }, + "sortable": { + "type": "array", + "items": { + "type": "string" + } + }, + "searchable": { + "type": "object", + "properties": { + "name": { + "type": "object", + "properties": { + "type": { + "type": "string" + } + } + }, + "description": { + "type": "object", + "properties": { + "type": { + "type": "string" + } + } + } + }, + "required": [ + "name", + "description" + ] + }, + "filterable": { + "type": [ + "array" + ] + }, + "parameters": { + "type":"object", + "properties": { + "offset": { + "type": "object", + "properties": { + "parameter": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": { + "type": "integer" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "parameter", + "title", + "description", + "default", + "type", + "required" + ] + }, + "limit": { + "type": "object", + "properties": { + "parameter": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": { + "type": "integer" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "parameter", + "title", + "description", + "default", + "type", + "required" + ] + }, + "collection": { + "type": "object", + "properties": { + "parameter": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": { + "type": "boolean" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "parameter", + "title", + "description", + "default", + "type", + "required" + ] + }, + "sort": { + "type": "object", + "properties": { + "parameter": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": { + "type": "null" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "parameter", + "title", + "description", + "default", + "type", + "required" + ] + }, + "search": { + "type": "object", + "properties": { + "parameter": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": { + "type": "null" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "parameter", + "title", + "description", + "default", + "type", + "required" + ] + }, + "item-subtype": { + "type": "object", + "properties": { + "parameter": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": { + "type": "null" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + }, + "allowed_values": { + "type": "object" + } + }, + "required": [ + "parameter", + "title", + "description", + "default", + "type", + "required", + "allowed_values" + ] + } + }, + "required": [ + "offset", + "limit", + "collection", + "sort", + "search", + "item-subtype" + ] + } + }, + "required": [ + "description", + "authentication", + "sortable", + "searchable", + "filterable", + "parameters" + ] + }, + "POST": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "authentication": { + "type": "object", + "properties": { + "required": { + "type": "boolean" + }, + "authenticated": { + "type": "boolean" + } + }, + "required": [ + "required", + "authenticated" + ] + }, + "fields": { + "type": "object", + "properties": { + "name": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "validation": { + "type": "object", + "properties": { + "unique-for": { + "type": "string" + }, + "max-length": { + "type": "integer" + } + }, + "required": [ + "max-length" + ] + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "validation", + "required" + ] + }, + "description": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "required" + ] + }, + "data": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "required": { + "type": "boolean" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "required" + ] + }, + "item_subtype_id": { + "type": "object", + "properties": { + "field": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string" + }, + "validation": { + "type": "object", + "properties": { + "length": { + "type": "integer" + } + }, + "required": [ + "length" + ] + }, + "required": { + "type": "boolean" + }, + "allowed_values": { + "type": "object" + } + }, + "required": [ + "field", + "title", + "description", + "type", + "validation", + "required" + ] + } + }, + "required": [ + "name", + "description", + "data", + "item_subtype_id" + ] + } + }, + "required": [ + "description", + "authentication", + "fields", + "parameters" + ] + } + }, + "required": [ + "GET", + "POST" + ] +}