Skip to content

Commit e326a31

Browse files
chore: CLI Profile Remove - Check and Use config file before checking system keychain. (twilio#126)
* chore: CLI Profile Remove - Check and Use config file before checking system keychain * Remves the check removeProfile while updating the project.
1 parent 9fb9dd3 commit e326a31

File tree

2 files changed

+106
-33
lines changed

2 files changed

+106
-33
lines changed

src/services/config.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ class ConfigData {
129129
}
130130

131131
removeProfile(profileToRemove) {
132-
this.projects = this.projects.filter((profile) => {
133-
return profile.id !== profileToRemove.id;
134-
});
132+
if (this.profiles[profileToRemove.id]) {
133+
delete this.profiles[profileToRemove.id];
134+
} else {
135+
this.projects = this.projects.filter((profile) => {
136+
return profile.id !== profileToRemove.id;
137+
});
138+
}
135139
if (profileToRemove.id === this.activeProfile) {
136140
this.activeProfile = null;
137141
}

test/services/config.test.js

+99-30
Original file line numberDiff line numberDiff line change
@@ -210,46 +210,115 @@ describe('services', () => {
210210
describe('ConfigData.removeProfile', () => {
211211
test.it('remove a profile that does not exist', () => {
212212
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+
);
216228
const fakeProfile = {
217229
id: 'DOES_NOT_EXIST',
218230
accountSid: 'fake_SID',
219231
};
220232
const originalLength = configData.projects.length;
233+
const originalProfilesLength = Object.keys(configData.profiles).length;
221234
configData.removeProfile(fakeProfile);
222235

223236
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;
224278
});
225279

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+
});
253322
});
254323
describe('ConfigData.prompts', () => {
255324
test.it('should store prompt acks', () => {

0 commit comments

Comments
 (0)