some vibe tests
better than none
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\DatabaseTestCase;
|
||||
|
||||
class AuthenticationTest extends DatabaseTestCase
|
||||
{
|
||||
/** @dataProvider protectedRoutes */
|
||||
public function test_guests_are_redirected_to_login($method, $path)
|
||||
{
|
||||
$this->call($method, $path)->assertRedirect('/login');
|
||||
}
|
||||
|
||||
public function protectedRoutes()
|
||||
{
|
||||
return [
|
||||
['GET', '/bookings/year-2020'], ['GET', '/people'],
|
||||
['GET', '/projects'], ['GET', '/targets'],
|
||||
['GET', '/reports/balances/2020'], ['GET', '/reports/scopes/compact/2020'],
|
||||
['POST', '/bookings'], ['PATCH', '/bookings/1'], ['DELETE', '/bookings/1'],
|
||||
];
|
||||
}
|
||||
|
||||
public function test_login_form_is_available()
|
||||
{
|
||||
$this->get('/login')->assertStatus(200)->assertSee('password');
|
||||
}
|
||||
|
||||
public function test_guests_cannot_change_or_delete_an_existing_booking()
|
||||
{
|
||||
$booking = $this->booking('2020-01-15', 100);
|
||||
$this->patch('/bookings/' . $booking->id, [
|
||||
'booking' => ['reference' => 'Unauthorized change'],
|
||||
])->assertRedirect('/login');
|
||||
$this->delete('/bookings/' . $booking->id)->assertRedirect('/login');
|
||||
$this->assertSame('Test booking', $booking->fresh()->reference);
|
||||
$this->assertCount(1, $booking->fresh()->subBookings);
|
||||
}
|
||||
|
||||
public function test_valid_credentials_log_in_and_redirect_to_bookings()
|
||||
{
|
||||
$this->post('/login', ['email' => $this->user->email, 'password' => 'test-password'])
|
||||
->assertRedirect('/bookings');
|
||||
$this->assertAuthenticatedAs($this->user);
|
||||
}
|
||||
|
||||
public function test_wrong_password_is_rejected()
|
||||
{
|
||||
$this->from('/login')->post('/login', [
|
||||
'email' => $this->user->email, 'password' => 'wrong-password',
|
||||
])->assertRedirect('/login')->assertSessionHasErrors('email');
|
||||
$this->assertGuest();
|
||||
}
|
||||
|
||||
public function test_logout_ends_authentication()
|
||||
{
|
||||
$this->actingAs($this->user)->post('/logout')->assertRedirect('/login');
|
||||
$this->assertGuest();
|
||||
$this->get('/bookings/year-2020')->assertRedirect('/login');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user