106 lines
3.3 KiB
PHP
106 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\App\Http\Controllers\Bo;
|
|
|
|
use App\Models\Setting;
|
|
use App\Models\User;
|
|
|
|
use function Pest\Laravel\actingAs;
|
|
|
|
describe('SettingsController', function (): void {
|
|
it('forbids accessing the employee sites edit form while SettingPolicy is disabled', function (): void {
|
|
// GIVEN
|
|
$user = User::factory()->createOne();
|
|
$route = route('bo.settings.edit');
|
|
|
|
// WHEN
|
|
$response = actingAs($user, 'backend')->get($route);
|
|
|
|
// THEN
|
|
$response->assertForbidden();
|
|
});
|
|
|
|
it('forbids updating employee sites while SettingPolicy is disabled', function (): void {
|
|
// GIVEN
|
|
$user = User::factory()->createOne();
|
|
$route = route('bo.settings.update');
|
|
$formData = [
|
|
'employee_sites' => ['PA', 'LY', 'NA'],
|
|
];
|
|
|
|
// WHEN
|
|
$response = actingAs($user, 'backend')->put($route, $formData);
|
|
|
|
// THEN
|
|
$response->assertForbidden();
|
|
});
|
|
|
|
it('displays the employee sites edit form to an admin', function (): void {
|
|
// GIVEN
|
|
$user = User::factory()->createOne();
|
|
$route = route('bo.settings.edit');
|
|
|
|
// WHEN
|
|
$response = actingAs($user, 'backend')->get($route);
|
|
|
|
// THEN
|
|
$response->assertOk()
|
|
->assertViewIs('bo.settings.edit')
|
|
->assertViewHas('setting');
|
|
})->skip('Arcadia API is offline; SettingPolicy and EmployeePolicy currently return false.');
|
|
|
|
it('updates employee sites with array input and redirects', function (): void {
|
|
// GIVEN
|
|
$user = User::factory()->createOne();
|
|
$route = route('bo.settings.update');
|
|
$formData = [
|
|
'employee_sites' => ['PA', 'LY', 'NA'],
|
|
];
|
|
|
|
// WHEN
|
|
$response = actingAs($user, 'backend')->put($route, $formData);
|
|
|
|
// THEN
|
|
$response->assertRedirect(route('bo.settings.edit'))
|
|
->assertSessionHas('success');
|
|
|
|
$setting = Setting::getSingleton();
|
|
expect($setting->employee_sites)->toBe(['PA', 'LY', 'NA']);
|
|
})->skip('Arcadia API is offline; SettingPolicy and EmployeePolicy currently return false.');
|
|
|
|
it('updates employee sites with comma string input and redirects', function (): void {
|
|
// GIVEN
|
|
$user = User::factory()->createOne();
|
|
$route = route('bo.settings.update');
|
|
$formData = [
|
|
'employee_sites' => 'PA, LY, NA',
|
|
];
|
|
|
|
// WHEN
|
|
$response = actingAs($user, 'backend')->put($route, $formData);
|
|
|
|
// THEN
|
|
$response->assertRedirect(route('bo.settings.edit'))
|
|
->assertSessionHas('success');
|
|
|
|
$setting = Setting::getSingleton();
|
|
expect($setting->employee_sites)->toBe(['PA', 'LY', 'NA']);
|
|
})->skip('Arcadia API is offline; SettingPolicy and EmployeePolicy currently return false.');
|
|
|
|
it('rejects invalid site code formats', function (): void {
|
|
// GIVEN
|
|
$user = User::factory()->createOne();
|
|
$route = route('bo.settings.update');
|
|
$formData = [
|
|
'employee_sites' => ['PA', '123', 'INVALID!'],
|
|
];
|
|
|
|
// WHEN
|
|
$response = actingAs($user, 'backend')->put($route, $formData);
|
|
|
|
// THEN
|
|
$response->assertSessionHasErrors(['employee_sites.1', 'employee_sites.2']);
|
|
});
|
|
});
|