Skip to content

Commit

Permalink
refactor: move tests and did some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Oct 1, 2021
1 parent 021326a commit 1e63234
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Containers\AppSection\User\Tests\Unit;

use App\Containers\AppSection\User\Actions\RegisterUserAction;
use App\Containers\AppSection\User\Tasks\CreateUserByCredentialsTask;
use App\Containers\AppSection\User\Tests\TestCase;
use App\Containers\AppSection\User\UI\API\Requests\RegisterUserRequest;
use App\Ship\Exceptions\CreateResourceFailedException;
Expand All @@ -15,6 +16,17 @@
*/
class CreateUserByCredentialsTaskTest extends TestCase
{
public function testCreateUserByCredentials(): void
{
$data = [
'email' => '[email protected]',
'password' => 'so-secret',
];

$user = app(CreateUserByCredentialsTask::class)->run($data);

$this->assertModelExists($user);
}

public function testCreateUserWithoutEmail(): void
{
Expand All @@ -26,8 +38,7 @@ public function testCreateUserWithoutEmail(): void
'name' => 'Mahmoud',
];

$request = new RegisterUserRequest($data);
app(RegisterUserAction::class)->run($request);
app(CreateUserByCredentialsTask::class)->run($data);
}

public function testCreateUserWithoutPassword(): void
Expand All @@ -40,8 +51,7 @@ public function testCreateUserWithoutPassword(): void
'name' => 'Mahmoud',
];

$request = new RegisterUserRequest($data);
app(RegisterUserAction::class)->run($request);
app(CreateUserByCredentialsTask::class)->run($data);
}

public function testCreateUserWithInvalidData(): void
Expand All @@ -55,7 +65,6 @@ public function testCreateUserWithInvalidData(): void
'birth' => 'wrong-format',
];

$request = new RegisterUserRequest($data);
app(RegisterUserAction::class)->run($request);
app(CreateUserByCredentialsTask::class)->run($data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@
*/
class RegisterUserActionTest extends TestCase
{
public function testCreateUser(): void
public function testSendNotification_AfterUserRegistration(): void
{
Notification::fake();
$data = [
'email' => '[email protected]',
'password' => 'so-secret',
'name' => 'Mahmoud',
];

$request = new RegisterUserRequest($data);
$user = app(RegisterUserAction::class)->run($request);

$this->assertModelExists($user);
Notification::assertSentTo($user, UserRegisteredNotification::class);
}
}

0 comments on commit 1e63234

Please sign in to comment.