Browse Source

Corrige testes

usuarios_separados
Guilherme Capanema 6 years ago
parent
commit
600b88a43f
6 changed files with 90 additions and 90 deletions
  1. +13
    -13
      app/Http/Livewire/Auth/Register/Individual.php
  2. +15
    -15
      tests/Feature/Auth/LoginTest.php
  3. +5
    -5
      tests/Feature/Auth/LogoutTest.php
  4. +8
    -8
      tests/Feature/Auth/Passwords/EmailTest.php
  5. +10
    -10
      tests/Feature/Auth/Passwords/ResetTest.php
  6. +39
    -39
      tests/Feature/Auth/Register/IndividualTest.php

+ 13
- 13
app/Http/Livewire/Auth/Register/Individual.php View File

@ -3,10 +3,10 @@
namespace App\Http\Livewire\Auth\Register; namespace App\Http\Livewire\Auth\Register;
use App\Providers\RouteServiceProvider; use App\Providers\RouteServiceProvider;
use App\User;
use App\UserCategory;
use App\UserNature;
use App\UserType;
use App\Associate;
use App\AssociateCategory;
use App\AssociateNature;
use App\AssociateType;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
@ -81,7 +81,7 @@ class Individual extends Component
'discussion' => ['string', 'in:all,daily,occasional'], 'discussion' => ['string', 'in:all,daily,occasional'],
'document.number' => ['string'], 'document.number' => ['string'],
'document.type' => ['string', 'in:cpf,identity,passport'], 'document.type' => ['string', 'in:cpf,identity,passport'],
'email' => ['email', 'unique:users'],
'email' => ['email', 'unique:associates'],
'profile.bike_activities' => ['string'], 'profile.bike_activities' => ['string'],
'profile.bike_use' => ['string'], 'profile.bike_use' => ['string'],
'profile.comments' => ['string'], 'profile.comments' => ['string'],
@ -114,7 +114,7 @@ class Individual extends Component
$this->dispatchBrowserEvent('address-autofilled'); $this->dispatchBrowserEvent('address-autofilled');
} }
} catch (\Illuminate\Http\Client\ConnectionException $exception) { } catch (\Illuminate\Http\Client\ConnectionException $exception) {
// TODO: show error to user
// TODO: show error to associate
} }
} }
} }
@ -135,7 +135,7 @@ class Individual extends Component
'discussion' => ['required', 'string', 'in:all,daily,occasional'], 'discussion' => ['required', 'string', 'in:all,daily,occasional'],
'document.number' => ['required', 'string'], 'document.number' => ['required', 'string'],
'document.type' => ['required', 'string', 'in:cpf,identity,passport'], 'document.type' => ['required', 'string', 'in:cpf,identity,passport'],
'email' => ['required', 'email', 'unique:users'],
'email' => ['required', 'email', 'unique:associates'],
'name' => ['required'], 'name' => ['required'],
'profile.bike_activities' => ['nullable', 'string'], 'profile.bike_activities' => ['nullable', 'string'],
'profile.bike_use' => ['nullable', 'string'], 'profile.bike_use' => ['nullable', 'string'],
@ -152,7 +152,7 @@ class Individual extends Component
'profile.website' => ['nullable', 'string'], 'profile.website' => ['nullable', 'string'],
]); ]);
$user = new User([
$associate = new Associate([
'address' => $this->address, 'address' => $this->address,
'birthday' => Carbon::createFromFormat('d/m/Y', $this->birthday), 'birthday' => Carbon::createFromFormat('d/m/Y', $this->birthday),
'contribution' => $this->contribution, 'contribution' => $this->contribution,
@ -163,13 +163,13 @@ class Individual extends Component
'profile' => $this->profile, 'profile' => $this->profile,
]); ]);
$user->user_category_id = UserCategory::where('key', 'individual')->first()->id;
$user->user_nature_id = UserNature::where('key', 'individual')->first()->id;
$user->user_type_id = UserType::where('key', 'individual')->first()->id;
$associate->associate_category_id = AssociateCategory::where('key', 'individual')->first()->id;
$associate->associate_nature_id = AssociateNature::where('key', 'individual')->first()->id;
$associate->associate_type_id = AssociateType::where('key', 'individual')->first()->id;
$user->save();
$associate->save();
Auth::login($user, true);
Auth::login($associate, true);
redirect(route('home')); redirect(route('home'));
} }


+ 15
- 15
tests/Feature/Auth/LoginTest.php View File

