Skip to content

Commit

Permalink
fix: filter allowedProperties on getConfigInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
amphro committed Feb 11, 2021
1 parent 49618db commit cbb91e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config/configAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export class ConfigAggregator extends AsyncOptionalCreatable<JsonMap> {
*/
public getConfigInfo(): ConfigInfo[] {
const infos = Object.keys(this.getConfig())
.filter((key) => this.getAllowedProperties().some((element) => key === element.key))
.map((key) => this.getInfo(key))
.filter((info): info is ConfigInfo => !!info);
return sortBy(infos, 'key');
Expand Down
12 changes: 11 additions & 1 deletion test/unit/config/configAggregatorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('ConfigAggregator', () => {
expect(aggregator.getLocation(Config.DEFAULT_USERNAME)).to.equal('Environment');
});

it('configInfo', async () => {
it('configInfo with env', async () => {
process.env.SFDX_DEFAULTUSERNAME = 'test';
$$.SANDBOX.stub(fs, 'readJson').returns(Promise.resolve({}));

Expand All @@ -170,5 +170,15 @@ describe('ConfigAggregator', () => {
expect(info.value).to.equal('test');
expect(info.location).to.equal('Environment');
});

it('configInfo ignores invalid entries', async () => {
$$.SANDBOX.stub(fs, 'readJsonMap').returns(Promise.resolve({ invalid: 'entry', apiVersion: 49.0 }));

const aggregator: ConfigAggregator = await ConfigAggregator.create();
const info = aggregator.getConfigInfo()[0];
expect(info.key).to.equal('apiVersion');
expect(info.value).to.equal(49.0);
expect(info.location).to.equal('Local');
});
});
});

0 comments on commit cbb91e1

Please sign in to comment.