import { DraftSchema } from '../../src/intake/draftSchema'; const valid = { name: 'Blue stoneware vase', description: 'A hand-thrown vase with a chipped base.', category: 'Ceramics', tags: ['stoneware', 'blue'], suggestedPriceCents: 4500 }; describe('DraftSchema', () => { it('accepts a complete draft', () => { expect(DraftSchema.parse(valid)).toEqual(valid); }); // The model is told to say nothing rather than guess, so every field it may // decline to answer has to be expressible as absent. it('accepts a draft with no category, tags or price', () => { const parsed = DraftSchema.parse({ name: valid.name, description: valid.description, category: null, tags: [], suggestedPriceCents: null }); expect(parsed.category).toBeNull(); expect(parsed.suggestedPriceCents).toBeNull(); }); // A name and a description are the whole point. A draft without them is not // a partial success worth storing. it('refuses a draft with no name', () => { expect(() => DraftSchema.parse({ ...valid, name: '' })).toThrow(); }); it('refuses a draft with no description', () => { expect(() => DraftSchema.parse({ ...valid, description: '' })).toThrow(); }); // A negative or absurd price reaching the review queue would be a number // somebody has to notice is wrong. Cheaper to refuse it here. it('refuses a negative price', () => { expect(() => DraftSchema.parse({ ...valid, suggestedPriceCents: -1 })).toThrow(); }); it('refuses a price beyond anything this shop sells', () => { expect(() => DraftSchema.parse({ ...valid, suggestedPriceCents: 100_000_00 })).toThrow(); }); // Cents, not dollars. A float would round somewhere nobody is looking. it('refuses a fractional price', () => { expect(() => DraftSchema.parse({ ...valid, suggestedPriceCents: 45.5 })).toThrow(); }); });