Files
hr/tests/Feature/Models/ShiftTest.php

45 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\Shift;
it('generates an uppercase slug code from name', function (): void {
expect(Shift::generateUniqueCodeFromName('Morning Shift'))
->toBe('MORNING-SHIFT');
});
it('generates code on save when code is blank', function (): void {
$shift = Shift::factory()->create([
'name' => 'Morning Shift',
'code' => '',
]);
expect($shift->code)->toBe('MORNING-SHIFT');
});
it('does not overwrite an existing code on update', function (): void {
$shift = Shift::factory()->create([
'name' => 'Morning Shift',
'code' => 'MS',
]);
$shift->update(['name' => 'Early Shift']);
expect($shift->fresh()->code)->toBe('MS');
});
it('appends a suffix when the generated code already exists', function (): void {
Shift::factory()->create([
'name' => 'Morning Team',
'code' => 'MORNING',
]);
$shift = Shift::factory()->create([
'name' => 'Morning',
'code' => '',
]);
expect($shift->code)->toBe('MORNING-1');
});