diff --git a/lib/decodeOpaqueId.test.js b/lib/decodeOpaqueId.test.js index 6112ca5..2d63ecb 100644 --- a/lib/decodeOpaqueId.test.js +++ b/lib/decodeOpaqueId.test.js @@ -1,5 +1,14 @@ +import { jest } from "@jest/globals"; +import config from "./config.js"; import decodeOpaqueId from "./decodeOpaqueId.js"; +jest.mock("./config.js", () => ({ + __esModule: true, // this property makes it work + default: { + REACTION_SHOULD_ENCODE_IDS: true, + }, +})); + test("decodes base64", () => { const encodedId = "cmVhY3Rpb24vc2hvcDpieTV3cGRnM25NcThnWDU0Yw=="; expect(decodeOpaqueId(encodedId)).toEqual({ @@ -15,3 +24,13 @@ test("passes through non-base64", () => { namespace: null }); }); + +test("skips decoding if REACTION_SHOULD_ENCODE_IDS env is false", async () => { + const id = "by5wpdg3nMq8gX54c"; + config.REACTION_SHOULD_ENCODE_IDS = false; + expect(decodeOpaqueId(id)).toEqual({ + id, + namespace: null + }); + config.REACTION_SHOULD_ENCODE_IDS = true; +});