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