diff --git a/src/AzureAppConfigurationImpl.ts b/src/AzureAppConfigurationImpl.ts index 7bc6d86..5791695 100644 --- a/src/AzureAppConfigurationImpl.ts +++ b/src/AzureAppConfigurationImpl.ts @@ -100,10 +100,12 @@ export class AzureAppConfigurationImpl extends Map implements Azure const keyValuePair = await this.processKeyValues(setting); keyValues.push(keyValuePair); } - // update etag of sentinels - const matchedSentinel = this._sentinels?.find(s => s.key === setting.key && (s.label ?? null) === setting.label); // Workaround: as undefined label represents the same with null. - if (matchedSentinel) { - matchedSentinel.etag = setting.etag; + // update etag of sentinels if refresh is enabled + if (this._refreshEnabled) { + const matchedSentinel = this._sentinels.find(s => s.key === setting.key && s.label === setting.label); + if (matchedSentinel) { + matchedSentinel.etag = setting.etag; + } } } } diff --git a/test/utils/testHelper.ts b/test/utils/testHelper.ts index db20938..69d09fb 100644 --- a/test/utils/testHelper.ts +++ b/test/utils/testHelper.ts @@ -6,6 +6,7 @@ import { AppConfigurationClient, ConfigurationSetting } from "@azure/app-configu import { ClientSecretCredential } from "@azure/identity"; import { KeyVaultSecret, SecretClient } from "@azure/keyvault-secrets"; import * as uuid from "uuid"; +import { RestError } from "@azure/core-rest-pipeline"; const TEST_CLIENT_ID = "00000000-0000-0000-0000-000000000000"; const TEST_TENANT_ID = "00000000-0000-0000-0000-000000000000"; @@ -39,15 +40,15 @@ function mockAppConfigurationClientListConfigurationSettings(kvList: Configurati function mockAppConfigurationClientGetConfigurationSetting(kvList) { sinon.stub(AppConfigurationClient.prototype, "getConfigurationSetting").callsFake((settingId, options) => { - const key = settingId.key; - const label = settingId.label ?? null; - const found = kvList.find(elem => elem.key === key && elem.label === label); + const found = kvList.find(elem => elem.key === settingId.key && elem.label === settingId.label); if (found) { if (options?.onlyIfChanged && settingId.etag === found.etag) { return { statusCode: 304 }; } else { return { statusCode: 200, ...found }; } + } else { + throw new RestError("", { statusCode: 404 }); } }); }