/** * Must match tests/CustomerServiceNameTest.php: the settings screen shows the name the checkout uses. */ import { customerServiceName, pickupKind, pickupTags, } from '../features/settings/utils/customerServiceName'; const service = (courier: string, rawName: string) => ({ courier, name: rawName.replace(courier, '').trim(), }); const cases: [string, string, string][] = [ ['Royal Mail', 'Royal Mail 48 Tracked Small Collection', 'Royal Mail 48 Tracked'], ['Royal Mail', 'Royal Mail 24 Tracked Small', 'Royal Mail 24 Tracked'], ['Parcelforce', 'Parcelforce Worldwide Express 48 Drop Off', 'Parcelforce Express 48'], ['Parcelforce', 'Parcelforce Worldwide by 10am', 'Parcelforce by 10am'], ['Parcelforce', 'Parcelforce Worldwide - Euro Economy Drop Shop', 'Parcelforce Euro Economy'], ['Evri Collection', 'Evri Collection', 'Evri Standard'], ['Evri Drop-off', 'Evri ParcelShop', 'Evri Standard'], ['Evri Drop-off', 'Evri ParcelShop Next Day', 'Evri Next Day'], ['InPost', 'InPost Lockers to Home', 'InPost Standard'], ['InPost', 'InPost Shop to Home', 'InPost Standard'], ['DHL eCommerce UK', 'DHL eCommerce UK - Drop Off', 'DHL Standard'], ['DHL', 'DHL eCommerce UK Collection', 'DHL Standard'], ['FedEx Express', 'FedEx Priority Drop Off', 'FedEx Express'], ['FedEx Express', 'FedEx Economy Collection', 'FedEx Economy'], ['FedEx Express', 'FedEx International Priority®', 'FedEx Express'], ['UPS', 'UPS Standard®', 'UPS Standard'], ['UPS', 'UPS Express Saver® by 12pm', 'UPS Express Saver by 12pm'], ['UPS Access Point', 'UPS Standard™ – drop off', 'UPS Standard'], ['DX', 'DX48', 'DX 48'], ]; describe('customerServiceName', () => { it.each(cases)('%s / %s → %s', (courier, rawName, expected) => { expect(customerServiceName(service(courier, rawName))).toBe(expected); }); // Positive — pickup point delivery says how the customer collects it('says when the customer collects from a shop', () => { expect( customerServiceName(service('Evri Drop-off', 'Evri ParcelShop to ParcelShop'), ['shopdelivery']) ).toBe('Evri Shop Pick-up'); }); it('says when the customer collects from a locker', () => { expect( customerServiceName(service('InPost', 'InPost Locker to Locker'), ['shopdelivery', 'locker']) ).toBe('InPost Locker Pick-up'); }); // Negative — a locker tag alone (lockers to home) is home delivery it('treats a locker tag alone as home delivery', () => { expect( customerServiceName(service('InPost', 'InPost Lockers to Home'), ['locker', 'dropoff']) ).toBe('InPost Standard'); }); // The settings screen saves the pickup kind and rebuilds the tags from it it('suggests the checkout name from a saved pickup kind', () => { const locker = service('InPost', 'InPost Locker to Locker'); expect(customerServiceName(locker, pickupTags(pickupKind(['shopdelivery', 'locker'])))).toBe( 'InPost Locker Pick-up' ); expect(pickupKind(['shopdelivery'])).toBe('shop'); expect(pickupKind(['locker', 'dropoff'])).toBe(''); expect(pickupKind()).toBe(''); expect(pickupTags('')).toEqual([]); expect(pickupTags(undefined)).toEqual([]); }); it('keeps an unknown courier name', () => { expect(customerServiceName({ courier: 'Acme Couriers', name: 'Next Day' })).toBe('Acme Couriers Next Day'); }); it('uses the slug when there is no courier or name', () => { expect(customerServiceName({ slug: 'some-slug', courier: '', name: '' })).toBe('some-slug'); }); });