Rocky_Mountain_Vending/.pnpm-store/v10/files/72/2cf4af5f48cdf033e460a8b5ad1c8270a13954d5c49987ea27ec62f95f24ca869865639047e8bf7624ae98d4b5befa6732255be632f0a6f37c231fe49c3baa
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

57 lines
1.7 KiB
Text

import { isLeft } from 'fp-ts/Either';
import * as t from 'io-ts';
import errorsToRecord from '../errorsToRecord';
const assertLeft = <T>(result: t.Validation<T>) => {
expect(isLeft(result)).toBe(true);
if (!isLeft(result)) {
throw new Error(
'panic! error is not of the "left" type, should be unreachable',
);
}
return result.left;
};
const FIRST_NAME_FIELD_PATH = 'firstName' as const;
const FIRST_NAME_ERROR_SHAPE = {
message: 'expected string but got undefined',
type: 'string',
};
describe('errorsToRecord', () => {
it('should return a correct error for an exact intersection type error object', () => {
// a recommended pattern from https://github.com/gcanti/io-ts/blob/master/index.md#mixing-required-and-optional-props
const schema = t.exact(
t.intersection([
t.type({
[FIRST_NAME_FIELD_PATH]: t.string,
}),
t.partial({
lastName: t.string,
}),
]),
);
const error = assertLeft(schema.decode({}));
const record = errorsToRecord(false)(error);
expect(record[FIRST_NAME_FIELD_PATH]).toMatchObject(FIRST_NAME_ERROR_SHAPE);
});
it('should return a correct error for a branded intersection', () => {
interface Brand {
readonly Brand: unique symbol;
}
const schema = t.brand(
t.intersection([
t.type({
[FIRST_NAME_FIELD_PATH]: t.string,
}),
t.type({
lastName: t.string,
}),
]),
(_x): _x is t.Branded<typeof _x, Brand> => true,
'Brand',
);
const error = assertLeft(schema.decode({}));
const record = errorsToRecord(false)(error);
expect(record[FIRST_NAME_FIELD_PATH]).toMatchObject(FIRST_NAME_ERROR_SHAPE);
});
});