setup: add vitest test infrastructure with helpers, fixtures, and reactive test patterns
This commit is contained in:
96
test/helpers/schemas.ts
Normal file
96
test/helpers/schemas.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
import { Type, type Static, type TSchema } from "@alkdev/typebox";
|
||||
|
||||
export const CompatibleInputSchema = Type.Object({
|
||||
value: Type.Number(),
|
||||
label: Type.Optional(Type.String()),
|
||||
});
|
||||
|
||||
export const CompatibleOutputSchema = Type.Object({
|
||||
value: Type.Number(),
|
||||
label: Type.Optional(Type.String()),
|
||||
});
|
||||
|
||||
export type CompatibleInput = Static<typeof CompatibleInputSchema>;
|
||||
export type CompatibleOutput = Static<typeof CompatibleOutputSchema>;
|
||||
|
||||
export const NarrowOutputSchema = Type.Object({
|
||||
value: Type.Number(),
|
||||
});
|
||||
|
||||
export const WideInputSchema = Type.Object({
|
||||
value: Type.Number(),
|
||||
label: Type.Optional(Type.String()),
|
||||
metadata: Type.Optional(Type.Record(Type.String(), Type.String())),
|
||||
});
|
||||
|
||||
export type NarrowOutput = Static<typeof NarrowOutputSchema>;
|
||||
export type WideInput = Static<typeof WideInputSchema>;
|
||||
|
||||
export const IncompatibleNumberOutputSchema = Type.Object({
|
||||
value: Type.Number(),
|
||||
});
|
||||
|
||||
export const IncompatibleStringInputSchema = Type.Object({
|
||||
value: Type.String(),
|
||||
});
|
||||
|
||||
export type IncompatibleNumberOutput = Static<typeof IncompatibleNumberOutputSchema>;
|
||||
export type IncompatibleStringInput = Static<typeof IncompatibleStringInputSchema>;
|
||||
|
||||
export const MissingRequiredFieldOutputSchema = Type.Object({
|
||||
id: Type.String(),
|
||||
});
|
||||
|
||||
export const MissingRequiredFieldInputSchema = Type.Object({
|
||||
id: Type.String(),
|
||||
name: Type.String(),
|
||||
});
|
||||
|
||||
export type MissingRequiredFieldOutput = Static<typeof MissingRequiredFieldOutputSchema>;
|
||||
export type MissingRequiredFieldInput = Static<typeof MissingRequiredFieldInputSchema>;
|
||||
|
||||
export const UnknownSchema = Type.Unknown();
|
||||
|
||||
export const compatiblePairs: Array<{
|
||||
name: string;
|
||||
output: TSchema;
|
||||
input: TSchema;
|
||||
}> = [
|
||||
{
|
||||
name: "identical-structure",
|
||||
output: CompatibleOutputSchema,
|
||||
input: CompatibleInputSchema,
|
||||
},
|
||||
{
|
||||
name: "narrow-output-wide-input",
|
||||
output: NarrowOutputSchema,
|
||||
input: WideInputSchema,
|
||||
},
|
||||
];
|
||||
|
||||
export const incompatiblePairs: Array<{
|
||||
name: string;
|
||||
output: TSchema;
|
||||
input: TSchema;
|
||||
}> = [
|
||||
{
|
||||
name: "type-mismatch-number-string",
|
||||
output: IncompatibleNumberOutputSchema,
|
||||
input: IncompatibleStringInputSchema,
|
||||
},
|
||||
{
|
||||
name: "missing-required-field",
|
||||
output: MissingRequiredFieldOutputSchema,
|
||||
input: MissingRequiredFieldInputSchema,
|
||||
},
|
||||
];
|
||||
|
||||
export const unknownSchemas: Array<{
|
||||
name: string;
|
||||
schema: TSchema;
|
||||
}> = [
|
||||
{
|
||||
name: "unknown-schema",
|
||||
schema: UnknownSchema,
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user