Skip to content

Commit 36c18a8

Browse files
kptdoberofe
andauthored
fix: filter undefined projects (#769)
* fix: filter undefined projects * chore: align test * chore: make code more readable. * Update src/extension/project.js Co-authored-by: Raphael Wegmueller <github@rofe.com> * chore: get rid of legacy --------- Co-authored-by: Raphael Wegmueller <github@rofe.com>
1 parent 6433dfe commit 36c18a8

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

src/extension/project.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export async function getProject(project = {}) {
4848
* @returns {Promise<Object[]>} The project configurations
4949
*/
5050
export async function getProjects() {
51-
return Promise.all((await getConfig('sync', 'projects')
52-
|| await getConfig('sync', 'hlxSidekickProjects') || []) // legacy
53-
.map((handle) => getProject(handle)));
51+
const configs = await getConfig('sync', 'projects') || [];
52+
const projects = await Promise.all(configs.map((handle) => getProject(handle)));
53+
return projects.filter((project) => project !== undefined);
5454
}
5555

5656
/**
@@ -353,8 +353,7 @@ export async function deleteProject(project) {
353353
({ owner, repo } = project);
354354
handle = `${owner}/${repo}`;
355355
}
356-
const projects = await getConfig('sync', 'projects')
357-
|| await getConfig('sync', 'hlxSidekickProjects') || []; // legacy
356+
const projects = await getConfig('sync', 'projects') || [];
358357
const i = projects.indexOf(handle);
359358
if (i >= 0) {
360359
// delete admin auth header rule

test/project.test.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ describe('Test project', () => {
132132
let value;
133133
switch (prop) {
134134
case 'projects':
135-
case 'hlxSidekickProjects': // legacy
136135
value = ['foo/bar1'];
137136
break;
138137
case 'foo/bar1':
@@ -155,22 +154,9 @@ describe('Test project', () => {
155154
sandbox.restore();
156155
sandbox.stub(chrome.storage.sync, 'get')
157156
.withArgs('projects')
158-
.resolves({})
159-
.withArgs('hlxSidekickProjects')
160157
.resolves({});
161158
projects = await getProjects();
162159
expect(projects.length).to.equal(0);
163-
// legacy projects
164-
sandbox.restore();
165-
sandbox.stub(chrome.storage.sync, 'get')
166-
.withArgs('projects')
167-
.resolves({})
168-
.withArgs('hlxSidekickProjects')
169-
.resolves({
170-
hlxSidekickProjects: ['foo/bar1'],
171-
});
172-
projects = await getProjects();
173-
expect(projects.length).to.equal(1);
174160
});
175161

176162
it('getProjectEnv', async () => {

0 commit comments

Comments
 (0)