Refactor employee management by implementing automatic employee number generation, updating national ID handling, and enhancing localization for gender and nationality fields across various resources. Adjust form components and validation logic to improve user experience and data integrity.

This commit is contained in:
Mekan1206
2026-08-02 21:06:37 +05:00
parent 28cbef8eb5
commit eed46157cd
25 changed files with 1175 additions and 51 deletions

View File

@@ -22,13 +22,13 @@ beforeEach(function (): void {
it('skips duplicate employees during import', function (): void {
Employee::factory()->create([
'employee_number' => 'EMP-90001',
'national_id' => '1234567890',
'national_id' => 'TM',
]);
$rows = [[
'employee_number' => 'EMP-90001',
'full_name' => 'Duplicate Employee',
'national_id' => '1234567890',
'national_id' => 'TM',
'department' => 'Engineering',
'position' => 'Developer',
'shift' => 'Day Shift',
@@ -68,6 +68,29 @@ it('imports valid employee rows', function (): void {
]);
});
it('imports valid employee rows without an employee number', function (): void {
$rows = [[
'full_name' => 'Auto Number Employee',
'gender' => 'male',
'birth_date' => '1992-02-20',
'department' => 'Engineering',
'position' => 'Developer',
'shift' => 'Day Shift',
'hire_date' => '2024-04-01',
]];
$result = $this->importService->import(ImportType::Employees, $rows);
expect($result->imported)->toBe(1)
->and($result->skipped)->toBe(0)
->and($result->failed)->toBe(0);
$employee = Employee::query()->where('full_name', 'Auto Number Employee')->first();
expect($employee)->not->toBeNull()
->and($employee->employee_number)->toBe('EMP-00001');
});
it('reports validation errors for invalid employee rows', function (): void {
$rows = [[
'employee_number' => '',
@@ -93,8 +116,7 @@ it('validates required fields and unknown references', function (): void {
$errors = $this->transformer->validate($dto);
expect($errors)->toContain('Employee number is required.')
->and($errors)->toContain('Full name is required.')
expect($errors)->toContain('Full name is required.')
->and($errors)->toContain('Department "Missing Department" was not found.')
->and($errors)->toContain('Position "Missing Position" was not found.')
->and($errors)->toContain('Shift "Missing Shift" was not found.');
@@ -103,7 +125,7 @@ it('validates required fields and unknown references', function (): void {
it('detects duplicates by employee number or national id', function (): void {
Employee::factory()->create([
'employee_number' => 'EMP-80001',
'national_id' => '9988776655',
'national_id' => 'TM',
]);
$duplicateByNumber = EmployeeRowDto::fromMappedRow([
@@ -114,7 +136,7 @@ it('detects duplicates by employee number or national id', function (): void {
$duplicateByNationalId = EmployeeRowDto::fromMappedRow([
'employee_number' => 'EMP-80002',
'full_name' => 'Another Person',
'national_id' => '9988776655',
'national_id' => 'TM',
]);
expect($this->transformer->isDuplicate($duplicateByNumber))->toBeTrue()