240 lines
7.5 KiB
TypeScript
240 lines
7.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
import type { CardField, CardPreview } from "../../../shared/api/schemas";
|
||
import {
|
||
contactAccessAfterVisibilityChange,
|
||
describeAccessOrganization,
|
||
describePublicationClosure,
|
||
editableCardFields,
|
||
presentCandidatePreview,
|
||
publishableCardFields,
|
||
} from "./presentation";
|
||
|
||
function preview(card: NonNullable<CardPreview["card"]>): CardPreview {
|
||
return {
|
||
state: "published",
|
||
fields: ["categories", "self_assessment", "stack", "experience", "work_formats"],
|
||
card,
|
||
evidence: { items: [] },
|
||
generated_at: "2026-10-06T12:00:00Z",
|
||
};
|
||
}
|
||
|
||
describe("candidate card presentation", () => {
|
||
it("keeps confirmed categories separate from declared grades", () => {
|
||
const result = presentCandidatePreview(
|
||
preview({
|
||
pseudonym: `cv1_${"a".repeat(43)}`,
|
||
categories: [
|
||
{
|
||
specialization: "backend",
|
||
grade: "junior",
|
||
strength: "standard",
|
||
basis: "synthetic_demo",
|
||
},
|
||
],
|
||
stack: ["go"],
|
||
self_assessment: [
|
||
{
|
||
specialization: "network_engineer",
|
||
confirmation_status: "unconfirmed",
|
||
declared_grade: "middle",
|
||
},
|
||
],
|
||
experience_band: "1_3",
|
||
work_formats: ["remote"],
|
||
salary_compatibility: null,
|
||
}),
|
||
);
|
||
|
||
expect(result?.categories).toEqual([
|
||
{
|
||
specialization: "Backend",
|
||
grade: "Junior",
|
||
strength: "Демонстрационное подтверждение",
|
||
},
|
||
]);
|
||
expect(result?.selfAssessments).toEqual([
|
||
{
|
||
specialization: "Сетевое администрирование",
|
||
declaredGrade: "Middle",
|
||
confirmed: false,
|
||
confirmation: "Грейд не подтвержден",
|
||
},
|
||
]);
|
||
});
|
||
|
||
it("states the confirmation of every specialization on its own", () => {
|
||
const result = presentCandidatePreview(
|
||
preview({
|
||
pseudonym: `cv1_${"b".repeat(43)}`,
|
||
categories: [
|
||
{
|
||
specialization: "backend",
|
||
grade: "middle",
|
||
strength: "strong",
|
||
basis: "synthetic_demo",
|
||
},
|
||
],
|
||
stack: null,
|
||
self_assessment: [
|
||
{ specialization: "backend", confirmation_status: "confirmed", declared_grade: "middle" },
|
||
{
|
||
specialization: "network_engineer",
|
||
confirmation_status: "unconfirmed",
|
||
declared_grade: "junior",
|
||
},
|
||
{ specialization: "qa", confirmation_status: "unconfirmed", declared_grade: null },
|
||
],
|
||
experience_band: null,
|
||
work_formats: null,
|
||
salary_compatibility: null,
|
||
}),
|
||
);
|
||
|
||
expect(
|
||
result?.selfAssessments?.map((item) => [
|
||
item.specialization,
|
||
item.confirmed,
|
||
item.confirmation,
|
||
]),
|
||
).toEqual([
|
||
["Backend", true, "Грейд подтвержден"],
|
||
["Сетевое администрирование", false, "Грейд не подтвержден"],
|
||
["Тестирование", false, "Грейд не подтвержден"],
|
||
]);
|
||
expect(result?.selfAssessments?.[2]?.declaredGrade).toBeNull();
|
||
});
|
||
|
||
it("restates the evidence basis and calibration the server reports", () => {
|
||
const result = presentCandidatePreview({
|
||
...preview({
|
||
pseudonym: `cv1_${"c".repeat(43)}`,
|
||
categories: [
|
||
{
|
||
specialization: "backend",
|
||
grade: "middle",
|
||
strength: "standard",
|
||
basis: "synthetic_demo",
|
||
},
|
||
],
|
||
stack: null,
|
||
self_assessment: null,
|
||
experience_band: null,
|
||
work_formats: null,
|
||
salary_compatibility: null,
|
||
}),
|
||
evidence: {
|
||
items: [
|
||
{
|
||
skill: "backend",
|
||
grade: "middle",
|
||
trust: 1,
|
||
basis: "synthetic_demo",
|
||
calibration_status: "uncalibrated",
|
||
observed_year: 2026,
|
||
},
|
||
],
|
||
},
|
||
});
|
||
|
||
expect(result?.evidence).toEqual([
|
||
{
|
||
title: "Backend: Middle",
|
||
trust: "partial",
|
||
trustLabel: "Онлайн-результат без подтверждения личности",
|
||
observedYear: 2026,
|
||
basisLabel: "Синтетическая демонстрация, не проверенное измерение",
|
||
calibrationLabel: "Пороги не откалиброваны",
|
||
},
|
||
]);
|
||
});
|
||
|
||
it("keeps an empty evidence list apart from a closed card", () => {
|
||
const published = presentCandidatePreview(
|
||
preview({
|
||
pseudonym: `cv1_${"d".repeat(43)}`,
|
||
categories: null,
|
||
stack: null,
|
||
self_assessment: null,
|
||
experience_band: null,
|
||
work_formats: null,
|
||
salary_compatibility: null,
|
||
}),
|
||
);
|
||
expect(published?.evidence).toEqual([]);
|
||
});
|
||
|
||
it("does not present a closed preview as an empty published card", () => {
|
||
expect(
|
||
presentCandidatePreview({
|
||
state: "closed",
|
||
fields: [],
|
||
card: null,
|
||
evidence: null,
|
||
generated_at: "2026-10-06T12:00:00Z",
|
||
}),
|
||
).toBeNull();
|
||
});
|
||
});
|
||
|
||
describe("editable card fields", () => {
|
||
it("exposes only safe groups supported by the anonymous-card contract", () => {
|
||
const stored: CardField[] = [
|
||
"categories",
|
||
"soft_skills",
|
||
"location",
|
||
"relocation",
|
||
"work_formats",
|
||
];
|
||
|
||
expect(publishableCardFields).toEqual([
|
||
"categories",
|
||
"self_assessment",
|
||
"stack",
|
||
"experience",
|
||
"work_formats",
|
||
"salary_compatibility",
|
||
]);
|
||
expect(editableCardFields(stored)).toEqual(["categories", "work_formats"]);
|
||
});
|
||
});
|
||
|
||
describe("publication closure explanation", () => {
|
||
it("explains a revoked C2 as closed future reads and a new C4 for a former company", () => {
|
||
const notice = describePublicationClosure({
|
||
state: "closed",
|
||
closed_reason: "consent_revoked",
|
||
});
|
||
const text = [notice?.title, ...(notice?.points ?? [])].join(" ");
|
||
|
||
expect(text).toContain("Будущие чтения карточки компаниями закрыты");
|
||
expect(text).toContain("Новое согласие C2 не откроет карточку само");
|
||
expect(text).toContain("новое приглашение и новое согласие C4");
|
||
});
|
||
|
||
it("explains a closing by the candidate and says nothing about a published or new card", () => {
|
||
expect(
|
||
describePublicationClosure({
|
||
state: "closed",
|
||
closed_reason: "closed_by_candidate",
|
||
})?.points.join(" "),
|
||
).toContain("не восстанавливает прежний доступ к контактам");
|
||
expect(describePublicationClosure({ state: "published", closed_reason: null })).toBeNull();
|
||
expect(
|
||
describePublicationClosure({ state: "closed", closed_reason: "never_published" }),
|
||
).toBeNull();
|
||
});
|
||
|
||
it("never promises that an unhide or a republish restores a contact grant", () => {
|
||
expect(contactAccessAfterVisibilityChange).toContain("не восстанавливают прежний доступ");
|
||
expect(contactAccessAfterVisibilityChange).toContain("новое согласие C4");
|
||
});
|
||
});
|
||
|
||
describe("card access organization", () => {
|
||
it("does not invent a name for an organization the server cannot present", () => {
|
||
expect(describeAccessOrganization(null)).toBe("Организация не раскрывается");
|
||
expect(describeAccessOrganization({ name: "Компания А" })).toBe("Компания А");
|
||
});
|
||
});
|