Rocky_Mountain_Vending/.pnpm-store/v10/files/25/587282495e5c5084d0f67b9edf6c36df10b6b266b8223b5273280268b5898614e6bb965a7b2bc3c24206901a5012b4819cbcf5b266d35c3a9e27c963fff83f
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

141 lines
4 KiB
Text

import * as valibot from 'valibot';
/* eslint-disable no-console, @typescript-eslint/ban-ts-comment */
import { valibotResolver } from '..';
import {
fields,
invalidData,
invalidSchemaErrorData,
schema,
schemaError,
validData,
validSchemaErrorData,
} from './__fixtures__/data';
const shouldUseNativeValidation = false;
describe('valibotResolver', () => {
it('should return parsed values from valibotResolver with `mode: sync` when validation pass', async () => {
vi.mock('valibot', async () => {
const a = await vi.importActual<any>('valibot');
return {
__esModule: true,
...a,
};
});
const funcSpy = vi.spyOn(valibot, 'safeParseAsync');
const result = await valibotResolver(schema, undefined, {
mode: 'sync',
})(validData, undefined, { fields, shouldUseNativeValidation });
expect(funcSpy).toHaveBeenCalledTimes(1);
expect(result.errors).toEqual({});
expect(result).toMatchSnapshot();
});
it('should return a single error from valibotResolver with `mode: sync` when validation fails', async () => {
vi.mock('valibot', async () => {
const a = await vi.importActual<any>('valibot');
return {
__esModule: true,
...a,
};
});
const funcSpy = vi.spyOn(valibot, 'safeParseAsync');
const result = await valibotResolver(schema, undefined, {
mode: 'sync',
})(invalidData, undefined, { fields, shouldUseNativeValidation });
expect(funcSpy).toHaveBeenCalledTimes(1);
expect(result).toMatchSnapshot();
});
it('should return values from valibotResolver when validation pass', async () => {
const result = await valibotResolver(schema)(validData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(result).toEqual({ errors: {}, values: validData });
});
it('should return a single error from valibotResolver when validation fails', async () => {
const result = await valibotResolver(schema)(invalidData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(result).toMatchSnapshot();
});
it('should return values from valibotResolver when validation pass & raw=true', async () => {
const result = await valibotResolver(schema, undefined, {
raw: true,
})(validData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(result).toEqual({ errors: {}, values: validData });
});
it('should return all the errors from valibotResolver when validation fails with `validateAllFieldCriteria` set to true', async () => {
const result = await valibotResolver(schema)(invalidData, undefined, {
fields,
criteriaMode: 'all',
shouldUseNativeValidation,
});
expect(result).toMatchSnapshot();
});
it('should return all the errors from valibotResolver when validation fails with `validateAllFieldCriteria` set to true and `mode: sync`', async () => {
const result = await valibotResolver(schema, undefined, { mode: 'sync' })(
invalidData,
undefined,
{
fields,
criteriaMode: 'all',
shouldUseNativeValidation,
},
);
expect(result).toMatchSnapshot();
});
it('should be able to validate variants without errors', async () => {
const result = await valibotResolver(schemaError, undefined, {
mode: 'sync',
})(validSchemaErrorData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(result).toEqual({
errors: {},
values: {
type: 'a',
},
});
});
it('should be able to validate variants with errors', async () => {
const result = await valibotResolver(schemaError, undefined, {
mode: 'sync',
})(invalidSchemaErrorData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(result).toEqual({
errors: {
type: {
message: 'Invalid type: Expected "a" | "b" but received "c"',
ref: undefined,
type: 'variant',
},
},
values: {},
});
});
});