Skip to content

Commit 910f422

Browse files
author
Anuj
committed
Refactor profiles usage to projects
1 parent 7b77c20 commit 910f422

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/services/config.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ConfigData {
2020
this.edge = undefined;
2121
this.email = {};
2222
this.prompts = {};
23-
this.profiles = [];
23+
this.projects = [];
2424
this.activeProfile = null;
2525
}
2626

@@ -66,7 +66,7 @@ class ConfigData {
6666
if (profileId) {
6767
// Clean the profile ID.
6868
profileId = this.sanitize(profileId);
69-
profile = this.profiles.find((p) => p.id === profileId);
69+
profile = this.projects.find((p) => p.id === profileId);
7070
} else {
7171
profile = this.getActiveProfile();
7272
}
@@ -90,19 +90,19 @@ class ConfigData {
9090

9191
getActiveProfile() {
9292
let profile;
93-
if (this.profiles.length > 0) {
93+
if (this.projects.length > 0) {
9494
if (this.activeProfile) {
95-
profile = this.profiles.find((p) => p.id === this.activeProfile);
95+
profile = this.projects.find((p) => p.id === this.activeProfile);
9696
}
9797
if (!profile) {
98-
profile = this.profiles[0];
98+
profile = this.projects[0];
9999
}
100100
}
101101
return profile;
102102
}
103103

104104
removeProfile(profileToRemove) {
105-
this.profiles = this.profiles.filter((profile) => {
105+
this.projects = this.projects.filter((profile) => {
106106
return profile.id !== profileToRemove.id;
107107
});
108108
if (profileToRemove.id === this.activeProfile) {
@@ -121,7 +121,7 @@ class ConfigData {
121121
existing.accountSid = accountSid;
122122
existing.region = region;
123123
} else {
124-
this.profiles.push(new ConfigDataProfile(id, accountSid, region));
124+
this.projects.push(new ConfigDataProfile(id, accountSid, region));
125125
}
126126
}
127127

@@ -147,8 +147,8 @@ class ConfigData {
147147
this.email = configObj.email || {};
148148
this.prompts = configObj.prompts || {};
149149
// Note the historical 'projects' naming.
150-
configObj.profiles = configObj.projects || [];
151-
configObj.profiles.forEach((profile) => this.addProfile(profile.id, profile.accountSid, profile.region));
150+
configObj.projects = configObj.projects || [];
151+
configObj.projects.forEach((project) => this.addProfile(project.id, project.accountSid, project.region));
152152
this.setActiveProfile(configObj.activeProject);
153153
}
154154

@@ -181,7 +181,7 @@ class Config {
181181
email: configData.email,
182182
prompts: configData.prompts,
183183
// Note the historical 'projects' naming.
184-
projects: configData.profiles,
184+
projects: configData.projects,
185185
activeProject: configData.activeProfile,
186186
};
187187

test/services/config.test.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ describe('services', () => {
1414
const configData = new ConfigData();
1515
configData.addProfile('newProfile', constants.FAKE_ACCOUNT_SID, 'dev');
1616

17-
expect(configData.profiles[0].id).to.equal('newProfile');
18-
expect(configData.profiles[0].accountSid).to.equal(constants.FAKE_ACCOUNT_SID);
19-
expect(configData.profiles[0].region).to.equal('dev');
17+
expect(configData.projects[0].id).to.equal('newProfile');
18+
expect(configData.projects[0].accountSid).to.equal(constants.FAKE_ACCOUNT_SID);
19+
expect(configData.projects[0].region).to.equal('dev');
2020
});
2121

2222
test.it('should update an existing profile', () => {
2323
const configData = new ConfigData();
2424
configData.addProfile('activeProfile', constants.FAKE_ACCOUNT_SID, 'dev');
2525
configData.addProfile('activeProfile', 'new-account-sid');
2626

27-
expect(configData.profiles[0].id).to.equal('activeProfile');
28-
expect(configData.profiles[0].accountSid).to.equal('new-account-sid');
29-
expect(configData.profiles[0].region).to.be.undefined;
27+
expect(configData.projects[0].id).to.equal('activeProfile');
28+
expect(configData.projects[0].accountSid).to.equal('new-account-sid');
29+
expect(configData.projects[0].region).to.be.undefined;
3030
});
3131
});
3232

@@ -161,10 +161,10 @@ describe('services', () => {
161161
id: 'DOES_NOT_EXIST',
162162
accountSid: 'fake_SID',
163163
};
164-
const originalLength = configData.profiles.length;
164+
const originalLength = configData.projects.length;
165165
configData.removeProfile(fakeProfile);
166166

167-
expect(configData.profiles.length).to.equal(originalLength);
167+
expect(configData.projects.length).to.equal(originalLength);
168168
});
169169

170170
test.it('removes profile', () => {
@@ -175,8 +175,8 @@ describe('services', () => {
175175
const profile = configData.getProfileById('secondProfile');
176176
configData.removeProfile(profile);
177177

178-
expect(configData.profiles[1].id).to.equal('thirdProfile');
179-
expect(configData.profiles[1].accountSid).to.equal('newest_account_SID');
178+
expect(configData.projects[1].id).to.equal('thirdProfile');
179+
expect(configData.projects[1].accountSid).to.equal('newest_account_SID');
180180
});
181181

182182
test.it('removes active profile', () => {
@@ -187,8 +187,8 @@ describe('services', () => {
187187
const profile = configData.setActiveProfile('firstProfile');
188188
configData.removeProfile(profile);
189189

190-
expect(configData.profiles[1].id).to.equal('thirdProfile');
191-
expect(configData.profiles[1].accountSid).to.equal('newest_account_SID');
190+
expect(configData.projects[1].id).to.equal('thirdProfile');
191+
expect(configData.projects[1].accountSid).to.equal('newest_account_SID');
192192
expect(configData.activeProfile).to.equal(null);
193193
});
194194
});

0 commit comments

Comments
 (0)