@@ -169,6 +169,73 @@ describe("AppSettings", () => {
169169 } ) ;
170170 } ) ;
171171
172+ describe ( "set" , ( ) => {
173+ beforeEach ( ( ) => {
174+ jest . spyOn ( JSONSettingsFilePersistence . prototype , "read" ) . mockReturnValueOnce ( {
175+ overrides : {
176+ CredentialManager : "@zowe/cli"
177+ }
178+ } ) ;
179+ AppSettings . initialize ( "file" , defaultSettings ) ;
180+ } ) ;
181+
182+ it ( "sets a property in credentialManagerOptions with the given key/value pair" , ( ) => {
183+ expect ( ( ) => AppSettings . instance . set ( "credentialManagerOptions" , "persist" , PersistenceLevel . LocalMachine ) ) . not . toThrow ( ) ;
184+ } ) ;
185+
186+ it ( "throws an error if the given namespace does not exist" , ( ) => {
187+ expect ( ( ) => AppSettings . instance . set ( "nonexistent" as any , "blah" , 123 ) ) . toThrow ( "Namespace nonexistent does not exist" ) ;
188+ } ) ;
189+ } ) ;
190+
191+ describe ( "get" , ( ) => {
192+ beforeEach ( ( ) => {
193+ jest . spyOn ( JSONSettingsFilePersistence . prototype , "read" ) . mockReturnValueOnce ( {
194+ overrides : {
195+ CredentialManager : false ,
196+ } ,
197+ credentialManagerOptions : { }
198+ } ) ;
199+ AppSettings . initialize ( "file" , defaultSettings ) ;
200+ } ) ;
201+
202+ it ( "throws an error if the given namespace does not exist" , ( ) => {
203+ expect ( ( ) => AppSettings . instance . get ( "asdfghjkl" as any , "nonexistent_key" ) ) . toThrow ( "Namespace asdfghjkl does not exist" ) ;
204+ } ) ;
205+
206+ it ( "returns a property in credentialManagerOptions namespace when options are present" , ( ) => {
207+ AppSettings . instance . set ( "credentialManagerOptions" , "persist" , PersistenceLevel . LocalMachine ) ;
208+ expect ( AppSettings . instance . get ( "credentialManagerOptions" , "persist" ) ) . not . toBeUndefined ( ) ;
209+ expect ( AppSettings . instance . get ( "credentialManagerOptions" , "persist" ) ) . toStrictEqual ( PersistenceLevel . LocalMachine ) ;
210+ } ) ;
211+
212+ it ( "returns undefined for a credentialManagerOptions property when no options are present" , ( ) => {
213+ expect ( AppSettings . instance . get ( "credentialManagerOptions" , "persist" ) ) . toBeUndefined ( ) ;
214+ } ) ;
215+ } ) ;
216+
217+ describe ( "getNamespace" , ( ) => {
218+ beforeEach ( ( ) => {
219+ jest . spyOn ( JSONSettingsFilePersistence . prototype , "read" ) . mockReturnValueOnce ( {
220+ overrides : {
221+ CredentialManager : false
222+ }
223+ } ) ;
224+ AppSettings . initialize ( "file" , defaultSettings ) ;
225+ } ) ;
226+
227+ it ( "returns the object for overrides namespace" , ( ) => {
228+ expect ( AppSettings . instance . getNamespace ( "overrides" ) ) . not . toBeUndefined ( ) ;
229+ expect ( AppSettings . instance . getNamespace ( "overrides" ) ) . toStrictEqual ( defaultSettings . overrides ) ;
230+ } ) ;
231+
232+ it ( "returns the namespace for credentialManagerOptions when options are present" , ( ) => {
233+ AppSettings . instance . set ( "credentialManagerOptions" , "persist" , PersistenceLevel . LocalMachine ) ;
234+ expect ( AppSettings . instance . getNamespace ( "credentialManagerOptions" ) ) . not . toBeUndefined ( ) ;
235+ expect ( AppSettings . instance . getNamespace ( "credentialManagerOptions" ) ) . toStrictEqual ( { persist : PersistenceLevel . LocalMachine } ) ;
236+ } ) ;
237+ } ) ;
238+
172239 describe ( "writing settings" , ( ) => {
173240 /**
174241 * Takes an app settings object and mocks the {@link IAppSettingsAllMethods#writeSettingsFile} method
0 commit comments