/* eslint-env jest */ import { shippingFill, shippingFillSummary } from '../shipping-fill'; const found = (rate: string, free_over = '', zones = ['Romania']) => ({ countries: rate === '' ? '' : 'RO,MD', rate, free_over, zones: rate === '' ? [] : zones, skipped: [], }); describe('filling the shipping fields from WooCommerce', () => { it('sets the rate, the threshold and the countries as typed by hand', () => { expect(shippingFill(found('5', '75'))).toEqual({ rate: '5', free_over: '75', countries: 'RO, MD', }); expect(shippingFillSummary(found('5', '75', ['Romania', 'Moldova']))).toBe( 'A flat 5, free from 75, to RO, MD, from the 2 zones Romania, Moldova. Check it and save the changes to put it in the schema.' ); expect(shippingFillSummary(found('0'))).toMatch( /^Free shipping to RO, MD, from the zone Romania\./ ); }); it('fills nothing when no zone maps', () => { expect(shippingFill(found(''))).toBeNull(); expect(shippingFillSummary(found(''))).toMatch(/^Nothing filled/); }); });