Skip to content

Commit

Permalink
SomeMissingErrorsInTestImproveService
Browse files Browse the repository at this point in the history
  • Loading branch information
JustTheDude001 committed May 16, 2024
1 parent 80a1f5f commit 5ecefab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
3 changes: 1 addition & 2 deletions app/Service/User/UserRegisterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function createUser(RegisterRequest $registerData): array | bool

$success['token'] = $user->createToken('ITAcademy')->accessToken;


DB::commit();
} catch (\PDOException $e) {
// Woopsy
Expand All @@ -50,7 +49,7 @@ public function createUser(RegisterRequest $registerData): array | bool
if(empty($user->email)){
return False;
}*/

//$success['token'] = $user->createToken('ITAcademy')->accessToken;
$success['email'] = $user->email;

return $success;
Expand Down
41 changes: 30 additions & 11 deletions tests/Feature/Service/User/RegisterUserServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ public function test_required_fields_for_user_creation()
/**
* @dataProvider required_fields_for_user_creation_provider
*/
public function test_required_fields_for_user_creation_my(array $array)
public function test_required_fields_for_user_creation_my(array $array, bool $resultCorrect)
{
// Missing 'username' field
$registerData1 = new RegisterRequest([
$registerData = new RegisterRequest([
//'username' => 'test_username',
'username' => $array['username'] ?? "",
'specialization' => $array['specialization'] ?? "",
Expand All @@ -214,15 +214,25 @@ public function test_required_fields_for_user_creation_my(array $array)
]);

//$this->expectException(Exception::class);
$this->userService->createUser($registerData1);
$succes = $this->userService->createUser($registerData1);
$this->assertEquals(False, $succes);
//$this->userService->createUser($registerData1);
$success = $this->userService->createUser($registerData);
//$this->assertEquals(False, $succes);
//$this->assertEquals($this->validationMessage, $succes);

if($resultCorrect){
//$this->assertEquals($this->validationMessage, $succes);
$this->assertEquals(True, empty($success['email']) == False && empty($success['token']) == False );

}else{
$this->assertEquals($resultCorrect, $success);
}

}

static function required_fields_for_user_creation_provider()
{
$array = array(
// Missing 'username' field
// Missing 'username' field - 0
array(
array(
//'username' => 'hoho',
Expand All @@ -232,8 +242,9 @@ static function required_fields_for_user_creation_provider()
'password' => 'password123',
'dni' => '27827083G'
),
True
),
// Missing 'email' field
// Missing 'email' field - 1
array(
array(
'username' => 'test_username',
Expand All @@ -242,8 +253,10 @@ static function required_fields_for_user_creation_provider()
'password' => 'password123',
'dni' => '27827083G'
),
//Returning False because email is not specified
False
),
// Missing 'dni' field
// Missing 'password' field - 2
array(
array(
'username' => 'test_username',
Expand All @@ -252,8 +265,10 @@ static function required_fields_for_user_creation_provider()
'email' => '[email protected]',
'dni' => '27827083G'
),
True
),
// Missing 'specialization' field

//// Missing 'dni' field - 3
array(
array(
'username' => 'test_username',
Expand All @@ -262,8 +277,9 @@ static function required_fields_for_user_creation_provider()
'terms' => 'true',
'password' => 'password123'
),
True
),
// Missing 'terms' field
// Missing 'specialization' field - 4
array(
array(
'username' => 'Alice Brown',
Expand All @@ -272,9 +288,11 @@ static function required_fields_for_user_creation_provider()
'terms' => 'true',
'password' => 'password123'
),
//False because "specialization" not in DB ENUM
False
),

// Missing 'terms' field
// Missing 'terms' field - 5
array(
array(
'username' => 'Alice Brown',
Expand All @@ -283,6 +301,7 @@ static function required_fields_for_user_creation_provider()
'specialization' => 'Backend',
'password' => 'password123'
),
True
),


Expand Down

0 comments on commit 5ecefab

Please sign in to comment.