Skip to content

Commit 70bbdee

Browse files
add testcase
1 parent 50fc5b6 commit 70bbdee

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/RefreshOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface RefreshOptions {
2424
* Any modifications to watched settings will refresh all settings loaded by the configuration provider when refresh() is called.
2525
*
2626
* @remarks
27-
* If no watched settings is specified, all configuration settings will be watched.
27+
* If no watched setting is specified, all configuration settings will be watched.
2828
*/
2929
watchedSettings?: WatchedSetting[];
3030
}

test/refresh.test.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,62 @@ describe("dynamic refresh", function () {
302302
expect(settings.get("app.settings.fontColor")).eq("red");
303303
});
304304

305+
it("should refresh key value based on page eTag, if no watched setting is specified", async () => {
306+
const connectionString = createMockedConnectionString();
307+
const settings = await load(connectionString, {
308+
refreshOptions: {
309+
enabled: true,
310+
refreshIntervalInMs: 2000
311+
}
312+
});
313+
expect(settings).not.undefined;
314+
expect(settings.get("app.settings.fontColor")).eq("red");
315+
expect(settings.get("app.settings.fontSize")).eq("40");
316+
317+
// change setting
318+
updateSetting("app.settings.fontColor", "blue");
319+
320+
// after refreshInterval, should really refresh
321+
await sleepInMs(2 * 1000 + 1);
322+
await settings.refresh();
323+
expect(settings.get("app.settings.fontColor")).eq("blue");
324+
});
325+
326+
it("should refresh key value based on page Etag, only on change", async () => {
327+
const connectionString = createMockedConnectionString();
328+
const settings = await load(connectionString, {
329+
refreshOptions: {
330+
enabled: true,
331+
refreshIntervalInMs: 2000
332+
}
333+
});
334+
335+
let refreshSuccessfulCount = 0;
336+
settings.onRefresh(() => {
337+
refreshSuccessfulCount++;
338+
});
339+
340+
expect(settings).not.undefined;
341+
expect(settings.get("app.settings.fontColor")).eq("red");
342+
343+
await sleepInMs(2 * 1000 + 1);
344+
await settings.refresh();
345+
expect(refreshSuccessfulCount).eq(0); // no change in feature flags, because page etags are the same.
346+
347+
// change key value
348+
restoreMocks();
349+
let changedKVs = [
350+
{ value: "blue", key: "app.settings.fontColor" },
351+
{ value: "40", key: "app.settings.fontSize" }
352+
].map(createMockedKeyValue);
353+
mockAppConfigurationClientListConfigurationSettings(changedKVs);
354+
mockAppConfigurationClientGetConfigurationSetting(changedKVs);
355+
356+
await sleepInMs(2 * 1000 + 1);
357+
await settings.refresh();
358+
expect(refreshSuccessfulCount).eq(1); // change in key values, because page etags are different.
359+
expect(settings.get("app.settings.fontColor")).eq("blue");
360+
});
305361
});
306362

307363
describe("dynamic refresh feature flags", function () {
@@ -358,7 +414,7 @@ describe("dynamic refresh feature flags", function () {
358414

359415
});
360416

361-
it("should refresh feature flags only on change, based on page etags", async () => {
417+
it("should refresh feature flags based on page etags, only on change", async () => {
362418
// mock multiple pages of feature flags
363419
const page1 = [
364420
createMockedFeatureFlag("Alpha_1", { enabled: true }),

0 commit comments

Comments
 (0)