Closer/functions/dist/couples/onCoupleKeyRotated.test.js

41 lines
2.6 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const onCoupleKeyRotated_1 = require("./onCoupleKeyRotated");
describe('isKeyGenerationIncrease', () => {
it('fires on a genuine rotation (0 → 1, and every later bump)', () => {
expect((0, onCoupleKeyRotated_1.isKeyGenerationIncrease)(undefined, 1)).toBe(true);
expect((0, onCoupleKeyRotated_1.isKeyGenerationIncrease)(0, 1)).toBe(true);
expect((0, onCoupleKeyRotated_1.isKeyGenerationIncrease)(3, 4)).toBe(true);
});
it('ignores every non-rotation update to the couple doc', () => {
// The trigger watches the whole couple doc — streaks, rhythm, recovery re-wraps all pass through here.
expect((0, onCoupleKeyRotated_1.isKeyGenerationIncrease)(undefined, undefined)).toBe(false);
expect((0, onCoupleKeyRotated_1.isKeyGenerationIncrease)(2, 2)).toBe(false);
expect((0, onCoupleKeyRotated_1.isKeyGenerationIncrease)(0, undefined)).toBe(false);
});
it('never fires on a downgrade — rules forbid it, but a redelivered stale event must not alert either', () => {
expect((0, onCoupleKeyRotated_1.isKeyGenerationIncrease)(5, 4)).toBe(false);
});
it('treats junk as zero rather than alerting on garbage', () => {
expect((0, onCoupleKeyRotated_1.isKeyGenerationIncrease)('x', 'y')).toBe(false);
expect((0, onCoupleKeyRotated_1.isKeyGenerationIncrease)(null, 'high')).toBe(false);
});
});
describe('isPhrasePublished', () => {
it('fires when a new recovery phrase is published (phase 1)', () => {
expect((0, onCoupleKeyRotated_1.isPhrasePublished)(undefined, 1)).toBe(true);
expect((0, onCoupleKeyRotated_1.isPhrasePublished)(0, 1)).toBe(true);
expect((0, onCoupleKeyRotated_1.isPhrasePublished)(2, 3)).toBe(true);
});
it('ignores the acks and the completion — only the publish needs the partner in the app', () => {
// Phase 2 (acks) and phase 3 (the re-wrap) leave phraseGeneration alone, so they must not alert:
// the partner is already acting, and re-alerting them would be noise on a security channel.
expect((0, onCoupleKeyRotated_1.isPhrasePublished)(1, 1)).toBe(false);
expect((0, onCoupleKeyRotated_1.isPhrasePublished)(undefined, undefined)).toBe(false);
});
it('never fires on a downgrade or a redelivered stale event', () => {
expect((0, onCoupleKeyRotated_1.isPhrasePublished)(5, 4)).toBe(false);
expect((0, onCoupleKeyRotated_1.isPhrasePublished)(1, undefined)).toBe(false);
});
});
//# sourceMappingURL=onCoupleKeyRotated.test.js.map