diff --git a/app/Http/Livewire/Auth/Register/Individual.php b/app/Http/Livewire/Auth/Register/Individual.php index c8ab175..f061faf 100644 --- a/app/Http/Livewire/Auth/Register/Individual.php +++ b/app/Http/Livewire/Auth/Register/Individual.php @@ -3,10 +3,10 @@ namespace App\Http\Livewire\Auth\Register; 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 Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Http; @@ -81,7 +81,7 @@ class Individual extends Component 'discussion' => ['string', 'in:all,daily,occasional'], 'document.number' => ['string'], 'document.type' => ['string', 'in:cpf,identity,passport'], - 'email' => ['email', 'unique:users'], + 'email' => ['email', 'unique:associates'], 'profile.bike_activities' => ['string'], 'profile.bike_use' => ['string'], 'profile.comments' => ['string'], @@ -114,7 +114,7 @@ class Individual extends Component $this->dispatchBrowserEvent('address-autofilled'); } } 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'], 'document.number' => ['required', 'string'], 'document.type' => ['required', 'string', 'in:cpf,identity,passport'], - 'email' => ['required', 'email', 'unique:users'], + 'email' => ['required', 'email', 'unique:associates'], 'name' => ['required'], 'profile.bike_activities' => ['nullable', 'string'], 'profile.bike_use' => ['nullable', 'string'], @@ -152,7 +152,7 @@ class Individual extends Component 'profile.website' => ['nullable', 'string'], ]); - $user = new User([ + $associate = new Associate([ 'address' => $this->address, 'birthday' => Carbon::createFromFormat('d/m/Y', $this->birthday), 'contribution' => $this->contribution, @@ -163,13 +163,13 @@ class Individual extends Component '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')); } diff --git a/tests/Feature/Auth/LoginTest.php b/tests/Feature/Auth/LoginTest.php index b1b06ef..2ca3313 100644 --- a/tests/Feature/Auth/LoginTest.php +++ b/tests/Feature/Auth/LoginTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Auth; -use App\User; +use App\Associate; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; @@ -24,34 +24,34 @@ class LoginTest extends TestCase /** @test */ 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')) ->assertRedirect(route('home')); } /** @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') - ->set('email', $user->email) + ->set('email', $associate->email) ->set('password', 'password') ->call('authenticate'); - $this->assertAuthenticatedAs($user); + $this->assertAuthenticatedAs($associate); } /** @test */ 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') - ->set('email', $user->email) + ->set('email', $associate->email) ->set('password', 'password') ->call('authenticate') ->assertRedirect(route('home')); @@ -60,7 +60,7 @@ class LoginTest extends TestCase /** @test */ 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') ->set('password', 'password') @@ -71,7 +71,7 @@ class LoginTest extends TestCase /** @test */ 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') ->set('email', 'invalid-email') @@ -83,10 +83,10 @@ class LoginTest extends TestCase /** @test */ 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') - ->set('email', $user->email) + ->set('email', $associate->email) ->call('authenticate') ->assertHasErrors(['password' => 'required']); } @@ -94,10 +94,10 @@ class LoginTest extends TestCase /** @test */ public function bad_login_attempt_shows_message() { - $user = factory(User::class)->create(); + $associate = factory(Associate::class)->create(); Livewire::test('auth.login') - ->set('email', $user->email) + ->set('email', $associate->email) ->set('password', 'bad-password') ->call('authenticate') ->assertHasErrors('email'); diff --git a/tests/Feature/Auth/LogoutTest.php b/tests/Feature/Auth/LogoutTest.php index 2c4d211..8fa5d71 100644 --- a/tests/Feature/Auth/LogoutTest.php +++ b/tests/Feature/Auth/LogoutTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Auth; -use App\User; +use App\Associate; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Auth; use Tests\TestCase; @@ -12,10 +12,10 @@ class LogoutTest extends TestCase use RefreshDatabase; /** @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')) ->assertRedirect(route('home')); @@ -24,7 +24,7 @@ class LogoutTest extends TestCase } /** @test */ - public function an_unauthenticated_user_can_not_log_out() + public function an_unauthenticated_associate_can_not_log_out() { $this->post(route('logout')) ->assertRedirect(route('login')); diff --git a/tests/Feature/Auth/Passwords/EmailTest.php b/tests/Feature/Auth/Passwords/EmailTest.php index 055f753..da3c58a 100644 --- a/tests/Feature/Auth/Passwords/EmailTest.php +++ b/tests/Feature/Auth/Passwords/EmailTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Auth\Passwords; -use App\User; +use App\Associate; use Illuminate\Foundation\Testing\RefreshDatabase; use Livewire\Livewire; use Tests\TestCase; @@ -20,7 +20,7 @@ class EmailTest extends TestCase } /** @test */ - public function a_user_must_enter_an_email_address() + public function a_associate_must_enter_an_email_address() { Livewire::test('auth.passwords.email') ->call('sendResetPasswordLink') @@ -28,7 +28,7 @@ class EmailTest extends TestCase } /** @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') ->set('email', 'email') @@ -37,17 +37,17 @@ class EmailTest extends TestCase } /** @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') - ->set('email', $user->email) + ->set('email', $associate->email) ->call('sendResetPasswordLink') ->assertNotSet('emailSentMessage', false); - $this->assertDatabaseHas('password_resets', [ - 'email' => $user->email, + $this->assertDatabaseHas('associate_password_resets', [ + 'email' => $associate->email, ]); } } diff --git a/tests/Feature/Auth/Passwords/ResetTest.php b/tests/Feature/Auth/Passwords/ResetTest.php index bf088ce..0fe7f2e 100644 --- a/tests/Feature/Auth/Passwords/ResetTest.php +++ b/tests/Feature/Auth/Passwords/ResetTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature\Auth\Passwords; -use App\User; +use App\Associate; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Auth; @@ -19,18 +19,18 @@ class ResetTest extends TestCase /** @test */ public function can_view_password_reset_page() { - $user = factory(User::class)->create(); + $associate = factory(Associate::class)->create(); $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), 'created_at' => Carbon::now(), ]); $this->get(route('password.reset', [ - 'email' => $user->email, + 'email' => $associate->email, 'token' => $token, ])) ->assertSuccessful() @@ -40,12 +40,12 @@ class ResetTest extends TestCase /** @test */ public function can_reset_password() { - $user = factory(User::class)->create(); + $associate = factory(Associate::class)->create(); $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), 'created_at' => Carbon::now(), ]); @@ -53,13 +53,13 @@ class ResetTest extends TestCase Livewire::test('auth.passwords.reset', [ 'token' => $token, ]) - ->set('email', $user->email) + ->set('email', $associate->email) ->set('password', 'new-password') ->set('passwordConfirmation', 'new-password') ->call('resetPassword'); $this->assertTrue(Auth::attempt([ - 'email' => $user->email, + 'email' => $associate->email, 'password' => 'new-password', ])); } diff --git a/tests/Feature/Auth/Register/IndividualTest.php b/tests/Feature/Auth/Register/IndividualTest.php index 6978758..b0509ab 100644 --- a/tests/Feature/Auth/Register/IndividualTest.php +++ b/tests/Feature/Auth/Register/IndividualTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\Auth\Register; use App\Providers\RouteServiceProvider; -use App\User; +use App\Associate; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Auth; @@ -27,54 +27,54 @@ class IndividualTest extends TestCase /** @test */ 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')) ->assertRedirect(route('home')); } /** @test */ - function a_user_can_register() + function a_associate_can_register() { 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') ->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 */ @@ -242,7 +242,7 @@ class IndividualTest extends TestCase /** @test */ 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') ->set('email', 'tallstack@example.com') @@ -251,9 +251,9 @@ class IndividualTest extends TestCase } /** @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') ->set('email', 'smallstack@gmail.com')