Skip to content

Commit 0de4de6

Browse files
authored
Testing bits (#69)
* Update AccountControllerTest.php * Update EmailVerificationControllerTest.php * Update HomeControllerTest.php * Update LoginControllerTest.php * Update LogoutControllerTest.php * Update RolesAndPermissionsSeeder.php * Update OrganisationControllerTest.php * Update RegisterControllerTest.php * Update ResetPasswordControllerTest.php
1 parent f44562d commit 0de4de6

9 files changed

+30
-7
lines changed

database/seeders/RolesAndPermissionsSeeder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ protected function createPermissions()
6161
protected function assignPermissionsToRoles()
6262
{
6363
$this->roles->get(Role::SUPER_ADMIN->value)->givePermissionTo($this->superAdminPermissions);
64+
$this->roles->get(Role::SUPER_ADMIN->value)->givePermissionTo($this->orgnaisationPermissions);
65+
$this->roles->get(Role::SUPER_ADMIN->value)->givePermissionTo($this->postPermissions);
6466

65-
$this->roles->get(Role::ADMIN->value)->givePermissionTo($this->postPermissions);
6667
$this->roles->get(Role::ADMIN->value)->givePermissionTo($this->orgnaisationPermissions);
68+
$this->roles->get(Role::ADMIN->value)->givePermissionTo($this->postPermissions);
6769

6870
$this->roles->get(Role::USER->value)->givePermissionTo($this->postPermissions);
6971
}

tests/Feature/Controllers/AccountControllerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
actingAs($user)
1717
->get(route('account.edit'))
18+
->assertOk()
1819
->assertInertia(
1920
fn (Assert $page) => $page
2021
->component('Account/Edit')
@@ -42,6 +43,7 @@
4243
'password' => 'newPassword#123',
4344
])
4445
->assertRedirectToRoute('account.edit')
46+
->assertSessionDoesntHaveErrors()
4547
->assertSessionHas('success', __('account.updated'));
4648

4749
expect($user->refresh())
@@ -62,10 +64,12 @@
6264
]);
6365

6466
actingAs($user)
67+
->from(route('account.edit'))
6568
->patch(route('account.update'), $newData = [
6669
'email' => 'jim@test.com',
6770
])
68-
->assertSessionHasErrors('email');
71+
->assertSessionHasErrors('email')
72+
->assertRedirectToRoute('account.edit');
6973

7074
expect($user->refresh()->email)->not()->toBe($newData['email']);
7175
});

tests/Feature/Controllers/EmailVerificationControllerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
test('Can access the verification page', function () {
1414
actingAs(User::factory()->unverified()->create())
1515
->get(route('verification.notice'))
16+
->assertOk()
1617
->assertInertia(
1718
fn (Assert $page) => $page
1819
->component('EmailVerification/Show')
@@ -32,6 +33,7 @@
3233
'id' => $user->getKey(),
3334
'hash' => sha1($user->getEmailForVerification()),
3435
]))
36+
->assertSessionDoesntHaveErrors()
3537
->assertRedirectToRoute('home');
3638

3739
expect($user->refresh()->email_verified_at)->not()->toBeNull();
@@ -45,6 +47,7 @@
4547
from(route('verification.notice'))
4648
->actingAs($user)
4749
->post(route('verification.send'))
50+
->assertSessionDoesntHaveErrors()
4851
->assertRedirectToRoute('verification.notice');
4952

5053
Notification::assertSentTo($user, Illuminate\Auth\Notifications\VerifyEmail::class);

tests/Feature/Controllers/HomeControllerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
test('Can access the home page', function () {
1111
actingAs(User::factory()->create())
1212
->get(route('home'))
13+
->assertOk()
1314
->assertInertia(
1415
fn (Assert $page) => $page
1516
->component('Dashboard/Index')

tests/Feature/Controllers/LoginControllerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
'email' => $user->email,
3838
'password' => '12345',
3939
])
40+
->assertSessionDoesntHaveErrors()
4041
->assertRedirectToRoute('home');
4142

4243
assertAuthenticated();
@@ -55,6 +56,7 @@
5556
'password' => '12345',
5657
'redirect' => $redirect,
5758
])
59+
->assertSessionDoesntHaveErrors()
5860
->assertRedirect($redirect);
5961

6062
assertAuthenticated();
@@ -69,7 +71,7 @@
6971
'email' => $user->email,
7072
'password' => 'test',
7173
])
72-
->assertsessionHasErrors();
74+
->assertSessionHasErrors();
7375

7476
assertGuest();
7577
});

tests/Feature/Controllers/LogoutControllerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
test('Can logout', function () {
1111
actingAs(User::factory()->create())
1212
->post(route('logout'))
13+
->assertSessionDoesntHaveErrors()
1314
->assertRedirectToRoute('login');
1415

1516
assertGuest();
@@ -19,6 +20,7 @@
1920
describe('Guests', function () {
2021
test("Can't logout", function () {
2122
post(route('logout'))
23+
->assertSessionDoesntHaveErrors()
2224
->assertRedirectToRoute('login');
2325
});
2426
});

tests/Feature/Controllers/OrganisationControllerTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use App\Models\User;
4+
use Inertia\Testing\AssertableInertia as Assert;
45

56
use function Pest\Laravel\actingAs;
67
use function Pest\Laravel\from;
@@ -23,7 +24,11 @@
2324
test('Can see the edit page for their current organisation', function () {
2425
actingAs($this->adminUser)
2526
->get(route('organisation.edit'))
26-
->assertOk();
27+
->assertOk()
28+
->assertInertia(
29+
fn (Assert $page) => $page
30+
->component('Organisation/Edit')
31+
);
2732
});
2833

2934
test("Can update their organisation's name", function () {
@@ -34,6 +39,7 @@
3439
->patch(route('organisation.update'), [
3540
'name' => 'New Name',
3641
])
42+
->assertSessionDoesntHaveErrors()
3743
->assertRedirectToRoute('organisation.edit');
3844

3945
expect($this->adminUser->organisation->refresh()->name)->toBe('New Name');
@@ -73,11 +79,11 @@
7379
describe('Guests', function () {
7480
test("Can't see the edit page of organisations", function () {
7581
get(route('organisation.edit'))
76-
->assertRedirect();
82+
->assertRedirectToRoute('login');
7783
});
7884

7985
test("Can't update organisations", function () {
8086
patch(route('organisation.edit'))
81-
->assertRedirect();
87+
->assertRedirectToRoute('login');
8288
});
8389
});

tests/Feature/Controllers/RegisterControllerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'email' => $email,
4040
'password' => 'P$ssword12345#',
4141
])
42+
->assertSessionDoesntHaveErrors()
4243
->assertRedirectToRoute('home');
4344

4445
assertDatabaseHas('users', [

tests/Feature/Controllers/ResetPasswordControllerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
post(route('password.store'), [
2929
'email' => $user->email,
3030
])
31+
->assertSessionDoesntHaveErrors()
3132
->assertRedirectToRoute('login');
3233

3334
Notification::assertSentTo($user, ResetPassword::class);
@@ -40,7 +41,7 @@
4041
->post(route('password.store'), [
4142
'email' => fake()->email(),
4243
])
43-
->assertsessionHasErrors('email')
44+
->assertSessionHasErrors('email')
4445
->assertRedirectToRoute('password');
4546

4647
Notification::assertNothingSent();
@@ -75,5 +76,6 @@
7576
'password' => $newPassword,
7677
'password_confirmation' => $newPassword,
7778
]))
79+
->assertSessionDoesntHaveErrors()
7880
->assertRedirectToRoute('login');
7981
});

0 commit comments

Comments
 (0)