-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45cb070
commit 8bdbb7e
Showing
21 changed files
with
481 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 48 additions & 67 deletions
115
tests/Http/Controllers/Auth/AuthenticatedSessionControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,55 @@ | ||
<?php | ||
|
||
namespace Outhebox\TranslationsUI\Tests\Http\Controllers\Auth; | ||
|
||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Validation\ValidationException; | ||
use Outhebox\TranslationsUI\Enums\RoleEnum; | ||
use Outhebox\TranslationsUI\Models\Contributor; | ||
use Outhebox\TranslationsUI\Tests\TestCase; | ||
|
||
class AuthenticatedSessionControllerTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function login_page_can_be_rendered() | ||
{ | ||
$this->get(route('ltu.login')) | ||
->assertStatus(200); | ||
|
||
} | ||
|
||
/** @test */ | ||
public function login_request_will_validate_email(): void | ||
{ | ||
$response = $this->post(route('ltu.login.attempt'), [ | ||
'email' => 'not-an-email', | ||
'password' => 'password', | ||
])->assertRedirect(route('ltu.login')); | ||
|
||
$this->assertInstanceOf(ValidationException::class, $response->exception); | ||
} | ||
|
||
/** @test */ | ||
public function login_request_will_validate_password(): void | ||
{ | ||
$response = $this->post(route('ltu.login.attempt'), [ | ||
'email' => $this->owner->email, | ||
'password' => 'what-is-my-password', | ||
])->assertSessionHasErrors(); | ||
|
||
$this->assertInstanceOf(ValidationException::class, $response->exception); | ||
} | ||
|
||
/** @test */ | ||
public function login_request_will_authenticate_user(): void | ||
{ | ||
$this->withoutExceptionHandling(); | ||
|
||
$user = Contributor::factory([ | ||
'role' => RoleEnum::owner, | ||
'password' => Hash::make('password'), | ||
])->create(); | ||
|
||
$this->post(route('ltu.login.attempt'), [ | ||
'email' => $user->email, | ||
'password' => 'password', | ||
])->assertRedirect(route('ltu.translation.index')); | ||
} | ||
|
||
/** @test */ | ||
public function authenticated_users_can_access_dashboard(): void | ||
{ | ||
$this->actingAs($this->owner, 'translations') | ||
->get(route('ltu.login')) | ||
->assertRedirect(route('ltu.translation.index')); | ||
} | ||
|
||
/** @test */ | ||
public function authenticated_users_can_logout(): void | ||
{ | ||
$this->actingAs($this->owner, 'translations') | ||
->get(route('ltu.logout')) | ||
->assertRedirect(route('ltu.login')); | ||
} | ||
} | ||
it('login page can be rendered', function () { | ||
$this->get(route('ltu.login')) | ||
->assertStatus(200); | ||
}); | ||
|
||
it('login request will validate email', function () { | ||
$response = $this->post(route('ltu.login.attempt'), [ | ||
'email' => 'not-an-email', | ||
'password' => 'password', | ||
])->assertRedirect(route('ltu.login')); | ||
|
||
expect($response->exception)->toBeInstanceOf(ValidationException::class); | ||
}); | ||
|
||
it('login request will validate password', function () { | ||
$response = $this->post(route('ltu.login.attempt'), [ | ||
'email' => $this->owner->email, | ||
'password' => 'what-is-my-password', | ||
])->assertSessionHasErrors(); | ||
|
||
expect($response->exception)->toBeInstanceOf(ValidationException::class); | ||
}); | ||
|
||
it('login request will authenticate user', function () { | ||
$this->withoutExceptionHandling(); | ||
|
||
$user = Contributor::factory([ | ||
'role' => RoleEnum::owner, | ||
'password' => Hash::make('password'), | ||
])->create(); | ||
|
||
$this->post(route('ltu.login.attempt'), [ | ||
'email' => $user->email, | ||
'password' => 'password', | ||
])->assertRedirect(route('ltu.translation.index')); | ||
}); | ||
|
||
it('authenticated users can access dashboard', function () { | ||
$this->actingAs($this->owner, 'translations') | ||
->get(route('ltu.login')) | ||
->assertRedirect(route('ltu.translation.index')); | ||
}); | ||
|
||
it('authenticated users can logout', function () { | ||
$this->actingAs($this->owner, 'translations') | ||
->get(route('ltu.logout')) | ||
->assertRedirect(route('ltu.login')); | ||
}); |
Oops, something went wrong.