import { isQuoteDropoff, isQuoteDDP, metersToMiles, getQuotesValidCollectionDates, } from '../features/order-ship/utils/quoteHelpers'; import type { Quote } from '../types'; function makeQuote( tags: string[] = [], dates: any[] = [] ): Quote { return { tags, dates, price: { net: 1000, gross: 1200 }, availableExtras: [], service: { includedProtection: 0 }, } as unknown as Quote; } // ------------------------------------------------------------------------- describe( 'isQuoteDropoff', () => { // Positive it( 'returns true when tag is "dropoff"', () => { expect( isQuoteDropoff( makeQuote( [ 'dropoff' ] ) ) ).toBe( true ); } ); it( 'returns true when tag is "locker"', () => { expect( isQuoteDropoff( makeQuote( [ 'locker' ] ) ) ).toBe( true ); } ); it( 'returns true when multiple tags include "dropoff"', () => { expect( isQuoteDropoff( makeQuote( [ 'standard', 'dropoff' ] ) ) ).toBe( true ); } ); // Negative it( 'returns false when no matching tag', () => { expect( isQuoteDropoff( makeQuote( [ 'standard', 'express' ] ) ) ).toBe( false ); } ); it( 'returns false for empty tags array', () => { expect( isQuoteDropoff( makeQuote( [] ) ) ).toBe( false ); } ); it( 'returns false when tags is null', () => { expect( isQuoteDropoff( { tags: null } as any ) ).toBe( false ); } ); it( 'returns false when tags is undefined', () => { expect( isQuoteDropoff( {} as any ) ).toBe( false ); } ); } ); // ------------------------------------------------------------------------- describe( 'isQuoteDDP', () => { // Positive it( 'returns true when tag is "ddp"', () => { expect( isQuoteDDP( makeQuote( [ 'ddp' ] ) ) ).toBe( true ); } ); it( 'returns true when multiple tags include "ddp"', () => { expect( isQuoteDDP( makeQuote( [ 'express', 'ddp' ] ) ) ).toBe( true ); } ); // Negative it( 'returns false when no "ddp" tag', () => { expect( isQuoteDDP( makeQuote( [ 'standard' ] ) ) ).toBe( false ); } ); it( 'returns false for empty tags', () => { expect( isQuoteDDP( makeQuote() ) ).toBe( false ); } ); it( 'returns false when tags is null', () => { expect( isQuoteDDP( { tags: null } as any ) ).toBe( false ); } ); } ); // ------------------------------------------------------------------------- describe( 'metersToMiles', () => { // Positive it( 'converts exactly 1609.344m to 1 mile', () => { expect( metersToMiles( 1609.344 ) ).toBe( '1 miles' ); } ); it( 'formats distances >= 1 mile as integer', () => { expect( metersToMiles( 16093.44 ) ).toBe( '10 miles' ); } ); it( 'formats sub-mile distances with one decimal', () => { // 800m ≈ 0.497 miles → rounds to 0.5 const result = metersToMiles( 800 ); expect( result ).toMatch( /^\d+(\.\d)? miles$/ ); } ); // Negative it( 'handles zero meters without throwing', () => { expect( () => metersToMiles( 0 ) ).not.toThrow(); } ); it( 'still includes "miles" unit for very large distances', () => { expect( metersToMiles( 1_000_000 ) ).toContain( 'miles' ); } ); } ); // ------------------------------------------------------------------------- describe( 'getQuotesValidCollectionDates', () => { const past = new Date( Date.now() - 86_400_000 ).toISOString(); const future = new Date( Date.now() + 86_400_000 ).toISOString(); // Positive it( 'returns all dates when none have a cutoff', () => { const quote = makeQuote( [], [ { id: '1' }, { id: '2' } ] ); expect( getQuotesValidCollectionDates( quote ) ).toHaveLength( 2 ); } ); it( 'returns dates with future cutoff', () => { const quote = makeQuote( [], [ { id: '1', cutoff: future } ] ); expect( getQuotesValidCollectionDates( quote ) ).toHaveLength( 1 ); } ); // Negative it( 'filters out dates with a past cutoff', () => { const quote = makeQuote( [], [ { id: '1', cutoff: past } ] ); expect( getQuotesValidCollectionDates( quote ) ).toHaveLength( 0 ); } ); it( 'returns only future dates when mixed', () => { const quote = makeQuote( [], [ { cutoff: past }, { cutoff: future }, ] ); const result = getQuotesValidCollectionDates( quote ); expect( result ).toHaveLength( 1 ); expect( result[ 0 ].cutoff ).toBe( future ); } ); it( 'returns empty array when all dates have past cutoffs', () => { const quote = makeQuote( [], [ { id: '1', cutoff: past }, { id: '2', cutoff: past }, ] ); expect( getQuotesValidCollectionDates( quote ) ).toHaveLength( 0 ); } ); } );