diff --git a/app/JsonApi/Schemas/GoalSchema.php b/app/JsonApi/Schemas/GoalSchema.php index 8a7c482..f2bd9ec 100644 --- a/app/JsonApi/Schemas/GoalSchema.php +++ b/app/JsonApi/Schemas/GoalSchema.php @@ -25,6 +25,7 @@ class GoalSchema extends SchemaProvider */ public function getAttributes($resource): array { + /** @var \App\Models\Goal $resource */ return [ 'name' => $resource->name, 'days' => $resource->days, diff --git a/tests/Feature/Http/Controllers/GoalControllerTest.php b/tests/Feature/Http/Controllers/GoalControllerTest.php index 8768912..350ef1f 100644 --- a/tests/Feature/Http/Controllers/GoalControllerTest.php +++ b/tests/Feature/Http/Controllers/GoalControllerTest.php @@ -41,4 +41,39 @@ class GoalControllerTest extends HttpControllerTestCase return $this->factory()->for($this->user)->create(); } + /** + * @inheritdoc + */ + public function testCanAddInstance(): void + { + $create_url = action([$this->class(), 'create']); + $response = $this->get($create_url); + $response->assertOk(); + + $data = $this->factory()->makeOne()->toArray(); + $data['days'] = Goal::days()->pluck('value')->random(3)->toArray(); + + $store_url = action([$this->class(), 'store']); + $response = $this->post($store_url, $data); + $response->assertSessionHasNoErrors(); + } + + /** + * @inheritdoc + */ + public function testCanEditInstance(): void + { + $instance = $this->createInstance(); + $edit_url = action([$this->class(), 'edit'], [$this->routeKey() => $instance]); + $response = $this->get($edit_url); + $response->assertOk(); + + $data = $this->factory()->makeOne()->toArray(); + $data['days'] = Goal::days()->pluck('value')->random(3)->toArray(); + + $put_url = action([$this->class(), 'update'], [$this->routeKey() => $instance]); + $response = $this->put($put_url, $data); + $response->assertSessionHasNoErrors(); + } + }