Files
brain/tools/judge-card-guard.test.mjs
T

43 lines
1.7 KiB
JavaScript

// tools/judge-card-guard.test.mjs
import { describe, it, expect } from 'vitest';
import { cardHash, guardCard, guardCards } from './judge-card-guard.mjs';
const CARD = { skill: 'frontend-design', needs: ['mobile'] };
describe('guardCard (§11 #5 — страж карточки)', () => {
it('своя карточка есть, хеш не требуется → ок', () => {
expect(guardCard(CARD, {})).toEqual({ ok: true, blind: false });
});
it('карточки нет → сужу вслепую', () => {
const r = guardCard(null, {});
expect(r.ok).toBe(false);
expect(r.blind).toBe(true);
expect(r.reason).toMatch(/отсутств|вслепую/i);
});
it('чужая карточка, хеш сошёлся → ок', () => {
const h = cardHash(CARD);
expect(guardCard(CARD, { expectedHash: h }).ok).toBe(true);
});
it('чужая карточка, хеш НЕ сошёлся → сужу вслепую', () => {
const r = guardCard(CARD, { expectedHash: 'deadbeef' });
expect(r.ok).toBe(false);
expect(r.blind).toBe(true);
expect(r.reason).toMatch(/хеш|вслепую/i);
});
});
describe('guardCards (агрегат)', () => {
it('собирает список карточек, по которым судим вслепую', () => {
const r = guardCards(
[{ skill: 'a' }, null, { skill: 'c' }],
{ expectedHashes: { c: 'wrong' } },
);
expect(r.ok).toBe(false);
// null-карточка (индекс 1) + 'c' с неверным хешем
expect(r.blindOn.length).toBe(2);
});
it('все карточки целы → ок', () => {
expect(guardCards([{ skill: 'a' }, { skill: 'b' }], {}).ok).toBe(true);
});
});