Skip to content

Commit

Permalink
fix(test): HTTP headers
Browse files Browse the repository at this point in the history
  • Loading branch information
leocavalcante committed Aug 15, 2023
1 parent ed1328e commit 0fd09a2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/Controller/PeopleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/Request/PeopleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}
Expand Down
35 changes: 35 additions & 0 deletions test/Cases/CreatePeopleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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' => '',
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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());
}
}

0 comments on commit 0fd09a2

Please sign in to comment.