import { isAllowedStatusTransition, isValidDocumentCode, isValidImageUrl, isValidLatitude, PACKING_SLIP_USER_TRANSITIONS, SALES_INVOICE_USER_TRANSITIONS, SALES_ORDER_SYSTEM_TRANSITIONS, SALES_ORDER_USER_TRANSITIONS, SALES_PAYMENT_USER_TRANSITIONS, } from './sales-fields'; describe('sales fields', () => { it('accepts generated and user document codes', () => { expect(isValidDocumentCode('SR-20260824-0001')).toBe(true); expect(isValidDocumentCode('REQ_01')).toBe(true); expect(isValidDocumentCode('')).toBe(false); expect(isValidDocumentCode('SR 1')).toBe(false); }); it('accepts http(s) image URLs only', () => { expect(isValidImageUrl('https://cdn.example.com/a.png')).toBe(true); expect(isValidImageUrl('ftp://x/a.png')).toBe(false); expect(isValidImageUrl('not-a-url')).toBe(false); }); it('validates latitude', () => { expect(isValidLatitude(-6.2)).toBe(true); expect(isValidLatitude(100)).toBe(false); }); it('allows sales-order user transitions draft to processed or cancelled', () => { expect( isAllowedStatusTransition( 'draft', 'processed', SALES_ORDER_USER_TRANSITIONS, ), ).toBe(true); expect( isAllowedStatusTransition( 'draft', 'cancelled', SALES_ORDER_USER_TRANSITIONS, ), ).toBe(true); expect( isAllowedStatusTransition( 'processed', 'completed', SALES_ORDER_USER_TRANSITIONS, ), ).toBe(false); expect( isAllowedStatusTransition( 'processed', 'completed', SALES_ORDER_SYSTEM_TRANSITIONS, ), ).toBe(true); }); it('allows packing processed to completed or cancelled', () => { expect( isAllowedStatusTransition( 'processed', 'completed', PACKING_SLIP_USER_TRANSITIONS, ), ).toBe(true); expect( isAllowedStatusTransition( 'draft', 'completed', PACKING_SLIP_USER_TRANSITIONS, ), ).toBe(false); }); it('allows invoice user transitions from draft to processed or cancelled', () => { expect( isAllowedStatusTransition( 'draft', 'processed', SALES_INVOICE_USER_TRANSITIONS, ), ).toBe(true); expect( isAllowedStatusTransition( 'draft', 'cancelled', SALES_INVOICE_USER_TRANSITIONS, ), ).toBe(true); expect( isAllowedStatusTransition( 'processed', 'completed', SALES_INVOICE_USER_TRANSITIONS, ), ).toBe(false); }); it('allows payment pending to approved, rejected, or draft', () => { expect( isAllowedStatusTransition( 'draft', 'pending', SALES_PAYMENT_USER_TRANSITIONS, ), ).toBe(true); expect( isAllowedStatusTransition( 'pending', 'approved', SALES_PAYMENT_USER_TRANSITIONS, ), ).toBe(true); expect( isAllowedStatusTransition( 'draft', 'approved', SALES_PAYMENT_USER_TRANSITIONS, ), ).toBe(false); }); });