fortify-schema
Version:
A modern TypeScript validation library designed around familiar interface syntax and powerful conditional validation. Experience schema validation that feels natural to TypeScript developers while unlocking advanced runtime validation capabilities.
92 lines (80 loc) • 2.57 kB
text/typescript
// Test Make API fix
import { Interface, Make } from "../schema/mode/interfaces/Interface";
console.log("=== TESTING MAKE API FIX ===");
// Test that conversion is working by checking schema internals
console.log("Testing Make API conversion...");
// Create schema with Make API
const TestSchema = Interface({
id: "number",
status: Make.union("active", "inactive"),
role: Make.const("user"),
});
// Test 1: Valid Make.const()
const test1 = TestSchema.safeParse({
id: 1,
status: "active",
role: "user", // Should match Make.const("user")
});
console.log("✅ Valid const:", test1.success ? "PASSED" : "FAILED");
// Test 2: Invalid Make.const()
const test2 = TestSchema.safeParse({
id: 1,
status: "active",
role: "admin", // Should fail - doesn't match Make.const("user")
});
console.log("❌ Invalid const:", !test2.success ? "PASSED" : "FAILED");
if (!test2.success) {
console.log(" Error:", test2.errors[0]);
}
// Test 3: Valid Make.union()
const test3 = TestSchema.safeParse({
id: 1,
status: "inactive", // Should match Make.union("active", "inactive")
role: "user",
});
console.log("✅ Valid union:", test3.success ? "PASSED" : "FAILED");
// Test 4: Invalid Make.union()
const test4 = TestSchema.safeParse({
id: 1,
status: "pending", // Should fail - not in Make.union("active", "inactive")
role: "user",
});
console.log("❌ Invalid union:", !test4.success ? "PASSED" : "FAILED");
if (!test4.success) {
console.log(" Error:", test4.errors[0]);
}
// Test 5: Basic type validation
const test5 = TestSchema.safeParse({
id: "1", // String instead of number - should fail
status: "active",
role: "user",
});
console.log("❌ Invalid type:", !test5.success ? "PASSED" : "FAILED");
if (!test5.success) {
console.log(" Error:", test5.errors[0]);
}
// Test 6: Direct string syntax (should work the same)
console.log("\n=== TESTING DIRECT STRING SYNTAX ===");
const DirectSchema = Interface({
id: "number",
status: "active|inactive",
role: "=user",
});
const test6 = DirectSchema.safeParse({
id: 1,
status: "active",
role: "admin", // Should fail - doesn't match "=user"
});
console.log("❌ Direct const syntax:", !test6.success ? "PASSED" : "FAILED");
console.log("❌ Direct const syntax error:", test6.errors);
if (!test6.success) {
console.log(" Error:", test6.errors[0]);
}
console.log("\n=== SUMMARY ===");
const allPassed =
test1.success &&
!test2.success &&
test3.success &&
!test4.success &&
!test5.success;
console.log("All tests:", allPassed ? "✅ PASSED" : "❌ FAILED");