forked from apiato/apiato
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove name 'require' validation and update/improve tests
- Loading branch information
1 parent
73b175f
commit f8147dc
Showing
2 changed files
with
35 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace App\Containers\AppSection\User\UI\API\Tests\Functional; | ||
|
||
use App\Containers\AppSection\User\UI\API\Tests\ApiTestCase; | ||
use Illuminate\Testing\Fluent\AssertableJson; | ||
|
||
/** | ||
* Class RegisterUserTest. | ||
|
@@ -25,120 +26,94 @@ public function testRegisterNewUserWithCredentials(): void | |
{ | ||
$data = [ | ||
'email' => '[email protected]', | ||
'name' => 'Apiato', | ||
'password' => 'secretpass', | ||
]; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
$response->assertStatus(200); | ||
$this->assertResponseContainKeyValue([ | ||
'email' => $data['email'], | ||
'name' => $data['name'], | ||
]); | ||
$responseContent = $this->getResponseContentObject(); | ||
$this->assertNotEmpty($responseContent->data); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => | ||
$json->has('data') | ||
->where('data.email', $data['email']) | ||
->etc() | ||
); | ||
} | ||
|
||
public function testRegisterNewUserUsingGetVerb(): void | ||
{ | ||
$data = [ | ||
'email' => '[email protected]', | ||
'name' => 'Apiato', | ||
'password' => 'secret', | ||
]; | ||
|
||
$response = $this->endpoint('get@v1/register')->makeCall($data); | ||
|
||
$response->assertStatus(405); | ||
$this->assertResponseContainKeyValue([ | ||
'message' => 'The GET method is not supported for this route. Supported methods: POST.', | ||
]); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => | ||
$json->has('message') | ||
->where('message', 'The GET method is not supported for this route. Supported methods: POST.') | ||
->etc() | ||
); | ||
} | ||
|
||
public function testRegisterExistingUser(): void | ||
{ | ||
$userDetails = [ | ||
'email' => '[email protected]', | ||
'name' => 'Apiato', | ||
'password' => 'secret', | ||
]; | ||
|
||
$this->getTestingUser($userDetails); | ||
|
||
$data = [ | ||
'email' => $userDetails['email'], | ||
'name' => $userDetails['name'], | ||
'password' => $userDetails['password'], | ||
]; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
$response->assertStatus(422); | ||
$this->assertValidationErrorContain([ | ||
'email' => 'The email has already been taken.', | ||
]); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => | ||
$json->has('errors') | ||
->where('errors.email.0', 'The email has already been taken.') | ||
->etc() | ||
); | ||
} | ||
|
||
public function testRegisterNewUserWithoutEmail(): void | ||
public function testRegisterNewUserWithoutData(): void | ||
{ | ||
$data = [ | ||
'name' => 'Apiato', | ||
'password' => 'secret', | ||
]; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
$response->assertStatus(422); | ||
// assert response contain the correct message | ||
$this->assertValidationErrorContain([ | ||
'email' => 'The email field is required.', | ||
]); | ||
} | ||
|
||
public function testRegisterNewUserWithoutName(): void | ||
{ | ||
$data = [ | ||
'email' => '[email protected]', | ||
'password' => 'secret', | ||
]; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
$response->assertStatus(422); | ||
$this->assertValidationErrorContain([ | ||
'name' => 'The name field is required.', | ||
]); | ||
} | ||
|
||
public function testRegisterNewUserWithoutPassword(): void | ||
{ | ||
$data = [ | ||
'email' => '[email protected]', | ||
'name' => 'Apiato', | ||
]; | ||
$data = []; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
$response->assertStatus(422); | ||
$this->assertValidationErrorContain([ | ||
'password' => 'The password field is required.', | ||
]); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => | ||
$json->has('errors') | ||
->where('errors.email.0', 'The email field is required.') | ||
->where('errors.password.0', 'The password field is required.') | ||
->etc() | ||
); | ||
} | ||
|
||
public function testRegisterNewUserWithInvalidEmail(): void | ||
{ | ||
$data = [ | ||
'email' => 'missing-at.test', | ||
'name' => 'Apiato', | ||
'password' => 'secret', | ||
]; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
$response->assertStatus(422); | ||
$this->assertValidationErrorContain([ | ||
'email' => 'The email must be a valid email address.', | ||
]); | ||
$response->assertJson( | ||
fn (AssertableJson $json) => | ||
$json->has('errors') | ||
->where('errors.email.0', 'The email must be a valid email address.') | ||
->etc() | ||
); | ||
} | ||
} |