Skip to content

Commit 310d56e

Browse files
committed
feat: simplify user login in tests by using loginAsUser helper
1 parent 7c92752 commit 310d56e

File tree

11 files changed

+36
-4
lines changed

11 files changed

+36
-4
lines changed

contexts/ArticlePublishing/Tests/Feature/ArticlePublishingTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Contexts\ArticlePublishing\Domain\Events\ArticlePublishedEvent;
66
use Contexts\ArticlePublishing\Domain\Gateway\AuthorizationGateway;
7-
use Contexts\Authorization\Infrastructure\Records\UserRecord;
87
use Contexts\CategoryManagement\Infrastructure\Records\CategoryRecord;
98

109
beforeEach(function () {
@@ -16,8 +15,7 @@
1615

1716
$this->categories = CategoryRecord::factory(2)->create();
1817

19-
$userRecord = UserRecord::factory()->create();
20-
$this->actingAs($userRecord);
18+
$this->loginAsUser();
2119
});
2220

2321
it('can publish aritcle drafts via api', function () {

contexts/ArticlePublishing/Tests/Feature/Requests/CreateArticleRequestTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
declare(strict_types=1);
44

5+
beforeEach(function () {
6+
$this->loginAsUser();
7+
});
8+
59
it('[smoke test] requires a title field', function () {
610
$response = $this->postJson('articles', [
711
'body' => 'This is test body',

contexts/ArticlePublishing/Tests/Feature/Requests/PublishDraftRequestTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
declare(strict_types=1);
44

5+
beforeEach(function () {
6+
$this->loginAsUser();
7+
});
8+
59
it('[smoke test] id must greater than 0', function () {
610
$response = $this->putJson('articles/-1/publish');
711

contexts/Authorization/Infrastructure/Routes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
declare(strict_types=1);
44

5+
use App\Http\Middlewares\AuthenticateMiddleware;
56
use Contexts\Authorization\Presentation\Controllers\AuthenticationController;
67
use Contexts\Authorization\Presentation\Controllers\RoleController;
78
use Contexts\Authorization\Presentation\Controllers\UserIdentityController;
89
use Illuminate\Support\Facades\Route;
910

10-
Route::middleware([])->name('Authentication')->group(function () {
11+
Route::name('Authentication')->withoutMiddleware(AuthenticateMiddleware::class)->group(function () {
1112
Route::controller(AuthenticationController::class)->prefix('auth')->name('Auth.')->group(function () {
1213
Route::post('login', 'login')->name('login');
1314
});

contexts/Authorization/Tests/Feature/PolicyTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
$this->roleLabelUniquenessService = mock(RoleLabelUniquenessService::class);
3636
$this->roleLabelUniquenessService->shouldReceive('ensureUnique')->andReturn(true);
3737
$this->roleFactory = new RoleFactory($this->roleLabelUniquenessService);
38+
$this->loginAsUser();
3839
});
3940

4041
it('can get default policy handler', function () {

contexts/Authorization/Tests/Feature/Requests/CreateRoleRequestTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
declare(strict_types=1);
44

5+
beforeEach(function () {
6+
$this->loginAsUser();
7+
});
8+
59
it('[smoke test] requires a label field', function () {
610
$response = $this->postJson('roles', []);
711

contexts/Authorization/Tests/Feature/Requests/CreateUserRequestTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
declare(strict_types=1);
44

5+
beforeEach(function () {
6+
$this->loginAsUser();
7+
});
8+
59
it('[smoke test] requires a email field', function () {
610
$response = $this->postJson('users', []);
711

contexts/Authorization/Tests/Feature/RoleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
use Contexts\Authorization\Domain\Role\Models\RoleStatus;
55
use Contexts\Authorization\Infrastructure\Records\RoleRecord;
66

7+
beforeEach(function () {
8+
$this->loginAsUser();
9+
});
10+
711
it('can create active roles via api', function () {
812
$response = $this->postJson('roles', [
913
'label' => 'My Role',

contexts/Authorization/Tests/Feature/UserTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
use Contexts\Authorization\Infrastructure\Records\RoleRecord;
66

7+
beforeEach(function () {
8+
$this->loginAsUser();
9+
});
10+
711
it('can create active users via api', function () {
812
$response = $this->postJson('users', [
913
'email' => 'test@email.com',

contexts/CategoryManagement/Tests/Feature/CategoryTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
declare(strict_types=1);
44

5+
beforeEach(function () {
6+
$this->loginAsUser();
7+
});
8+
59
it('can create active categories via api', function () {
610
$response = $this->postJson('categories', [
711
'label' => 'My Category',

0 commit comments

Comments
 (0)