Rocky_Mountain_Vending/.pnpm-store/v10/files/b9/9b0898b6d13171b3c26a9e6044cd74c13edadc0638741e8b637569c93ea62cce253401cddc9a2762ed84978efb5f9e91ff6735dd32319c3605bb753f183174
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

113 lines
3.2 KiB
Text

/* eslint-disable no-console, @typescript-eslint/ban-ts-comment */
import { fluentValidationResolver } from '..';
import {
SchemaValidator,
fields,
invalidData,
validData,
} from './__fixtures__/data';
const shouldUseNativeValidation = false;
const validator = new SchemaValidator();
describe('fluentValidationResolver', () => {
it('should return values from fluentValidationResolver when validation pass', async () => {
const validatorSpy = vi.spyOn(validator, 'validate');
const result = await fluentValidationResolver(validator)(
validData,
undefined,
{
fields,
shouldUseNativeValidation,
},
);
expect(validatorSpy).toHaveBeenCalledTimes(1);
expect(result).toEqual({ errors: {}, values: validData });
});
it('should return values from fluentValidationResolver with `mode: sync` when validation pass', async () => {
const validatorSpy = vi.spyOn(validator, 'validate');
const result = await fluentValidationResolver(validator)(
validData,
undefined,
{ fields, shouldUseNativeValidation },
);
expect(validatorSpy).toHaveBeenCalledTimes(1);
expect(result).toEqual({ errors: {}, values: validData });
});
it('should return a single error from fluentValidationResolver when validation fails', async () => {
const result = await fluentValidationResolver(validator)(
invalidData,
undefined,
{
fields,
shouldUseNativeValidation,
},
);
expect(result).toMatchSnapshot();
});
it('should return a single error from fluentValidationResolver with `mode: sync` when validation fails', async () => {
const validateSpy = vi.spyOn(validator, 'validate');
const result = await fluentValidationResolver(validator)(
invalidData,
undefined,
{ fields, shouldUseNativeValidation },
);
expect(validateSpy).toHaveBeenCalledTimes(1);
expect(result).toMatchSnapshot();
});
it('should return all the errors from fluentValidationResolver when validation fails with `validateAllFieldCriteria` set to true', async () => {
const result = await fluentValidationResolver(validator)(
invalidData,
undefined,
{
fields,
criteriaMode: 'all',
shouldUseNativeValidation,
},
);
expect(result).toMatchSnapshot();
});
it('should return all the errors from fluentValidationResolver when validation fails with `validateAllFieldCriteria` set to true and `mode: sync`', async () => {
const result = await fluentValidationResolver(validator)(
invalidData,
undefined,
{
fields,
criteriaMode: 'all',
shouldUseNativeValidation,
},
);
expect(result).toMatchSnapshot();
});
it('should return values from fluentValidationResolver when validation pass & raw=true', async () => {
const schemaSpy = vi.spyOn(validator, 'validate');
const result = await fluentValidationResolver(validator)(
validData,
undefined,
{
fields,
shouldUseNativeValidation,
},
);
expect(schemaSpy).toHaveBeenCalledTimes(1);
expect(result).toEqual({ errors: {}, values: validData });
});
});