54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
import fc from "fast-check";
|
|
import { InitiateUploadBodySchema } from "../src/schemas/routes/initiate.js";
|
|
|
|
describe("InitiateUploadBodySchema (fast-check)", () => {
|
|
it("accepts every well-formed input across 200 runs", {
|
|
timeout: 30000,
|
|
}, () => {
|
|
fc.assert(
|
|
fc.property(
|
|
fc.record({
|
|
fileName: fc.string({ minLength: 1, maxLength: 200 }),
|
|
totalSize: fc.integer({
|
|
min: 1,
|
|
max: 1024 * 1024 * 1024,
|
|
}),
|
|
totalSha256: fc.hexaString({
|
|
minLength: 64,
|
|
maxLength: 64,
|
|
}),
|
|
}),
|
|
(input) => {
|
|
const result = InitiateUploadBodySchema.safeParse(input);
|
|
return result.success === true;
|
|
}
|
|
),
|
|
{ numRuns: 200 }
|
|
);
|
|
expect(true).toBe(true);
|
|
});
|
|
|
|
it("rejects malformed totalSha256 in 200 runs", {
|
|
timeout: 30000,
|
|
}, () => {
|
|
fc.assert(
|
|
fc.property(
|
|
fc.record({
|
|
fileName: fc.string({ minLength: 1, maxLength: 32 }),
|
|
totalSize: fc.integer({ min: 1, max: 1024 }),
|
|
totalSha256: fc
|
|
.string({ minLength: 1, maxLength: 63 })
|
|
.filter((s) => s.length !== 64),
|
|
}),
|
|
(input) => {
|
|
const result = InitiateUploadBodySchema.safeParse(input);
|
|
return result.success === false;
|
|
}
|
|
),
|
|
{ numRuns: 200 }
|
|
);
|
|
expect(true).toBe(true);
|
|
});
|
|
});
|