import { toCents, formatPrice, isValidEmail } from '../../src/utils'; describe('toCents', () => { it('converts a dollar string to integer cents', () => { expect(toCents('19.99')).toBe(1999); }); it('converts a plain number to integer cents', () => { expect(toCents(5)).toBe(500); }); it('rounds to the nearest cent', () => { expect(toCents('19.999')).toBe(2000); }); it('throws on non-numeric input', () => { expect(() => toCents('not-a-number')).toThrow('invalid price'); }); it('throws on a negative price', () => { expect(() => toCents(-5)).toThrow('invalid price'); }); }); describe('formatPrice', () => { it('formats cents as a dollar string', () => { expect(formatPrice(1999)).toBe('$19.99'); }); it('pads to two decimal places', () => { expect(formatPrice(500)).toBe('$5.00'); }); }); describe('isValidEmail', () => { it('accepts a well-formed email', () => { expect(isValidEmail('thom@example.com')).toBe(true); }); it('rejects a string with no @', () => { expect(isValidEmail('not-an-email')).toBe(false); }); it('rejects an email with no domain', () => { expect(isValidEmail('thom@')).toBe(false); }); });