Skip to content
Snippets Groups Projects
Commit b552bfbf authored by Jonathan Foucher's avatar Jonathan Foucher
Browse files

Fix user tests + validate that password contains a number on the backend

parent e8e069bf
No related branches found
No related tags found
No related merge requests found
Pipeline #30777 failed
...@@ -30,7 +30,7 @@ public function rules() ...@@ -30,7 +30,7 @@ public function rules()
'lastname' => 'string|nullable', 'lastname' => 'string|nullable',
'email' => 'nullable|email', 'email' => 'nullable|email',
'organization_id' => 'int|nullable', 'organization_id' => 'int|nullable',
'password' => 'string|nullable|min:9', 'password' => 'string|nullable|min:9|regex:/[0-9]/',
'role' => 'int', 'role' => 'int',
'last_login' => 'string|nullable', 'last_login' => 'string|nullable',
'civility' => 'string|required', 'civility' => 'string|required',
......
...@@ -248,7 +248,7 @@ public function testAdminCanCreateUser() ...@@ -248,7 +248,7 @@ public function testAdminCanCreateUser()
'firstname' => 'FIRSTNAME', 'firstname' => 'FIRSTNAME',
'lastname' => 'LASTNAME', 'lastname' => 'LASTNAME',
'email' => 'test@datakode.fr', 'email' => 'test@datakode.fr',
'password' => 'secret', 'password' => '1strongpassword',
'role' => User::ROLE_USER, 'role' => User::ROLE_USER,
'organization_id' => 1, 'organization_id' => 1,
'civility' => 'Madame', 'civility' => 'Madame',
...@@ -278,6 +278,51 @@ public function testAdminCanCreateUser() ...@@ -278,6 +278,51 @@ public function testAdminCanCreateUser()
$this->assertEquals(1, $newUser->organization_id); $this->assertEquals(1, $newUser->organization_id);
} }
/**
* Test user create.
*/
public function testShortPasswordFails()
{
$user = User::where('role', User::ROLE_ADMIN)->with('organization')->first();
$response = $this->actingAs($user)->postJson(route('api.users.post'), [
'firstname' => 'FIRSTNAME',
'lastname' => 'LASTNAME',
'email' => 'test@datakode.fr',
'password' => 'test',
'role' => User::ROLE_USER,
'organization_id' => 1,
'civility' => 'Madame',
]);
$response->assertStatus(422);
$response->assertJson(['message' => 'Le texte password doit contenir au moins 9 caractères.']);
}
/**
* Test user create.
*/
public function testNoNumberPasswordFails()
{
$user = User::where('role', User::ROLE_ADMIN)->with('organization')->first();
$response = $this->actingAs($user)->postJson(route('api.users.post'), [
'firstname' => 'FIRSTNAME',
'lastname' => 'LASTNAME',
'email' => 'test@datakode.fr',
'password' => 'testtesttest',
'role' => User::ROLE_USER,
'organization_id' => 1,
'civility' => 'Madame',
]);
$response->assertStatus(422);
$response->assertJson(['message' => 'Le format du champ password est invalide.']);
}
/** /**
* Test user create. * Test user create.
*/ */
...@@ -289,7 +334,7 @@ public function testUserCannotCreateUser() ...@@ -289,7 +334,7 @@ public function testUserCannotCreateUser()
'firstname' => 'FIRSTNAME', 'firstname' => 'FIRSTNAME',
'lastname' => 'LASTNAME', 'lastname' => 'LASTNAME',
'email' => 'test@datakode.fr', 'email' => 'test@datakode.fr',
'password' => 'secret', 'password' => '1strongpassword',
'role' => User::ROLE_USER, 'role' => User::ROLE_USER,
'civility' => 'Madame', 'civility' => 'Madame',
]); ]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment