Skip to content

Commit 8d4187d

Browse files
authored
Update mocked func for app-configuration v1.5.0 (#28)
1 parent aded5bb commit 8d4187d

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

test/utils/testHelper.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license.
33

44
import * as sinon from "sinon";
5-
import { AppConfigurationClient } from "@azure/app-configuration";
5+
import { AppConfigurationClient, ConfigurationSetting } from "@azure/app-configuration";
66
import { ClientSecretCredential } from "@azure/identity";
77
import { KeyVaultSecret, SecretClient } from "@azure/keyvault-secrets";
88
import * as uuid from "uuid";
@@ -11,17 +11,26 @@ const TEST_CLIENT_ID = "00000000-0000-0000-0000-000000000000";
1111
const TEST_TENANT_ID = "00000000-0000-0000-0000-000000000000";
1212
const TEST_CLIENT_SECRET = "0000000000000000000000000000000000000000";
1313

14-
function mockAppConfigurationClientListConfigurationSettings(kvList: any[]) {
14+
function mockAppConfigurationClientListConfigurationSettings(kvList: ConfigurationSetting[]) {
1515
function* testKvSetGnerator(kvs: any[]) {
1616
yield* kvs;
1717
}
1818
sinon.stub(AppConfigurationClient.prototype, "listConfigurationSettings").callsFake((listOptions) => {
1919
const keyFilter = listOptions?.keyFilter ?? "*";
2020
const labelFilter = listOptions?.labelFilter ?? "*";
2121
const kvs = kvList.filter(kv => {
22-
const keyMatched = keyFilter.endsWith("*") ? kv.key.startsWith(keyFilter.slice(0, keyFilter.length - 1)) : kv.key === keyFilter;
23-
const labelMatched = labelFilter.endsWith("*") ? kv.label.startsWith(labelFilter.slice(0, labelFilter.length - 1))
24-
: (labelFilter === "\0" ? kv.label === null : kv.label === labelFilter); // '\0' in labelFilter, null in config setting.
22+
const keyMatched = keyFilter.endsWith("*") ? kv.key.startsWith(keyFilter.slice(0, -1)) : kv.key === keyFilter;
23+
24+
let labelMatched = false;
25+
if (labelFilter === "*") {
26+
labelMatched = true;
27+
} else if (labelFilter === "\0") {
28+
labelMatched = kv.label === undefined;
29+
} else if (labelFilter.endsWith("*")) {
30+
labelMatched = kv.label !== undefined && kv.label.startsWith(labelFilter.slice(0, -1));
31+
} else {
32+
labelMatched = kv.label === labelFilter;
33+
}
2534
return keyMatched && labelMatched;
2635
})
2736
return testKvSetGnerator(kvs) as any;
@@ -64,36 +73,33 @@ const createMockedTokenCredential = (tenantId = TEST_TENANT_ID, clientId = TEST_
6473
return new ClientSecretCredential(tenantId, clientId, clientSecret);
6574
}
6675

67-
const createMockedKeyVaultReference = (key: string, vaultUri: string) => ({
76+
const createMockedKeyVaultReference = (key: string, vaultUri: string): ConfigurationSetting => ({
6877
// https://${vaultName}.vault.azure.net/secrets/${secretName}
6978
value: `{"uri":"${vaultUri}"}`,
7079
key,
71-
label: null,
7280
contentType: "application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8",
73-
lastModified: "2023-05-09T08:51:11.000Z",
81+
lastModified: new Date(),
7482
tags: {
7583
},
7684
etag: "SPJSMnJ2ph4BAjftWfdIctV2VIyQxtcIzRbh1oxTBkM",
7785
isReadOnly: false,
7886
});
7987

80-
const createMockedJsonKeyValue = (key: string, value: any) => ({
88+
const createMockedJsonKeyValue = (key: string, value: any): ConfigurationSetting => ({
8189
value: value,
8290
key: key,
83-
label: null,
8491
contentType: "application/json",
85-
lastModified: "2023-05-04T04:32:56.000Z",
92+
lastModified: new Date(),
8693
tags: {},
8794
etag: "GdmsLWq3mFjFodVEXUYRmvFr3l_qRiKAW_KdpFbxZKk",
8895
isReadOnly: false
8996
});
9097

91-
const createMockedKeyValue = (props: {[key: string]: any}) => (Object.assign({
98+
const createMockedKeyValue = (props: {[key: string]: any}): ConfigurationSetting => (Object.assign({
9299
value: "TestValue",
93100
key: "TestKey",
94-
label: null,
95101
contentType: "",
96-
lastModified: new Date().toISOString(),
102+
lastModified: new Date(),
97103
tags: {},
98104
etag: uuid.v4(),
99105
isReadOnly: false

0 commit comments

Comments
 (0)