Rocky_Mountain_Vending/.pnpm-store/v10/files/09/4673e9c8f11a04b944fee6c7d30a6827ccb20e446b53ab392e1c22dabee0a195470513fe29a4fe0c6b03db2f7608ccef8108fc31df2f836b1e90427b8c0069
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

109 lines
3 KiB
Text

import { expect, test } from "vitest";
import * as z from "zod/v4";
test("string format methods", () => {
const a = z.email().min(10);
const b = z.email().max(10);
const c = z.email().length(10);
const d = z.email().uppercase();
const e = z.email().lowercase();
// Positive and negative cases for `a`
expect(a.safeParse("longemail@example.com").success).toBe(true); // Positive
expect(a.safeParse("ort@e.co").success).toBe(false); // Negative
// Positive and negative cases for `b`
expect(b.safeParse("sho@e.co").success).toBe(true); // Positive
expect(b.safeParse("longemail@example.com").success).toBe(false); // Negative
// Positive and negative cases for `c`
expect(c.safeParse("56780@e.co").success).toBe(true); // Positive
expect(c.safeParse("shoasdfasdfrt@e.co").success).toBe(false); // Negative
// Positive and negative cases for `d`
expect(d.safeParse("EMAIL@EXAMPLE.COM").success).toBe(true); // Positive
expect(d.safeParse("email@example.com").success).toBe(false); // Negative
// Positive and negative cases for `e`
expect(e.safeParse("email@example.com").success).toBe(true); // Positive
expect(e.safeParse("EMAIL@EXAMPLE.COM").success).toBe(false); // Negative
});
test("z.stringFormat", () => {
const ccRegex = /^(?:\d{14,19}|\d{4}(?: \d{3,6}){2,4}|\d{4}(?:-\d{3,6}){2,4})$/u;
const a = z
.stringFormat("creditCard", (val) => ccRegex.test(val), {
error: `Invalid credit card number`,
})
.refine((_) => false, "Also bad");
expect(a.safeParse("asdf")).toMatchInlineSnapshot(`
{
"error": [ZodError: [
{
"code": "invalid_format",
"format": "creditCard",
"path": [],
"message": "Invalid credit card number"
},
{
"code": "custom",
"path": [],
"message": "Also bad"
}
]],
"success": false,
}
`);
expect(a.safeParse("1234-5678-9012-3456")).toMatchInlineSnapshot(`
{
"error": [ZodError: [
{
"code": "custom",
"path": [],
"message": "Also bad"
}
]],
"success": false,
}
`);
expect(a.def.pattern).toMatchInlineSnapshot(`undefined`);
const b = z
.stringFormat("creditCard", ccRegex, {
abort: true,
error: `Invalid credit card number`,
})
.refine((_) => false, "Also bad");
expect(b.safeParse("asdf")).toMatchInlineSnapshot(`
{
"error": [ZodError: [
{
"code": "invalid_format",
"format": "creditCard",
"path": [],
"message": "Invalid credit card number"
}
]],
"success": false,
}
`);
expect(b.safeParse("1234-5678-9012-3456")).toMatchInlineSnapshot(`
{
"error": [ZodError: [
{
"code": "custom",
"path": [],
"message": "Also bad"
}
]],
"success": false,
}
`);
expect(b.def.pattern).toMatchInlineSnapshot(
`/\\^\\(\\?:\\\\d\\{14,19\\}\\|\\\\d\\{4\\}\\(\\?: \\\\d\\{3,6\\}\\)\\{2,4\\}\\|\\\\d\\{4\\}\\(\\?:-\\\\d\\{3,6\\}\\)\\{2,4\\}\\)\\$/u`
);
});