77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
import { randomUUID } from 'node:crypto';
|
|
import {
|
|
customCandleRequestSchema,
|
|
customCandleDecisionSchema,
|
|
customCandleQuerySchema,
|
|
} from '../src/b2b/custom-candle.schemas';
|
|
|
|
const input = {
|
|
accountId: randomUUID(),
|
|
quantity: 500,
|
|
waxType: 'Soy',
|
|
fragrance: 'Rose',
|
|
container: 'Glass jar',
|
|
color: 'Ivory',
|
|
brandingRequirements: 'Printed logo label',
|
|
specifications: '200g fill, cotton wick',
|
|
idempotencyKey: randomUUID(),
|
|
};
|
|
describe('Custom candle validation', () => {
|
|
it('normalizes text and accepts quantity boundaries', () => {
|
|
expect(
|
|
customCandleRequestSchema.parse({ ...input, waxType: ' Soy ' }).waxType,
|
|
).toBe('Soy');
|
|
for (const quantity of [1, 1_000_000])
|
|
expect(
|
|
customCandleRequestSchema.safeParse({ ...input, quantity }).success,
|
|
).toBe(true);
|
|
});
|
|
it('rejects invalid quantities, missing specifications and unknown input', () => {
|
|
for (const quantity of [0, -1, 1.5, 1_000_001])
|
|
expect(
|
|
customCandleRequestSchema.safeParse({ ...input, quantity }).success,
|
|
).toBe(false);
|
|
for (const field of [
|
|
'waxType',
|
|
'fragrance',
|
|
'container',
|
|
'color',
|
|
'brandingRequirements',
|
|
'specifications',
|
|
]) {
|
|
expect(
|
|
customCandleRequestSchema.safeParse({ ...input, [field]: ' ' }).success,
|
|
).toBe(false);
|
|
}
|
|
expect(
|
|
customCandleRequestSchema.safeParse({ ...input, price: '100.00' })
|
|
.success,
|
|
).toBe(false);
|
|
expect(
|
|
customCandleRequestSchema.safeParse({
|
|
...input,
|
|
specifications: 'a'.repeat(2001),
|
|
}).success,
|
|
).toBe(false);
|
|
});
|
|
it('validates decisions and filters', () => {
|
|
expect(
|
|
customCandleDecisionSchema.safeParse({
|
|
decision: 'APPROVED',
|
|
note: 'Feasible',
|
|
idempotencyKey: randomUUID(),
|
|
}).success,
|
|
).toBe(true);
|
|
expect(
|
|
customCandleDecisionSchema.safeParse({
|
|
decision: 'REQUESTED',
|
|
note: 'Feasible',
|
|
idempotencyKey: randomUUID(),
|
|
}).success,
|
|
).toBe(false);
|
|
expect(
|
|
customCandleQuerySchema.safeParse({ status: 'DISPATCHED' }).success,
|
|
).toBe(false);
|
|
});
|
|
});
|