nextStripeNumber())->toBe('STR-00001'); expect($generator->nextStripeNumber())->toBe('STR-00002'); expect($generator->nextManualNumber())->toBe('MAN-00001'); expect($generator->nextStripeNumber())->toBe('STR-00003'); expect($generator->nextManualNumber())->toBe('MAN-00002'); }); test('an unknown circle is rejected', function () { expect(fn () => app(InvoiceNumberGenerator::class)->next('XXX')) ->toThrow(InvalidArgumentException::class); }); test('an existing sequence row is not reset by the race-safe ensure-insert', function () { DB::table('invoice_number_sequences')->insert([ 'circle' => InvoiceNumberGenerator::CIRCLE_MANUAL, 'next_number' => 5, 'created_at' => now(), 'updated_at' => now(), ]); expect(app(InvoiceNumberGenerator::class)->nextManualNumber())->toBe('MAN-00005'); expect(DB::table('invoice_number_sequences')->where('circle', 'MAN')->count())->toBe(1); });