Skip to content

Commit 4ac2092

Browse files
committed
test for override
1 parent 9f249b8 commit 4ac2092

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,45 @@ exports[`local integration test init init config works for runtime file auto sim
175175
},
176176
}
177177
`;
178+
179+
exports[`local integration test init init config works for runtime file auto simultaneously with overrides 1`] = `
180+
{
181+
"test/feature_a": {
182+
"config": {
183+
"SOURCE": "RUNTIME",
184+
"TYPE": "string",
185+
},
186+
"fallbackValue": "fallbackRuntimeA",
187+
},
188+
"test/feature_b": {
189+
"config": {
190+
"SOURCE": "RUNTIME",
191+
"TYPE": "string",
192+
},
193+
"fallbackValue": "fallbackRuntimeB",
194+
},
195+
"test/feature_c": {
196+
"config": {
197+
"SOURCE": "FILE",
198+
"SOURCE_FILEPATH": "toggles-2.json",
199+
"TYPE": "string",
200+
},
201+
"fallbackValue": "C-from-File2",
202+
},
203+
"test/feature_d": {
204+
"config": {
205+
"SOURCE": "FILE",
206+
"SOURCE_FILEPATH": "toggles-1.json",
207+
"TYPE": "string",
208+
},
209+
"fallbackValue": "fallbackFileD",
210+
},
211+
"test/feature_e": {
212+
"config": {
213+
"SOURCE": "AUTO",
214+
"TYPE": "string",
215+
},
216+
"fallbackValue": "fallbackAutoE",
217+
},
218+
}
219+
`;

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,46 @@ describe("local integration test", () => {
257257
]
258258
`);
259259
});
260+
261+
test("init config works for runtime file auto simultaneously with overrides", async () => {
262+
const localConfigForAuto = {
263+
...configForAuto, // E
264+
[FEATURE.A]: { type: "string", fallbackValue: "A-from-Auto" },
265+
[FEATURE.C]: { type: "string", fallbackValue: "C-from-Auto" },
266+
[FEATURE.D]: { type: "string", fallbackValue: "D-from-Auto" },
267+
};
268+
const localConfigForFile1 = {
269+
...configForFile, // C, D
270+
[FEATURE.A]: { type: "string", fallbackValue: "A-from-File1" },
271+
[FEATURE.C]: { type: "string", fallbackValue: "C-from-File1" },
272+
};
273+
const localConfigForFile2 = {
274+
[FEATURE.A]: { type: "string", fallbackValue: "A-from-File2" },
275+
[FEATURE.C]: { type: "string", fallbackValue: "C-from-File2" },
276+
};
277+
const localConfigForRuntime = {
278+
...configForRuntime, // A, B
279+
};
280+
281+
mockReadFile.mockImplementationOnce((path, cb) => cb(null, Buffer.from(JSON.stringify(localConfigForFile1))));
282+
mockReadFile.mockImplementationOnce((path, cb) => cb(null, Buffer.from(JSON.stringify(localConfigForFile2))));
283+
284+
await expect(
285+
toggles.initializeFeatures({
286+
configAuto: localConfigForAuto,
287+
configFiles: ["toggles-1.json", "toggles-2.json"],
288+
config: localConfigForRuntime,
289+
})
290+
).resolves.toBeDefined();
291+
expect(toggles.getFeaturesInfos()).toMatchSnapshot();
292+
293+
expect(featureTogglesLoggerSpy.info).toHaveBeenCalledTimes(1);
294+
expect(featureTogglesLoggerSpy.info.mock.calls[0]).toMatchInlineSnapshot(`
295+
[
296+
"finished initialization of "unicorn" with 11 feature toggles (4 auto, 5 file, 2 runtime) using NO_REDIS",
297+
]
298+
`);
299+
});
260300
});
261301

262302
describe("validations", () => {

0 commit comments

Comments
 (0)