CluPilotCloud/tests/Feature/OperatorInPortalTest.php

64 lines
2.1 KiB
PHP

<?php
use App\Livewire\Billing;
use App\Livewire\ConfirmCancelPackage;
use App\Livewire\ConfirmCloseAccount;
use App\Livewire\Settings;
use App\Livewire\Users;
use App\Models\Order;
use App\Models\User;
use Livewire\Livewire;
/**
* An operator account has no Customer. Portal actions must SAY so rather than
* silently doing nothing (which reads as a dead button).
*/
function operatorUser(): User
{
return User::factory()->operator('Owner')->create();
}
it('warns instead of silently ignoring a purchase without a customer', function () {
Livewire::actingAs(operatorUser())->test(Billing::class)
->call('purchase', 'storage')
->assertDispatched('notify');
expect(Order::query()->count())->toBe(0);
});
it('warns instead of silently ignoring a profile save without a customer', function () {
Livewire::actingAs(operatorUser())->test(Settings::class)
->set('companyName', 'Nope GmbH')
->call('saveProfile')
->assertDispatched('notify');
});
it('warns instead of silently ignoring a seat invite without a customer', function () {
Livewire::actingAs(operatorUser())->test(Users::class)
->set('inviteEmail', 'x@no-customer.test')
->call('invite')
->assertDispatched('notify');
expect(\App\Models\Seat::query()->count())->toBe(0);
});
it('shows an error in the cancel-package modal without a customer', function () {
Livewire::actingAs(operatorUser())->test(ConfirmCancelPackage::class)
->set('confirmName', 'whatever')
->call('cancelPackage')
->assertHasErrors(['confirmName']);
});
it('shows an error in the close-account modal without a customer', function () {
Livewire::actingAs(operatorUser())->test(ConfirmCloseAccount::class)
->set('confirmWord', __('settings.close_keyword'))
->call('closeAccount')
->assertHasErrors(['confirmWord']);
});
it('renders the portal notice for an operator account', function () {
$this->actingAs(operatorUser())->get(route('dashboard'))
->assertOk()
->assertSee(__('dashboard.no_customer_title'));
});