Skip to content

Commit d9a491e

Browse files
committed
test for validation configuration override behavior
1 parent 8823177 commit d9a491e

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,74 @@ describe("local integration test", () => {
219219
`);
220220
});
221221

222+
test("init config overrides can change validation", async () => {
223+
const checkKey = FEATURE.A;
224+
const configForFileValidationA = {
225+
[FEATURE.A]: { type: "string", fallbackValue: "A-from-A", validations: [{ regex: "^A-" }, { regex: "-A$" }] },
226+
};
227+
const configForFileValidationB = {
228+
[FEATURE.A]: { type: "string", fallbackValue: "A-from-B", validations: [{ regex: "^A-" }, { regex: "-B$" }] },
229+
};
230+
mockReadFile.mockImplementationOnce((path, cb) =>
231+
cb(null, Buffer.from(JSON.stringify(configForFileValidationA)))
232+
);
233+
mockReadFile.mockImplementationOnce((path, cb) =>
234+
cb(null, Buffer.from(JSON.stringify(configForFileValidationB)))
235+
);
236+
237+
await expect(
238+
toggles.initializeFeatures({ configFiles: ["toggles-1.json", "toggles-2.json"] })
239+
).resolves.toBeDefined();
240+
expect(toggles.getFeatureInfo(checkKey)).toMatchInlineSnapshot(`
241+
{
242+
"config": {
243+
"SOURCE": "FILE",
244+
"SOURCE_FILEPATH": "toggles-2.json",
245+
"TYPE": "string",
246+
"VALIDATIONS": [
247+
{
248+
"regex": "^A-",
249+
},
250+
{
251+
"regex": "-B$",
252+
},
253+
],
254+
},
255+
"fallbackValue": "A-from-B",
256+
}
257+
`);
258+
});
259+
260+
test("init config overrides can remove validation", async () => {
261+
const checkKey = FEATURE.A;
262+
const configForFileValidationA = {
263+
[FEATURE.A]: { type: "string", fallbackValue: "A-from-A", validations: [{ regex: "^A-" }, { regex: "-A$" }] },
264+
};
265+
const configForFileValidationB = {
266+
[FEATURE.A]: { type: "string", fallbackValue: "A-from-B" },
267+
};
268+
mockReadFile.mockImplementationOnce((path, cb) =>
269+
cb(null, Buffer.from(JSON.stringify(configForFileValidationA)))
270+
);
271+
mockReadFile.mockImplementationOnce((path, cb) =>
272+
cb(null, Buffer.from(JSON.stringify(configForFileValidationB)))
273+
);
274+
275+
await expect(
276+
toggles.initializeFeatures({ configFiles: ["toggles-1.json", "toggles-2.json"] })
277+
).resolves.toBeDefined();
278+
expect(toggles.getFeatureInfo(checkKey)).toMatchInlineSnapshot(`
279+
{
280+
"config": {
281+
"SOURCE": "FILE",
282+
"SOURCE_FILEPATH": "toggles-2.json",
283+
"TYPE": "string",
284+
},
285+
"fallbackValue": "A-from-B",
286+
}
287+
`);
288+
});
289+
222290
test("init config conflict between auto and file overrides in favor of file", async () => {
223291
const firstEntry = Object.entries(configForFile)[0];
224292
const configForConflict = Object.fromEntries(

0 commit comments

Comments
 (0)