Sistema de controles da União de Ciclistas do Brasil
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

132 lines
3.6 KiB

<?php
namespace Tests\Feature\Associates\Auth\Passwords;
use App\Associate;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Livewire\Livewire;
use Tests\TestCase;
class ResetTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function can_view_password_reset_page()
{
$associate = factory(Associate::class)->create();
$token = Str::random(16);
DB::table('associate_password_resets')->insert([
'email' => $associate->email,
'token' => Hash::make($token),
'created_at' => Carbon::now(),
]);
$this->get(route('password.reset', [
'email' => $associate->email,
'token' => $token,
]))
->assertSuccessful()
->assertSeeLivewire('associates.auth.passwords.reset');
}
/** @test */
public function can_reset_password()
{
$associate = factory(Associate::class)->create();
$token = Str::random(16);
DB::table('associate_password_resets')->insert([
'email' => $associate->email,
'token' => Hash::make($token),
'created_at' => Carbon::now(),
]);
Livewire::test('associates.auth.passwords.reset', [
'token' => $token,
])
->set('email', $associate->email)
->set('password', 'new-password')
->set('passwordConfirmation', 'new-password')
->call('resetPassword');
$this->assertTrue(Auth::attempt([
'email' => $associate->email,
'password' => 'new-password',
]));
}
/** @test */
public function token_is_required()
{
Livewire::test('associates.auth.passwords.reset', [
'token' => null,
])
->call('resetPassword')
->assertHasErrors(['token' => 'required']);
}
/** @test */
public function email_is_required()
{
Livewire::test('associates.auth.passwords.reset', [
'token' => Str::random(16),
])
->set('email', null)
->call('resetPassword')
->assertHasErrors(['email' => 'required']);
}
/** @test */
public function email_is_valid_email()
{
Livewire::test('associates.auth.passwords.reset', [
'token' => Str::random(16),
])
->set('email', 'email')
->call('resetPassword')
->assertHasErrors(['email' => 'email']);
}
/** @test */
function password_is_required()
{
Livewire::test('associates.auth.passwords.reset', [
'token' => Str::random(16),
])
->set('password', '')
->call('resetPassword')
->assertHasErrors(['password' => 'required']);
}
/** @test */
function password_is_minimum_of_eight_characters()
{
Livewire::test('associates.auth.passwords.reset', [
'token' => Str::random(16),
])
->set('password', 'secret')
->call('resetPassword')
->assertHasErrors(['password' => 'min']);
}
/** @test */
function password_matches_password_confirmation()
{
Livewire::test('associates.auth.passwords.reset', [
'token' => Str::random(16),
])
->set('password', 'new-password')
->set('passwordConfirmation', 'not-new-password')
->call('resetPassword')
->assertHasErrors(['password' => 'same']);
}
}