diff --git a/app/Controller/PeopleController.php b/app/Controller/PeopleController.php index e0c218ef..842350be 100644 --- a/app/Controller/PeopleController.php +++ b/app/Controller/PeopleController.php @@ -23,7 +23,7 @@ public function create(PeopleRequest $request, ResponseInterface $response): Mes { $person = $request->validated(); - return $response->json($person); + return $response->json($person)->withStatus(201); } public function show(RequestInterface $request, ResponseInterface $response): MessageResponseInterface diff --git a/app/Request/PeopleRequest.php b/app/Request/PeopleRequest.php index 49e3d03d..f17dfbc4 100644 --- a/app/Request/PeopleRequest.php +++ b/app/Request/PeopleRequest.php @@ -31,8 +31,8 @@ public function authorize(): bool public function rules(): array { return [ - 'apelido' => 'required|size:32', - 'nome' => 'required|size:100', + 'apelido' => 'required|max:32', + 'nome' => 'required|max:100', 'nascimento' => 'required|date_format:Y-m-d', ]; } diff --git a/test/Cases/CreatePeopleTest.php b/test/Cases/CreatePeopleTest.php index b0768846..2a00fac5 100644 --- a/test/Cases/CreatePeopleTest.php +++ b/test/Cases/CreatePeopleTest.php @@ -27,6 +27,9 @@ public function testCreatePeopleWithEmptyNickname(): void { /** @var Response $response */ $response = $this->request('post', '/pessoas', [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], 'json' => [ 'apelido' => '', 'nome' => 'OpenCodeCo', @@ -41,6 +44,9 @@ public function testCreatePeopleWithNullNickname(): void { /** @var Response $response */ $response = $this->request('post', '/pessoas', [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], 'json' => [ 'apelido' => null, 'nome' => 'OpenCodeCo', @@ -55,6 +61,9 @@ public function testCreatePeopleWithEmptyName(): void { /** @var Response $response */ $response = $this->request('post', '/pessoas', [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], 'json' => [ 'apelido' => 'opencodeco', 'nome' => '', @@ -69,6 +78,9 @@ public function testCreatePeopleWithNullName(): void { /** @var Response $response */ $response = $this->request('post', '/pessoas', [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], 'json' => [ 'apelido' => 'opencodeco', 'nome' => null, @@ -83,6 +95,9 @@ public function testCreatePeopleWithEmptyBirthDate(): void { /** @var Response $response */ $response = $this->request('post', '/pessoas', [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], 'json' => [ 'apelido' => 'opencodeco', 'nome' => 'OpenCodeCo', @@ -97,6 +112,9 @@ public function testCreatePeopleWithNullBirthDate(): void { /** @var Response $response */ $response = $this->request('post', '/pessoas', [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], 'json' => [ 'apelido' => 'opencodeco', 'nome' => 'OpenCodeCo', @@ -106,4 +124,21 @@ public function testCreatePeopleWithNullBirthDate(): void assertSame(422, $response->getStatusCode()); } + + public function testCreatePeople(): void + { + /** @var Response $response */ + $response = $this->request('POST', '/pessoas', [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], + 'json' => [ + 'apelido' => 'opencodeco', + 'nome' => 'OpenCodeCo', + 'nascimento' => '2023-07-01', + ], + ]); + + assertSame(201, $response->getStatusCode()); + } }