@ -2,7 +2,7 @@
namespace Tests\Feature\Auth; namespace Tests\Feature\Auth;
use App\User;
use App\Associate;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
@ -24,34 +24,34 @@ class LoginTest extends TestCase
/** @test */ /** @test */
public function is_redirected_if_already_logged_in() public function is_redirected_if_already_logged_in()
{ {
$user = factory(User::class)->create();
$associate = factory(Associate::class)->create();
$this->be($user);
$this->be($associate);
$this->get(route('login')) $this->get(route('login'))
->assertRedirect(route('home')); ->assertRedirect(route('home'));
} }
/** @test */ /** @test */
public function a_user_can_login()
public function a_associate_can_login()
{ {
$user = $this->factoryWithoutObservers(User::class)->create(['password' => Hash::make('password')]);
$associate = $this->factoryWithoutObservers(Associate::class)->create(['password' => Hash::make('password')]);
Livewire::test('auth.login') Livewire::test('auth.login')
->set('email', $user->email)
->set('email', $associate->email)
->set('password', 'password') ->set('password', 'password')
->call('authenticate'); ->call('authenticate');
$this->assertAuthenticatedAs($user);
$this->assertAuthenticatedAs($associate);
} }
/** @test */ /** @test */
public function is_redirected_to_the_home_page_after_login() public function is_redirected_to_the_home_page_after_login()
{ {
$user = $this->factoryWithoutObservers(User::class)->create(['password' => Hash::make('password')]);
$associate = $this->factoryWithoutObservers(Associate::class)->create(['password' => Hash::make('password')]);
Livewire::test('auth.login') Livewire::test('auth.login')
->set('email', $user->email)
->set('email', $associate->email)
->set('password', 'password') ->set('password', 'password')
->call('authenticate') ->call('authenticate')
->assertRedirect(route('home')); ->assertRedirect(route('home'));
@ -60,7 +60,7 @@ class LoginTest extends TestCase
/** @test */ /** @test */
public function email_is_required() public function email_is_required()
{ {
$user = factory(User::class)->create(['password' => Hash::make('password')]);
$associate = factory(Associate::class)->create(['password' => Hash::make('password')]);
Livewire::test('auth.login') Livewire::test('auth.login')
->set('password', 'password') ->set('password', 'password')
@ -71,7 +71,7 @@ class LoginTest extends TestCase
/** @test */ /** @test */
public function email_must_be_valid_email() public function email_must_be_valid_email()
{ {
$user = factory(User::class)->create(['password' => Hash::make('password')]);
$associate = factory(Associate::class)->create(['password' => Hash::make('password')]);
Livewire::test('auth.login') Livewire::test('auth.login')
->set('email', 'invalid-email') ->set('email', 'invalid-email')
@ -83,10 +83,10 @@ class LoginTest extends TestCase
/** @test */ /** @test */
public function password_is_required() public function password_is_required()
{ {
$user = factory(User::class)->create(['password' => Hash::make('password')]);
$associate = factory(Associate::class)->create(['password' => Hash::make('password')]);
Livewire::test('auth.login') Livewire::test('auth.login')
->set('email', $user->email)
->set('email', $associate->email)
->call('authenticate') ->call('authenticate')
->assertHasErrors(['password' => 'required']); ->assertHasErrors(['password' => 'required']);
} }
@ -94,10 +94,10 @@ class LoginTest extends TestCase
/** @test */ /** @test */
public function bad_login_attempt_shows_message() public function bad_login_attempt_shows_message()
{ {
$user = factory(User::class)->create();
$associate = factory(Associate::class)->create();
Livewire::test('auth.login') Livewire::test('auth.login')
->set('email', $user->email)
->set('email', $associate->email)
->set('password', 'bad-password') ->set('password', 'bad-password')
->call('authenticate') ->call('authenticate')
->assertHasErrors('email'); ->assertHasErrors('email');


+ 5
- 5
tests/Feature/Auth/LogoutTest.php View File

@ -2,7 +2,7 @@
namespace Tests\Feature\Auth; namespace Tests\Feature\Auth;
use App\User;
use App\Associate;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Tests\TestCase; use Tests\TestCase;
@ -12,10 +12,10 @@ class LogoutTest extends TestCase
use RefreshDatabase; use RefreshDatabase;
/** @test */ /** @test */
public function an_authenticated_user_can_log_out()
public function an_authenticated_associate_can_log_out()
{ {
$user = factory(User::class)->create();
$this->be($user);
$associate = factory(Associate::class)->create();
$this->be($associate);
$this->post(route('logout')) $this->post(route('logout'))
->assertRedirect(route('home')); ->assertRedirect(route('home'));
@ -24,7 +24,7 @@ class LogoutTest extends TestCase
} }
/** @test */ /** @test */
public function an_unauthenticated_user_can_not_log_out()
public function an_unauthenticated_associate_can_not_log_out()
{ {
$this->post(route('logout')) $this->post(route('logout'))
->assertRedirect(route('login')); ->assertRedirect(route('login'));


+ 8
- 8
tests/Feature/Auth/Passwords/EmailTest.php View File

@ -2,7 +2,7 @@
namespace Tests\Feature\Auth\Passwords; namespace Tests\Feature\Auth\Passwords;
use App\User;
use App\Associate;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire; use Livewire\Livewire;
use Tests\TestCase; use Tests\TestCase;
@ -20,7 +20,7 @@ class EmailTest extends TestCase
} }
/** @test */ /** @test */
public function a_user_must_enter_an_email_address()
public function a_associate_must_enter_an_email_address()
{ {
Livewire::test('auth.passwords.email') Livewire::test('auth.passwords.email')
->call('sendResetPasswordLink') ->call('sendResetPasswordLink')
@ -28,7 +28,7 @@ class EmailTest extends TestCase
} }
/** @test */ /** @test */
public function a_user_must_enter_a_valid_email_address()
public function a_associate_must_enter_a_valid_email_address()
{ {
Livewire::test('auth.passwords.email') Livewire::test('auth.passwords.email')
->set('email', 'email') ->set('email', 'email')
@ -37,17 +37,17 @@ class EmailTest extends TestCase
} }
/** @test */ /** @test */
public function a_user_who_enters_a_valid_email_address_will_get_sent_an_email()
public function a_associate_who_enters_a_valid_email_address_will_get_sent_an_email()
{ {
$user = factory(User::class)->create();
$associate = factory(Associate::class)->create();
Livewire::test('auth.passwords.email') Livewire::test('auth.passwords.email')
->set('email', $user->email)
->set('email', $associate->email)
->call('sendResetPasswordLink') ->call('sendResetPasswordLink')
->assertNotSet('emailSentMessage', false); ->assertNotSet('emailSentMessage', false);
$this->assertDatabaseHas('password_resets', [
'email' => $user->email,
$this->assertDatabaseHas('associate_password_resets', [
'email' => $associate->email,
]); ]);
} }
} }

+ 10
- 10
tests/Feature/Auth/Passwords/ResetTest.php View File

@ -2,7 +2,7 @@
namespace Tests\Feature\Auth\Passwords; namespace Tests\Feature\Auth\Passwords;
use App\User;
use App\Associate;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@ -19,18 +19,18 @@ class ResetTest extends TestCase
/** @test */ /** @test */
public function can_view_password_reset_page() public function can_view_password_reset_page()
{ {
$user = factory(User::class)->create();
$associate = factory(Associate::class)->create();
$token = Str::random(16); $token = Str::random(16);
DB::table('password_resets')->insert([
'email' => $user->email,
DB::table('associate_password_resets')->insert([
'email' => $associate->email,
'token' => Hash::make($token), 'token' => Hash::make($token),
'created_at' => Carbon::now(), 'created_at' => Carbon::now(),
]); ]);
$this->get(route('password.reset', [ $this->get(route('password.reset', [
'email' => $user->email,
'email' => $associate->email,
'token' => $token, 'token' => $token,
])) ]))
->assertSuccessful() ->assertSuccessful()
@ -40,12 +40,12 @@ class ResetTest extends TestCase
/** @test */ /** @test */
public function can_reset_password() public function can_reset_password()
{ {
$user = factory(User::class)->create();
$associate = factory(Associate::class)->create();
$token = Str::random(16); $token = Str::random(16);
DB::table('password_resets')->insert([
'email' => $user->email,
DB::table('associate_password_resets')->insert([
'email' => $associate->email,
'token' => Hash::make($token), 'token' => Hash::make($token),
'created_at' => Carbon::now(), 'created_at' => Carbon::now(),
]); ]);
@ -53,13 +53,13 @@ class ResetTest extends TestCase
Livewire::test('auth.passwords.reset', [ Livewire::test('auth.passwords.reset', [
'token' => $token, 'token' => $token,
]) ])
->set('email', $user->email)
->set('email', $associate->email)
->set('password', 'new-password') ->set('password', 'new-password')
->set('passwordConfirmation', 'new-password') ->set('passwordConfirmation', 'new-password')
->call('resetPassword'); ->call('resetPassword');
$this->assertTrue(Auth::attempt([ $this->assertTrue(Auth::attempt([
'email' => $user->email,
'email' => $associate->email,
'password' => 'new-password', 'password' => 'new-password',
])); ]));
} }


+ 39
- 39
tests/Feature/Auth/Register/IndividualTest.php View File

@ -3,7 +3,7 @@
namespace Tests\Feature\Auth\Register; namespace Tests\Feature\Auth\Register;
use App\Providers\RouteServiceProvider; use App\Providers\RouteServiceProvider;
use App\User;
use App\Associate;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@ -27,54 +27,54 @@ class IndividualTest extends TestCase
/** @test */ /** @test */
public function is_redirected_if_already_logged_in() public function is_redirected_if_already_logged_in()
{ {
$user = factory(User::class)->create();
$associate = factory(Associate::class)->create();
$this->be($user);
$this->be($associate);
$this->get(route('register.individual')) $this->get(route('register.individual'))
->assertRedirect(route('home')); ->assertRedirect(route('home'));
} }
/** @test */ /** @test */
function a_user_can_register()
function a_associate_can_register()
{ {
Mail::fake(); Mail::fake();
$user = factory(User::class)->make();
Livewire::test('auth.register.individual')
->set('address.city', $user->address['city'])
->set('address.complement', $user->address['complement'])
->set('address.country', $user->address['country'])
->set('address.neighbourhood', $user->address['neighbourhood'])
->set('address.number', $user->address['number'])
->set('address.postcode', $user->address['postcode'])
->set('address.state', $user->address['state'])
->set('address.street', $user->address['street'])
->set('birthday', $user->birthday->format('d/m/Y'))
->set('contribution', $user->contribution)
->set('discussion', $user->discussion)
->set('document.number', $user->document['number'])
->set('document.type', $user->document['type'])
->set('email', $user->email)
->set('name', $user->name)
->set('profile.bike_activities', $user->profile['bike_activities'])
->set('profile.bike_use', $user->profile['bike_use'])
->set('profile.comments', $user->profile['comments'])
->set('profile.expectation', $user->profile['expectation'])
->set('profile.gender', $user->profile['gender'])
->set('profile.occupation', $user->profile['occupation'])
->set('profile.org_participation', $user->profile['org_participation'])
->set('profile.phone', $user->profile['phone'])
->set('profile.scholarity', $user->profile['scholarity'])
->set('profile.secondary_emails', $user->profile['secondary_emails'])
->set('profile.social', $user->profile['social'])
->set('profile.website', $user->profile['website'])
$associate = factory(Associate::class)->make();
Livewire::test('auth.register.individual')
->set('address.city', $associate->address['city'])
->set('address.complement', $associate->address['complement'])
->set('address.country', $associate->address['country'])
->set('address.neighbourhood', $associate->address['neighbourhood'])
->set('address.number', $associate->address['number'])
->set('address.postcode', $associate->address['postcode'])
->set('address.state', $associate->address['state'])
->set('address.street', $associate->address['street'])
->set('birthday', $associate->birthday->format('d/m/Y'))
->set('contribution', $associate->contribution)
->set('discussion', $associate->discussion)
->set('document.number', $associate->document['number'])
->set('document.type', $associate->document['type'])
->set('email', $associate->email)
->set('name', $associate->name)
->set('profile.bike_activities', $associate->profile['bike_activities'])
->set('profile.bike_use', $associate->profile['bike_use'])
->set('profile.comments', $associate->profile['comments'])
->set('profile.expectation', $associate->profile['expectation'])
->set('profile.gender', $associate->profile['gender'])
->set('profile.occupation', $associate->profile['occupation'])
->set('profile.org_participation', $associate->profile['org_participation'])
->set('profile.phone', $associate->profile['phone'])
->set('profile.scholarity', $associate->profile['scholarity'])
->set('profile.secondary_emails', $associate->profile['secondary_emails'])
->set('profile.social', $associate->profile['social'])
->set('profile.website', $associate->profile['website'])
->call('register') ->call('register')
->assertRedirect(route('home')); ->assertRedirect(route('home'));
$this->assertTrue(User::whereEmail($user->email)->exists());
$this->assertEquals($user->email, Auth::user()->email);
$this->assertTrue(Associate::whereEmail($associate->email)->exists());
$this->assertEquals($associate->email, Auth::user()->email);
} }
/** @test */ /** @test */
@ -242,7 +242,7 @@ class IndividualTest extends TestCase
/** @test */ /** @test */
function email_hasnt_been_taken_already() function email_hasnt_been_taken_already()
{ {
factory(User::class)->create(['email' => 'tallstack@example.com']);
factory(Associate::class)->create(['email' => 'tallstack@example.com']);
Livewire::test('auth.register.individual') Livewire::test('auth.register.individual')
->set('email', 'tallstack@example.com') ->set('email', 'tallstack@example.com')
@ -251,9 +251,9 @@ class IndividualTest extends TestCase
} }
/** @test */ /** @test */
function see_email_hasnt_already_been_taken_validation_message_as_user_types()
function see_email_hasnt_already_been_taken_validation_message_as_associate_types()
{ {
factory(User::class)->create(['email' => 'tallstack@example.com']);
factory(Associate::class)->create(['email' => 'tallstack@example.com']);
Livewire::test('auth.register.individual') Livewire::test('auth.register.individual')
->set('email', 'smallstack@gmail.com') ->set('email', 'smallstack@gmail.com')