Modernizes testing infrastructure with dedicated Cloudflare Workers test pool: - Replaces Nuxt Test Utils with @cloudflare/vitest-pool-workers - Adds structured test organization for API endpoints - Introduces comprehensive testing patterns and examples - Implements schema-based test data generation with zod-mock - Enhances test utilities with proper CF Workers environment The new testing setup provides better isolation, more realistic worker runtime environment, and improved test data management through structured schemas and generators.
24 lines
1.1 KiB
TypeScript
24 lines
1.1 KiB
TypeScript
import { customAlphabet } from 'nanoid'
|
|
import { z } from 'zod'
|
|
|
|
const { slugRegex } = useAppConfig()
|
|
|
|
const slugDefaultLength = +useRuntimeConfig().public.slugDefaultLength
|
|
|
|
export const nanoid = (length: number = slugDefaultLength) => customAlphabet('23456789abcdefghjkmnpqrstuvwxyz', length)
|
|
|
|
export const LinkSchema = z.object({
|
|
id: z.string().trim().max(26).default(nanoid(10)),
|
|
url: z.string().trim().url().max(2048),
|
|
slug: z.string().trim().max(2048).regex(new RegExp(slugRegex)).default(nanoid()),
|
|
comment: z.string().trim().max(2048).optional(),
|
|
createdAt: z.number().int().safe().default(() => Math.floor(Date.now() / 1000)),
|
|
updatedAt: z.number().int().safe().default(() => Math.floor(Date.now() / 1000)),
|
|
expiration: z.number().int().safe().refine(expiration => expiration > Math.floor(Date.now() / 1000), {
|
|
message: 'expiration must be greater than current time',
|
|
path: ['expiration'],
|
|
}).optional(),
|
|
title: z.string().trim().max(2048).optional(),
|
|
description: z.string().trim().max(2048).optional(),
|
|
image: z.string().trim().url().max(2048).optional(),
|
|
})
|