ldc-boutique-cnc-sable/tests/Feature/Bo/Settings/SettingsControllerTest.php
Jérémy Munsch 3b3997d547
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees)
- Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue)
- Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts
- Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs
- Remove legacy and dead CSV employee import/export code
- Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation
- Add comprehensive Pest unit, integration, and feature test coverage
2026-10-27 09:58:44 +01:00

79 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']);
});
});