import { RawPayloadEncryptionService } from "../src/common/raw-payload-encryption.service"; describe("RawPayloadEncryptionService", () => { it("stores raw transaction payloads as encrypted envelopes", () => { const encryption = { encrypt: jest.fn((value: string) => `cipher:${Buffer.from(value).toString("base64")}`), decrypt: jest.fn((value: string) => Buffer.from(value.replace("cipher:", ""), "base64").toString("utf8")), }; const service = new RawPayloadEncryptionService(encryption as never); const encrypted = service.encrypt({ transaction_id: "tx_1", merchant: "Coffee" }) as { encrypted: boolean; version: number; ciphertext: string; transaction_id?: string; }; expect(encrypted).toEqual({ encrypted: true, version: 1, ciphertext: expect.stringMatching(/^cipher:/), }); expect(encrypted).not.toHaveProperty("transaction_id"); expect(service.decrypt(encrypted)).toEqual({ transaction_id: "tx_1", merchant: "Coffee" }); }); });