Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
test: added unit test for decodeOpaqueId
Browse files Browse the repository at this point in the history
  • Loading branch information
hrhosni committed Feb 24, 2021
1 parent 929423e commit 043d1e9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/decodeOpaqueId.test.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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;
});

0 comments on commit 043d1e9

Please sign in to comment.