Skip to content

Commit

Permalink
Ensure plugin and provider exist when resolving remote_values, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoTheThird committed Mar 7, 2021
1 parent 9b0bdb1 commit a9a4fa7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/core/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,17 @@ class PluginIndex {
});
}

/**
* resolves remote values
* @returns {Promise}
*/
remote_value(option) {
return Promise.resolve(this.parsePluginId(option.remote_values))
.then(([p, f]) => this.plugins[p][`remote_values__${f}`](option))
.then(([p, f]) =>
this.plugins[p] && this.plugins[p][`remote_values__${f}`]
? this.plugins[p][`remote_values__${f}`](option)
: []
)
.then(values => (option.values = values));
}

Expand Down
14 changes: 14 additions & 0 deletions src/core/plugins/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ describe("PluginIndex", () => {
pluginIndex.plugins.systemimage.remote_values__channels.mockRestore();
});
});
it("should resolve empty on invalid plugin", () => {
return pluginIndex
.remote_value({ remote_values: { "systemimage:invalid": { a: "b" } } })
.then(r => {
expect(r).toEqual([]);
});
});
it("should resolve empty on invalid provider", () => {
return pluginIndex
.remote_value({ remote_values: { "invalid:invalid": { a: "b" } } })
.then(r => {
expect(r).toEqual([]);
});
});
});
describe("getPluginArray()", () => {
it("should return plugin array", () =>
Expand Down

0 comments on commit a9a4fa7

Please sign in to comment.