22// Licensed under the MIT license.
33
44import * as sinon from "sinon" ;
5- import { AppConfigurationClient , AppConfigurationClientOptions , ConfigurationSetting } from "@azure/app-configuration" ;
5+ import { AppConfigurationClient , ConfigurationSetting } from "@azure/app-configuration" ;
66import { ClientSecretCredential } from "@azure/identity" ;
77import { KeyVaultSecret , SecretClient } from "@azure/keyvault-secrets" ;
88import * as uuid from "uuid" ;
@@ -100,22 +100,28 @@ function mockAppConfigurationClientListConfigurationSettings(...pages: Configura
100100 } ) ;
101101}
102102
103- function mockConfigurationManagerGetClients ( isFailoverable : boolean , clientOptions ?: AppConfigurationClientOptions ) {
103+ function mockConfigurationManagerGetClients ( isFailoverable : boolean , ... pages : ConfigurationSetting [ ] [ ] ) {
104104 // Stub the getClients method on the class prototype
105105 sinon . stub ( ConfigurationClientManager . prototype , "getClients" ) . callsFake ( async ( ) => {
106106 const clients : ConfigurationClientWrapper [ ] = [ ] ;
107107 const fakeEndpoint = createMockedEndpoint ( "fake" ) ;
108- const fakeStaticClientWrapper = new ConfigurationClientWrapper ( fakeEndpoint , new AppConfigurationClient ( createMockedConnectionString ( fakeEndpoint ) , clientOptions ) ) ;
108+ const fakeStaticClientWrapper = new ConfigurationClientWrapper ( fakeEndpoint , new AppConfigurationClient ( createMockedConnectionString ( fakeEndpoint ) ) ) ;
109+ sinon . stub ( fakeStaticClientWrapper . client , "listConfigurationSettings" ) . callsFake ( ( ) => {
110+ throw new RestError ( "Internal Server Error" , { statusCode : 500 } ) ;
111+ } ) ;
109112 clients . push ( fakeStaticClientWrapper ) ;
110113
111114 if ( ! isFailoverable ) {
112115 return clients ;
113116 }
114117
115118 const fakeReplicaEndpoint = createMockedEndpoint ( "fake-replica" ) ;
116- const fakeDynamicClientWrapper = new ConfigurationClientWrapper ( fakeReplicaEndpoint , new AppConfigurationClient ( createMockedConnectionString ( fakeReplicaEndpoint ) , clientOptions ) ) ;
119+ const fakeDynamicClientWrapper = new ConfigurationClientWrapper ( fakeReplicaEndpoint , new AppConfigurationClient ( createMockedConnectionString ( fakeReplicaEndpoint ) ) ) ;
117120 clients . push ( fakeDynamicClientWrapper ) ;
118-
121+ sinon . stub ( fakeDynamicClientWrapper . client , "listConfigurationSettings" ) . callsFake ( ( listOptions ) => {
122+ const kvs = _filterKVs ( pages . flat ( ) , listOptions ) ;
123+ return getMockedIterator ( pages , kvs , listOptions ) ;
124+ } ) ;
119125 return clients ;
120126 } ) ;
121127}
@@ -135,17 +141,6 @@ function mockAppConfigurationClientGetConfigurationSetting(kvList) {
135141 } ) ;
136142}
137143
138- function mockAppConfigurationClientListConfigurationSettingsWithFailure ( ...pages : ConfigurationSetting [ ] [ ] ) {
139- const stub = sinon . stub ( AppConfigurationClient . prototype , "listConfigurationSettings" ) ;
140-
141- // Configure the stub to throw an error on the first call and return mockedKVs on the second call
142- stub . onFirstCall ( ) . throws ( new RestError ( "Internal Server Error" , { statusCode : 500 } ) ) ;
143- stub . callsFake ( ( listOptions ) => {
144- const kvs = _filterKVs ( pages . flat ( ) , listOptions ) ;
145- return getMockedIterator ( pages , kvs , listOptions ) ;
146- } ) ;
147- }
148-
149144// uriValueList: [["<secretUri>", "value"], ...]
150145function mockSecretClientGetSecret ( uriValueList : [ string , string ] [ ] ) {
151146 const dict = new Map ( ) ;
@@ -235,7 +230,6 @@ export {
235230 sinon ,
236231 mockAppConfigurationClientListConfigurationSettings ,
237232 mockAppConfigurationClientGetConfigurationSetting ,
238- mockAppConfigurationClientListConfigurationSettingsWithFailure ,
239233 mockConfigurationManagerGetClients ,
240234 mockSecretClientGetSecret ,
241235 restoreMocks ,
0 commit comments