80 lines
2.4 KiB
PHP
80 lines
2.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Models\Setting;
|
||
|
|
use App\Models\User;
|
||
|
|
|
||
|
|
describe('SettingsController', function (): void {
|
||
|
|
it('displays the employee sites edit form to an admin', function (): void {
|
||
|
|
/** @var \Tests\TestCase $this */
|
||
|
|
// GIVEN
|
||
|
|
$user = User::factory()->createOne();
|
||
|
|
$route = route('bo.settings.edit');
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$response = $this->actingAs($user, 'backend')->get($route);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
$response->assertOk()
|
||
|
|
->assertViewIs('bo.settings.edit')
|
||
|
|
->assertViewHas('setting');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('updates employee sites with array input and redirects', function (): void {
|
||
|
|
/** @var \Tests\TestCase $this */
|
||
|
|
// GIVEN
|
||
|
|
$user = User::factory()->createOne();
|
||
|
|
$route = route('bo.settings.update');
|
||
|
|
$formData = [
|
||
|
|
'employee_sites' => ['PA', 'LY', 'NA'],
|
||
|
|
];
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$response = $this->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']);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('updates employee sites with comma string input and redirects', function (): void {
|
||
|
|
/** @var \Tests\TestCase $this */
|
||
|
|
// GIVEN
|
||
|
|
$user = User::factory()->createOne();
|
||
|
|
$route = route('bo.settings.update');
|
||
|
|
$formData = [
|
||
|
|
'employee_sites' => 'PA, LY, NA',
|
||
|
|
];
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$response = $this->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']);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('rejects invalid site code formats', function (): void {
|
||
|
|
/** @var \Tests\TestCase $this */
|
||
|
|
// GIVEN
|
||
|
|
$user = User::factory()->createOne();
|
||
|
|
$route = route('bo.settings.update');
|
||
|
|
$formData = [
|
||
|
|
'employee_sites' => ['PA', '123', 'INVALID!'],
|
||
|
|
];
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$response = $this->actingAs($user, 'backend')->put($route, $formData);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
$response->assertSessionHasErrors(['employee_sites.1', 'employee_sites.2']);
|
||
|
|
});
|
||
|
|
});
|