Skip to content

Commit 618f4d6

Browse files
committed
one more test for the road
1 parent 4867a0d commit 618f4d6

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

test/integration-local/feature-toggles.integration.test.js

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ describe("local integration test", () => {
155155
]
156156
`);
157157
});
158-
159-
// TODO test for custom validation code from two config files with CONFIG_DIR!
160158
});
161159

162160
describe("validations", () => {
@@ -273,6 +271,59 @@ describe("local integration test", () => {
273271
expect(mockValidator).toHaveBeenCalledTimes(1);
274272
expect(mockValidator).toHaveBeenCalledWith("fallback", undefined, undefined);
275273
});
274+
275+
test("custom module validations with call from CONFIG_DIR from two config filepath", async () => {
276+
jest.mock("./1/virtual-validator-with-call", () => ({ validator: jest.fn() }), { virtual: true });
277+
jest.mock("./2/virtual-validator-with-call", () => ({ validator: jest.fn() }), { virtual: true });
278+
const { validator: mockValidator1 } = require("./1/virtual-validator-with-call");
279+
const { validator: mockValidator2 } = require("./2/virtual-validator-with-call");
280+
281+
const configForFile1 = {
282+
[FEATURE.A]: {
283+
fallbackValue: "fallback1",
284+
type: "string",
285+
validations: [{ module: "$CONFIG_DIR/virtual-validator-with-call", call: "validator" }],
286+
},
287+
};
288+
const configForFile2 = {
289+
[FEATURE.B]: {
290+
fallbackValue: "fallback2",
291+
type: "string",
292+
validations: [{ module: "$CONFIG_DIR/virtual-validator-with-call", call: "validator" }],
293+
},
294+
};
295+
mockReadFile.mockImplementationOnce((filepath, callback) =>
296+
callback(null, Buffer.from(JSON.stringify(configForFile1)))
297+
);
298+
mockReadFile.mockImplementationOnce((filepath, callback) =>
299+
callback(null, Buffer.from(JSON.stringify(configForFile2)))
300+
);
301+
302+
await toggles.initializeFeatures({
303+
configFiles: [
304+
"./test/integration-local/1/virtual-config.json",
305+
"./test/integration-local/2/virtual-config.json",
306+
],
307+
});
308+
309+
expect(mockReadFile).toHaveBeenCalledTimes(2);
310+
expect(mockReadFile.mock.calls).toMatchInlineSnapshot(`
311+
[
312+
[
313+
"./test/integration-local/1/virtual-config.json",
314+
[Function],
315+
],
316+
[
317+
"./test/integration-local/2/virtual-config.json",
318+
[Function],
319+
],
320+
]
321+
`);
322+
expect(mockValidator1).toHaveBeenCalledTimes(1);
323+
expect(mockValidator1).toHaveBeenCalledWith("fallback1", undefined, undefined);
324+
expect(mockValidator2).toHaveBeenCalledTimes(1);
325+
expect(mockValidator1).toHaveBeenCalledWith("fallback2", undefined, undefined);
326+
});
276327
});
277328

278329
describe("common config init", () => {

0 commit comments

Comments
 (0)