test(frontend): pin the generated questionnaire contract
This commit is contained in:
1 parent
faeeb5f157
commit
78f1651f6b
1 file changed
+114
@@ -0,0 +1,114 @@
|
||||
import { describe, expect, expectTypeOf, it } from "vitest";
|
||||
import { saveMyQuestionnaire } from "./endpoints/candidate/candidate";
|
||||
import {
|
||||
CandidateQuestionnaire,
|
||||
CandidateQuestionnaireUpdate,
|
||||
SaveMyQuestionnaireBody,
|
||||
} from "./schemas";
|
||||
|
||||
// These tests pin the generated questionnaire contract that the FSD adapters
|
||||
// consume. They fail when regeneration drops a limit or adds a field that
|
||||
// would let a client claim a confirmed grade.
|
||||
|
||||
const backend = {
|
||||
specialization: "backend",
|
||||
self_assessed_grade: "middle",
|
||||
task_languages: ["go"],
|
||||
stack: ["PostgreSQL", "gRPC", "Kafka"],
|
||||
experience: { commercial_months: 30, academic_months: 12 },
|
||||
} as const;
|
||||
|
||||
const networkEngineer = {
|
||||
specialization: "network_engineer",
|
||||
self_assessed_grade: "junior",
|
||||
task_languages: [],
|
||||
stack: [],
|
||||
experience: null,
|
||||
} as const;
|
||||
|
||||
const validUpdate = {
|
||||
expected_version: 0,
|
||||
specializations: [backend, networkEngineer],
|
||||
work_context: { work_formats: ["remote", "hybrid"] },
|
||||
};
|
||||
|
||||
const bodySchemas = [
|
||||
["CandidateQuestionnaireUpdate", CandidateQuestionnaireUpdate],
|
||||
["SaveMyQuestionnaireBody", SaveMyQuestionnaireBody],
|
||||
] as const;
|
||||
|
||||
describe.each(bodySchemas)("generated %s", (_name, schema) => {
|
||||
it("accepts Backend with Go as a task language next to Network Engineer", () => {
|
||||
const parsed = schema.parse(validUpdate);
|
||||
|
||||
expect(parsed.specializations.map((item) => item.specialization)).toEqual([
|
||||
"backend",
|
||||
"network_engineer",
|
||||
]);
|
||||
expect(parsed.specializations[0]?.task_languages).toEqual(["go"]);
|
||||
});
|
||||
|
||||
it("rejects a third specialization instead of truncating the list", () => {
|
||||
const result = schema.safeParse({
|
||||
...validUpdate,
|
||||
specializations: [backend, networkEngineer, { ...backend, specialization: "qa" }],
|
||||
});
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.error?.issues).toEqual([
|
||||
expect.objectContaining({ code: "too_big", path: ["specializations"] }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("rejects an unknown grade", () => {
|
||||
const result = schema.safeParse({
|
||||
...validUpdate,
|
||||
specializations: [{ ...backend, self_assessed_grade: "lead" }],
|
||||
});
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.error?.issues).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "invalid_value",
|
||||
path: ["specializations", 0, "self_assessed_grade"],
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("rejects a language used as a specialization", () => {
|
||||
const result = schema.safeParse({
|
||||
...validUpdate,
|
||||
specializations: [{ ...backend, specialization: "go" }],
|
||||
});
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.error?.issues).toEqual([
|
||||
expect.objectContaining({ path: ["specializations", 0, "specialization"] }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("never carries a confirmed grade or a category in the parsed body", () => {
|
||||
const parsed = schema.parse({
|
||||
...validUpdate,
|
||||
confirmed_grade: "senior",
|
||||
specializations: [{ ...backend, confirmed_grade: "senior", category: "backend" }],
|
||||
});
|
||||
|
||||
// Generated Zod strips unknown keys; the server rejects them with 400.
|
||||
expect(parsed).not.toHaveProperty("confirmed_grade");
|
||||
expect(parsed.specializations[0]).not.toHaveProperty("confirmed_grade");
|
||||
expect(parsed.specializations[0]).not.toHaveProperty("category");
|
||||
});
|
||||
});
|
||||
|
||||
it("exposes the questionnaire DTOs without a confirmed grade field", () => {
|
||||
type UpdateItem = CandidateQuestionnaireUpdate["specializations"][number];
|
||||
type StoredItem = CandidateQuestionnaire["specializations"][number];
|
||||
|
||||
expectTypeOf<CandidateQuestionnaireUpdate>().not.toHaveProperty("confirmed_grade");
|
||||
expectTypeOf<UpdateItem>().not.toHaveProperty("confirmed_grade");
|
||||
expectTypeOf<UpdateItem>().not.toHaveProperty("category");
|
||||
expectTypeOf<StoredItem>().not.toHaveProperty("confirmed_grade");
|
||||
expectTypeOf<StoredItem>().not.toHaveProperty("category");
|
||||
expectTypeOf(saveMyQuestionnaire).parameter(0).toEqualTypeOf<CandidateQuestionnaireUpdate>();
|
||||
});
|
||||
Reference in new issue
Block a user