Merge branch 'chore-update-to-plugin' of github.com:hashicorp/boundary-ui into chore-update-to-plugin

This commit is contained in:
dharini committed 2022-02-15 08:39:24 -08:00
commit c9ef425152
4 files changed
+85 -1

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
import ApplicationAdapter from './application';
export default class HostCatalogAdapter extends ApplicationAdapter {
/**
* Overrides the default `buildURL` such that on _create_, URLs for records of
* type `plugin` get an extra query parameter `?plugin_name`. All other
* request types behave as normal.
*
* @override
* @param {string} modelName
* @param {string} id
* @return {string} url
* @return {string} requestType
*/
buildURL(modelName, id, snapshot, requestType) {
let url = super.buildURL(...arguments);
if (requestType === 'createRecord') {
const pluginName = snapshot.attr('plugin')?.name;
if (pluginName) url = `${url}?plugin_name=${pluginName}`;
}
return url;
}
}
+1
View File
@@ -0,0 +1 @@
export { default } from 'api/adapters/host-catalog';
+13 -1
View File
@@ -270,7 +270,19 @@ export default function () {
return hostCatalogs.where({ scopeId });
}
);
this.post('/host-catalogs');
this.post(
'/host-catalogs',
function ({ hostCatalogs }, { queryParams: { plugin_name } }) {
const attrs = this.normalizedRequestAttrs();
if (plugin_name) {
attrs.type = 'plugin';
attrs.plugin = {
name: plugin_name,
};
}
return hostCatalogs.create(attrs);
}
);
this.get('/host-catalogs/:id');
this.patch('/host-catalogs/:id');
this.del('/host-catalogs/:id');
@@ -0,0 +1,48 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Adapter | host catalog', function (hooks) {
setupTest(hooks);
test('it generates correct createRecord URLs for static host catalogs', function (assert) {
assert.expect(1);
const scopeID = 'o_1';
const mockSnapshot = {
adapterOptions: {
scopeID,
},
attr() {
return null;
},
};
const adapter = this.owner.lookup('adapter:host-catalog');
const createRecordURL = adapter.buildURL(
'host-catalog',
null,
mockSnapshot,
'createRecord'
);
assert.equal(createRecordURL, '/v1/host-catalogs');
});
test('it generates correct createRecord URLs for dynamic host catalogs with extra query parameter ?plugin_name', function (assert) {
assert.expect(1);
const scopeID = 'o_1';
const mockSnapshot = {
adapterOptions: {
scopeID,
},
attr() {
return { name: 'aws' };
},
};
const adapter = this.owner.lookup('adapter:host-catalog');
const createRecordURL = adapter.buildURL(
'host-catalog',
null,
mockSnapshot,
'createRecord'
);
assert.equal(createRecordURL, '/v1/host-catalogs?plugin_name=aws');
});
});