feat(privacy): complete the publication, hiding and preview settings screen
This commit is contained in:
1 parent
c2a8d17195
commit
5edff21d2d
28 files changed
+2230
-428
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import type { ZodType } from "zod";
|
||||
import { fakeFromPattern, type PatternLengthBounds } from "./mock-pattern";
|
||||
import * as schemas from "./schemas";
|
||||
@@ -11,7 +11,12 @@ import * as schemas from "./schemas";
|
||||
// discovered from the generated files, so a new operation is covered without
|
||||
// editing this test.
|
||||
|
||||
// A fixed, bounded set of seeds keeps every run identical. Generating and
|
||||
// validating the large union mocks takes seconds on a loaded machine, so the
|
||||
// default 5 s limit of a test would fail on speed, not on an invalid mock.
|
||||
const seeds = Array.from({ length: 25 }, (_, index) => index + 1);
|
||||
const mockCaseTimeoutMs = 60_000;
|
||||
const fixedReferenceDate = new Date("2026-10-09T12:00:00Z");
|
||||
|
||||
const mockModules = import.meta.glob<Record<string, unknown>>("./endpoints/*/*.msw.ts", {
|
||||
eager: true,
|
||||
@@ -95,6 +100,12 @@ function describeValue(value: unknown): string {
|
||||
const cases = discoverCases();
|
||||
|
||||
describe("generated MSW response mocks", () => {
|
||||
// Date generators are relative to the current time unless a reference date
|
||||
// is set, which would make a run depend on the moment it starts.
|
||||
beforeAll(() => {
|
||||
faker.setDefaultRefDate(fixedReferenceDate);
|
||||
});
|
||||
|
||||
it("discovers a response factory for every generated mock module", () => {
|
||||
expect(Object.keys(mockModules).length).toBeGreaterThan(0);
|
||||
const covered = new Set(cases.map((item) => item.file));
|
||||
@@ -111,24 +122,28 @@ describe("generated MSW response mocks", () => {
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it.each(cases)("$factoryName returns a valid $schemaName", ({ factory, schema }) => {
|
||||
const failures: string[] = [];
|
||||
for (const seed of seeds) {
|
||||
faker.seed(seed);
|
||||
const mock = factory();
|
||||
const result = schema.safeParse(mock);
|
||||
if (result.success) {
|
||||
continue;
|
||||
it.each(cases)(
|
||||
"$factoryName returns a valid $schemaName",
|
||||
({ factory, schema }) => {
|
||||
const failures: string[] = [];
|
||||
for (const seed of seeds) {
|
||||
faker.seed(seed);
|
||||
const mock = factory();
|
||||
const result = schema.safeParse(mock);
|
||||
if (result.success) {
|
||||
continue;
|
||||
}
|
||||
for (const issue of result.error.issues) {
|
||||
const path = issue.path.length > 0 ? issue.path.join(".") : "(root)";
|
||||
failures.push(
|
||||
`seed ${seed}: ${path}: ${issue.message}; value ${describeValue(valueAt(mock, issue.path))}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const issue of result.error.issues) {
|
||||
const path = issue.path.length > 0 ? issue.path.join(".") : "(root)";
|
||||
failures.push(
|
||||
`seed ${seed}: ${path}: ${issue.message}; value ${describeValue(valueAt(mock, issue.path))}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
expect(failures).toEqual([]);
|
||||
});
|
||||
expect(failures).toEqual([]);
|
||||
},
|
||||
mockCaseTimeoutMs,
|
||||
);
|
||||
});
|
||||
|
||||
describe("fakeFromPattern", () => {
|
||||
|
||||
Reference in new issue
Block a user