mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-17 02:04:03 +00:00
Finalize Typescript restructure
This commit is contained in:
83
tests/Feature/Customer/AuthTest.php
Normal file
83
tests/Feature/Customer/AuthTest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Customer;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
use function Pest\Laravel\postJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('customer portal guest entrypoints return the spa shell', function () {
|
||||
$customer = Customer::factory()->create();
|
||||
$companySlug = $customer->company->slug;
|
||||
|
||||
$this->followingRedirects()->get("/{$companySlug}/customer")
|
||||
->assertOk()
|
||||
->assertSee('window.InvoiceShelf.start()', false);
|
||||
|
||||
$this->followingRedirects()->get("/{$companySlug}/customer/login")
|
||||
->assertOk()
|
||||
->assertSee('window.InvoiceShelf.start()', false);
|
||||
|
||||
$this->followingRedirects()->get("/{$companySlug}/customer/forgot-password")
|
||||
->assertOk()
|
||||
->assertSee('window.InvoiceShelf.start()', false);
|
||||
|
||||
$this->followingRedirects()->get("/{$companySlug}/customer/reset/password/example-token")
|
||||
->assertOk()
|
||||
->assertSee('window.InvoiceShelf.start()', false);
|
||||
});
|
||||
|
||||
test('customer can login to the customer portal', function () {
|
||||
$customer = Customer::factory()->create([
|
||||
'password' => 'secret123',
|
||||
'enable_portal' => true,
|
||||
]);
|
||||
|
||||
$response = postJson("/{$customer->company->slug}/customer/login", [
|
||||
'email' => $customer->email,
|
||||
'password' => 'secret123',
|
||||
'device_name' => 'customer-portal-web',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$this->assertAuthenticatedAs($customer, 'customer');
|
||||
});
|
||||
|
||||
test('customer portal login rejects invalid credentials', function () {
|
||||
$customer = Customer::factory()->create([
|
||||
'password' => 'secret123',
|
||||
'enable_portal' => true,
|
||||
]);
|
||||
|
||||
postJson("/{$customer->company->slug}/customer/login", [
|
||||
'email' => $customer->email,
|
||||
'password' => 'wrong-password',
|
||||
'device_name' => 'customer-portal-web',
|
||||
])
|
||||
->assertStatus(422)
|
||||
->assertJsonValidationErrors(['email']);
|
||||
});
|
||||
|
||||
test('customer portal login rejects portal-disabled customers', function () {
|
||||
$customer = Customer::factory()->create([
|
||||
'password' => 'secret123',
|
||||
'enable_portal' => false,
|
||||
]);
|
||||
|
||||
postJson("/{$customer->company->slug}/customer/login", [
|
||||
'email' => $customer->email,
|
||||
'password' => 'secret123',
|
||||
'device_name' => 'customer-portal-web',
|
||||
])
|
||||
->assertStatus(422)
|
||||
->assertJsonValidationErrors(['email']);
|
||||
});
|
||||
Reference in New Issue
Block a user