@@ -210,46 +210,115 @@ describe('services', () => {
210
210
describe ( 'ConfigData.removeProfile' , ( ) => {
211
211
test . it ( 'remove a profile that does not exist' , ( ) => {
212
212
const configData = new ConfigData ( ) ;
213
- configData . addProfile ( 'firstProfile' , constants . FAKE_ACCOUNT_SID ) ;
214
- configData . addProfile ( 'secondProfile' , 'new_account_SID' ) ;
215
- configData . addProfile ( 'thirdProfile' , 'newest_account_SID' ) ;
213
+ configData . addProject ( 'firstProfile' , constants . FAKE_ACCOUNT_SID ) ;
214
+ configData . addProfile (
215
+ 'secondProfile' ,
216
+ 'new_account_SID' ,
217
+ '' ,
218
+ constants . FAKE_API_KEY ,
219
+ constants . FAKE_API_SECRET ,
220
+ ) ;
221
+ configData . addProfile (
222
+ 'thirdProfile' ,
223
+ 'newest_account_SID' ,
224
+ '' ,
225
+ constants . FAKE_API_KEY ,
226
+ constants . FAKE_API_SECRET ,
227
+ ) ;
216
228
const fakeProfile = {
217
229
id : 'DOES_NOT_EXIST' ,
218
230
accountSid : 'fake_SID' ,
219
231
} ;
220
232
const originalLength = configData . projects . length ;
233
+ const originalProfilesLength = Object . keys ( configData . profiles ) . length ;
221
234
configData . removeProfile ( fakeProfile ) ;
222
235
223
236
expect ( configData . projects . length ) . to . equal ( originalLength ) ;
237
+ expect ( Object . keys ( configData . profiles ) . length ) . to . equal ( originalProfilesLength ) ;
238
+ } ) ;
239
+
240
+ test . it ( 'removes profile from projects' , ( ) => {
241
+ const configData = new ConfigData ( ) ;
242
+ configData . addProject ( 'firstProfile' , constants . FAKE_ACCOUNT_SID ) ;
243
+ configData . addProject ( 'secondProfile' , 'new_account_SID' ) ;
244
+ configData . addProject ( 'thirdProfile' , 'newest_account_SID' ) ;
245
+ configData . addProfile (
246
+ 'fourthProfile' ,
247
+ 'fourth_account_SID' ,
248
+ '' ,
249
+ constants . FAKE_API_KEY ,
250
+ constants . FAKE_API_SECRET ,
251
+ ) ;
252
+ const profile = configData . getProfileById ( 'secondProfile' ) ;
253
+ const originalLengthProfiles = Object . keys ( configData . profiles ) . length ;
254
+ configData . removeProfile ( profile ) ;
255
+
256
+ expect ( configData . projects [ 1 ] . id ) . to . equal ( 'thirdProfile' ) ;
257
+ expect ( configData . projects [ 1 ] . accountSid ) . to . equal ( 'newest_account_SID' ) ;
258
+ expect ( Object . keys ( configData . profiles ) . length ) . to . equal ( originalLengthProfiles ) ;
259
+ } ) ;
260
+ test . it ( 'removes profile from profiles' , ( ) => {
261
+ const configData = new ConfigData ( ) ;
262
+ configData . addProject ( 'firstProfile' , constants . FAKE_ACCOUNT_SID ) ;
263
+ configData . addProject ( 'secondProfile' , 'new_account_SID' ) ;
264
+ configData . addProfile ( 'thirdProfile' , 'newest_account_SID' , '' , 'third_api_key' , 'third_api_secret' ) ;
265
+ configData . addProfile (
266
+ 'fourthProfile' ,
267
+ 'fourth_account_SID' ,
268
+ '' ,
269
+ constants . FAKE_API_KEY ,
270
+ constants . FAKE_API_SECRET ,
271
+ ) ;
272
+ const profile = configData . getProfileById ( 'thirdProfile' ) ;
273
+ const originalLengthProjects = configData . projects . length ;
274
+ configData . removeProfile ( profile ) ;
275
+
276
+ expect ( configData . projects . length ) . to . equal ( originalLengthProjects ) ;
277
+ expect ( configData . profiles [ profile . id ] ) . to . be . undefined ;
224
278
} ) ;
225
279
226
- /*
227
- * TODO: To be fixed with profiles:remove functionality
228
- * test.it('removes profile', () => {
229
- * const configData = new ConfigData();
230
- * configData.addProfile('firstProfile', constants.FAKE_ACCOUNT_SID);
231
- * configData.addProfile('secondProfile', 'new_account_SID');
232
- * configData.addProfile('thirdProfile', 'newest_account_SID');
233
- * const profile = configData.getProfileById('secondProfile');
234
- * configData.removeProfile(profile);
235
- *
236
- * expect(configData.projects[1].id).to.equal('thirdProfile');
237
- * expect(configData.projects[1].accountSid).to.equal('newest_account_SID');
238
- * });
239
- *
240
- * test.it('removes active profile', () => {
241
- * const configData = new ConfigData();
242
- * configData.addProfile('firstProfile', constants.FAKE_ACCOUNT_SID);
243
- * configData.addProfile('secondProfile', 'new_account_SID');
244
- * configData.addProfile('thirdProfile', 'newest_account_SID');
245
- * const profile = configData.setActiveProfile('firstProfile');
246
- * configData.removeProfile(profile);
247
- *
248
- * expect(configData.projects[1].id).to.equal('thirdProfile');
249
- * expect(configData.projects[1].accountSid).to.equal('newest_account_SID');
250
- * expect(configData.activeProfile).to.equal(null);
251
- * });
252
- */
280
+ test . it ( 'removes active profile of projects' , ( ) => {
281
+ const configData = new ConfigData ( ) ;
282
+ configData . addProject ( 'firstProfile' , constants . FAKE_ACCOUNT_SID ) ;
283
+ configData . addProject ( 'secondProfile' , 'new_account_SID' ) ;
284
+ configData . addProject ( 'thirdProfile' , 'newest_account_SID' ) ;
285
+ configData . addProfile (
286
+ 'fourthProfile' ,
287
+ 'fourth_account_SID' ,
288
+ '' ,
289
+ constants . FAKE_API_KEY ,
290
+ constants . FAKE_API_SECRET ,
291
+ ) ;
292
+ const profile = configData . setActiveProfile ( 'firstProfile' ) ;
293
+ const originalLengthProfiles = Object . keys ( configData . profiles ) . length ;
294
+ configData . removeProfile ( profile ) ;
295
+
296
+ expect ( configData . projects [ 1 ] . id ) . to . equal ( 'thirdProfile' ) ;
297
+ expect ( configData . projects [ 1 ] . accountSid ) . to . equal ( 'newest_account_SID' ) ;
298
+ expect ( configData . activeProfile ) . to . equal ( null ) ;
299
+ expect ( Object . keys ( configData . profiles ) . length ) . to . equal ( originalLengthProfiles ) ;
300
+ } ) ;
301
+
302
+ test . it ( 'removes active profile of profiles' , ( ) => {
303
+ const configData = new ConfigData ( ) ;
304
+ configData . addProject ( 'firstProfile' , constants . FAKE_ACCOUNT_SID ) ;
305
+ configData . addProject ( 'secondProfile' , 'new_account_SID' ) ;
306
+ configData . addProfile ( 'thirdProfile' , 'newest_account_SID' , '' , 'third_api_key' , 'third_api_secret' ) ;
307
+ configData . addProfile (
308
+ 'fourthProfile' ,
309
+ 'fourth_account_SID' ,
310
+ '' ,
311
+ constants . FAKE_API_KEY ,
312
+ constants . FAKE_API_SECRET ,
313
+ ) ;
314
+ const profile = configData . setActiveProfile ( 'thirdProfile' ) ;
315
+ const originalLengthProjects = configData . projects . length ;
316
+ configData . removeProfile ( profile ) ;
317
+
318
+ expect ( configData . projects . length ) . to . equal ( originalLengthProjects ) ;
319
+ expect ( configData . profiles [ profile . id ] ) . to . be . undefined ;
320
+ expect ( configData . activeProfile ) . to . equal ( null ) ;
321
+ } ) ;
253
322
} ) ;
254
323
describe ( 'ConfigData.prompts' , ( ) => {
255
324
test . it ( 'should store prompt acks' , ( ) => {
0 commit comments