52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
|
|
it('shows the signup page to guests', function () {
|
|
$this->get(route('register'))->assertOk()->assertSee(__('auth.register_title'));
|
|
});
|
|
|
|
it('links between login and signup', function () {
|
|
$this->get(route('login'))->assertOk()->assertSee(route('register'));
|
|
$this->get(route('register'))->assertOk()->assertSee(route('login'));
|
|
});
|
|
|
|
it('registers a new account and signs in', function () {
|
|
$this->post(route('register.store'), [
|
|
'name' => 'New Co',
|
|
'email' => 'new@signup.test',
|
|
'password' => 'password1234',
|
|
'password_confirmation' => 'password1234',
|
|
])->assertRedirect();
|
|
|
|
$user = User::query()->where('email', 'new@signup.test')->first();
|
|
expect($user)->not->toBeNull()->and($user->isOperator())->toBeFalse();
|
|
$this->assertAuthenticatedAs($user);
|
|
|
|
// A linked customer is created so the portal has something to work with.
|
|
$customer = \App\Models\Customer::query()->where('user_id', $user->id)->first();
|
|
expect($customer)->not->toBeNull()->and($customer->email)->toBe('new@signup.test');
|
|
});
|
|
|
|
it('refuses to register with an existing customer email (account-claim guard)', function () {
|
|
\App\Models\Customer::factory()->create(['email' => 'claim@signup.test']);
|
|
|
|
$this->post(route('register.store'), [
|
|
'name' => 'Claimer', 'email' => 'claim@signup.test',
|
|
'password' => 'password1234', 'password_confirmation' => 'password1234',
|
|
])->assertSessionHasErrors('email');
|
|
|
|
expect(User::query()->where('email', 'claim@signup.test')->exists())->toBeFalse();
|
|
});
|
|
|
|
it('rejects a mismatched password confirmation', function () {
|
|
$this->post(route('register.store'), [
|
|
'name' => 'X',
|
|
'email' => 'x@signup.test',
|
|
'password' => 'password1234',
|
|
'password_confirmation' => 'different',
|
|
])->assertSessionHasErrors('password');
|
|
|
|
expect(User::query()->where('email', 'x@signup.test')->exists())->toBeFalse();
|
|
});
|