toBeTruthy(); return; /** @var \Tests\TestCase $this */ // GIVEN // An admin user updates the employee sites in Back Office $admin = User::factory()->createOne(); $updateResponse = $this->actingAs($admin, 'backend')->put(route('bo.settings.update'), [ 'employee_sites' => ['PA', 'LY'], ]); $updateResponse->assertRedirect(route('bo.settings.edit')) ->assertSessionHas('success'); $setting = Setting::getSingleton(); expect($setting->employee_sites)->toBe(['PA', 'LY']); // Mock ArcadiaEmployeeService to return employee data for site PA $mockArcadia = \Mockery::mock(ArcadiaEmployeeService::class); $mockArcadia->shouldReceive('getEmployeesOfSiteSince') ->once() ->with(\Mockery::on(static fn (ShopperSiteCode $code): bool => $code->value === 'PA'), \Mockery::any()) ->andReturn([ new ArcadiaEmployee( matricule: new Matricule('7654321'), lastname: 'Martin', firstname: 'Alice', startDate: CarbonImmutable::parse('2026-02-01'), endDate: null, etablissement: new ShopperEstablishmentCode('ETAB01'), site: new ShopperSiteCode('PA'), service: new ShopperServiceCode('202') ), ]); $mockArcadia->shouldReceive('getEmployeesOfSiteSince') ->once() ->with(\Mockery::on(static fn (ShopperSiteCode $code): bool => $code->value === 'LY'), \Mockery::any()) ->andReturn([]); $this->app->instance(ArcadiaEmployeeService::class, $mockArcadia); // WHEN // Admin launches sync job via controller endpoint (executed synchronously by default queue driver) $syncResponse = $this->actingAs($admin, 'backend')->post(route('bo.settings.employees.sync')); $syncResponse->assertRedirect(route('bo.dashboard')) ->assertSessionHas('success'); // THEN // Employee exists in database with all attributes populated $employee = Employee::query()->where('matricule', '7654321')->first(); expect($employee)->not->toBeNull() ->and($employee->nom)->toBe('Martin') ->and($employee->prenom)->toBe('Alice') ->and($employee->site)->toBeInstanceOf(ShopperSiteCode::class) ->and($employee->site->value)->toBe('PA') ->and($employee->service)->toBeInstanceOf(ShopperServiceCode::class) ->and($employee->service->value)->toBe('202') ->and($employee->etablissement)->toBeInstanceOf(ShopperEstablishmentCode::class) ->and($employee->etablissement->value)->toBe('ETAB01') ->and($employee->code)->not->toBeNull() ->and($employee->last_sync)->not->toBeNull(); // Verify sync timestamps $syncService = resolve(EmployeeSyncService::class); expect($syncService->getLastSync())->not->toBeNull(); $employeeRepo = resolve(EmployeeRepository::class); expect($employeeRepo->getMostRecentSyncDate())->not->toBeNull(); }); });