From da7a2e651a7aaa7c31065e281b2e94f40cfa6cb5 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Thu, 20 Aug 2020 12:04:54 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20add=20set-hosts=20mock?= =?UTF-8?q?=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/models/host-set.js | 18 ++++++++++++++++-- .../project/host-catalogs/host-catalog.js | 6 ++++++ ui/core/mirage/config.js | 7 +++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/addons/api/addon/models/host-set.js b/addons/api/addon/models/host-set.js index bdfb07214..e30e86236 100644 --- a/addons/api/addon/models/host-set.js +++ b/addons/api/addon/models/host-set.js @@ -16,14 +16,28 @@ export default class HostSetModel extends GeneratedHostSetModel { /** * Saves the `host_ids` array on the host set via the `set-hosts` method. * See serializer and adapter for more information. + * @param {object} options + * @param {object} options.adapterOptions + * @param {string} options.adapterOptions.hostCatalogID * @return {Promise} */ - saveHostIDs() { - return this.save({ + saveHostIDs(options={ adapterOptions: {} }) { + const defaultOptions = { adapterOptions: { method: 'set-hosts', serializeHostIDs: true } + }; + // There is no "deep merge" in ES. + // All of this nonsense is here to ensure we get + // a decent merge of `adapterOptions`. + return this.save({ + ...defaultOptions, + ...options, + adapterOptions: { + ...defaultOptions.adapterOptions, + ...options.adapterOptions + } }); } diff --git a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog.js b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog.js index d25608633..04e27c261 100644 --- a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog.js +++ b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog.js @@ -12,6 +12,12 @@ export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogRoute exte */ async model({ host_catalog_id }) { const { id: scopeID } = this.modelFor('scopes.scope'); + this.store.findAll('host-set', { + adapterOptions: { + scopeID, + hostCatalogID: host_catalog_id + } + }) return this.store.findRecord('host-catalog', host_catalog_id, { adapterOptions: { scopeID }, }); diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index 5f4a14649..4f69c6f33 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -115,6 +115,13 @@ export default function() { this.get('/scopes/:scope_id/host-catalogs/:hostCatalogId/host-sets/:id'); this.patch('/scopes/:scope_id/host-catalogs/:hostCatalogId/host-sets/:id'); this.del('/scopes/:scope_id/host-catalogs/:hostCatalogId/host-sets/:id'); + this.post('/scopes/:scope_id/host-catalogs/:hostCatalogId/host-sets/:idMethod', function ({ hostSets }, { params: { idMethod } }) { + const attrs = this.normalizedRequestAttrs(); + const id = idMethod.split(':')[0]; + const hostSet = hostSets.find(id); + attrs.id = id; + return hostSet.update(attrs); + }); // Uncomment the following line and the Response import above // Then change the response code to simulate error responses.