Skip to content

Commit 6522085

Browse files
committed
Update mocked func for app-configuration v1.5.0
1 parent d3a6279 commit 6522085

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;
@@ -79,36 +88,33 @@ const createMockedTokenCredential = (tenantId = TEST_TENANT_ID, clientId = TEST_
7988
return new ClientSecretCredential(tenantId, clientId, clientSecret);
8089
}
8190

82-
const createMockedKeyVaultReference = (key: string, vaultUri: string) => ({
91+
const createMockedKeyVaultReference = (key: string, vaultUri: string): ConfigurationSetting => ({
8392
// https://${vaultName}.vault.azure.net/secrets/${secretName}
8493
value: `{"uri":"${vaultUri}"}`,
8594
key,
86-
label: null,
8795
contentType: "application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8",
88-
lastModified: "2023-05-09T08:51:11.000Z",
96+
lastModified: new Date(),
8997
tags: {
9098
},
9199
etag: "SPJSMnJ2ph4BAjftWfdIctV2VIyQxtcIzRbh1oxTBkM",
92100
isReadOnly: false,
93101
});
94102

95-
const createMockedJsonKeyValue = (key: string, value: any) => ({
103+
const createMockedJsonKeyValue = (key: string, value: any): ConfigurationSetting => ({
96104
value: value,
97105
key: key,
98-
label: null,
99106
contentType: "application/json",
100-
lastModified: "2023-05-04T04:32:56.000Z",
107+
lastModified: new Date(),
101108
tags: {},
102109
etag: "GdmsLWq3mFjFodVEXUYRmvFr3l_qRiKAW_KdpFbxZKk",
103110
isReadOnly: false
104111
});
105112

106-
const createMockedKeyValue = (props: {[key: string]: any}) => (Object.assign({
113+
const createMockedKeyValue = (props: {[key: string]: any}): ConfigurationSetting => (Object.assign({
107114
value: "TestValue",
108115
key: "TestKey",
109-
label: null,
110116
contentType: "",
111-
lastModified: new Date().toISOString(),
117+
lastModified: new Date(),
112118
tags: {},
113119
etag: uuid.v4(),
114120
isReadOnly: false

0 commit comments

Comments
 (0)