feat(privacy): complete the publication, hiding and preview settings screen

This commit is contained in:
shira committed 2026-10-09 12:47:26 +03:00
1 parent c2a8d17195
commit 5edff21d2d
28 files changed
+2230 -428

No files matched your search

@@ -1,6 +1,13 @@
import { describe, expect, it } from "vitest";
import type { CardField, CardPreview } from "../../../shared/api/schemas";
import { editableCardFields, presentCandidatePreview, publishableCardFields } from "./presentation";
import {
contactAccessAfterVisibilityChange,
describeAccessOrganization,
describePublicationClosure,
editableCardFields,
presentCandidatePreview,
publishableCardFields,
} from "./presentation";
function preview(card: NonNullable<CardPreview["card"]>): CardPreview {
return {
@@ -43,11 +50,99 @@ describe("candidate card presentation", () => {
{
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" }],
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" }],
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({
@@ -82,3 +177,42 @@ describe("editable card fields", () => {
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("Компания А");
});
});