diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index 4a949b05f..5f4a14649 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -90,19 +90,31 @@ export default function() { // host - this.get('/scopes/:scope_id/host-catalogs/:host_catalog_id/hosts'); - this.post('/scopes/:scope_id/host-catalogs/:host_catalog_id/hosts'); - this.get('/scopes/:scope_id/host-catalogs/:host_catalog_id/hosts/:id'); - this.patch('/scopes/:scope_id/host-catalogs/:host_catalog_id/hosts/:id'); - this.del('/scopes/:scope_id/host-catalogs/:host_catalog_id/hosts/:id'); + this.get('/scopes/:scope_id/host-catalogs/:hostCatalogId/hosts', function ({ hosts }, { params: { hostCatalogId } }) { + return hosts.where({ hostCatalogId }); + }); + this.post('/scopes/:scope_id/host-catalogs/:hostCatalogId/hosts', function ({ hosts }, { params: { hostCatalogId } }) { + const attrs = this.normalizedRequestAttrs(); + attrs.hostCatalogId = hostCatalogId; + return hosts.create(attrs); + }); + this.get('/scopes/:scope_id/host-catalogs/:hostCatalogId/hosts/:id'); + this.patch('/scopes/:scope_id/host-catalogs/:hostCatalogId/hosts/:id'); + this.del('/scopes/:scope_id/host-catalogs/:hostCatalogId/hosts/:id'); // host-set - this.get('/scopes/:scope_id/host-catalogs/:host_catalog_id/host-sets'); - this.post('/scopes/:scope_id/host-catalogs/:host_catalog_id/host-sets'); - this.get('/scopes/:scope_id/host-catalogs/:host_catalog_id/host-sets/:id'); - this.patch('/scopes/:scope_id/host-catalogs/:host_catalog_id/host-sets/:id'); - this.del('/scopes/:scope_id/host-catalogs/:host_catalog_id/host-sets/:id'); + this.get('/scopes/:scope_id/host-catalogs/:hostCatalogId/host-sets', function ({ hostSets }, { params: { hostCatalogId } }) { + return hostSets.where({ hostCatalogId }); + }); + this.post('/scopes/:scope_id/host-catalogs/:hostCatalogId/host-sets', function ({ hostSets }, { params: { hostCatalogId } }) { + const attrs = this.normalizedRequestAttrs(); + attrs.hostCatalogId = hostCatalogId; + return hostSets.create(attrs); + }); + 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'); // Uncomment the following line and the Response import above // Then change the response code to simulate error responses. diff --git a/ui/core/mirage/factories/host-catalog.js b/ui/core/mirage/factories/host-catalog.js index ffd635036..02feb756d 100644 --- a/ui/core/mirage/factories/host-catalog.js +++ b/ui/core/mirage/factories/host-catalog.js @@ -1,3 +1,16 @@ import factory from '../generated/factories/host-catalog'; +import { trait } from 'ember-cli-mirage'; -export default factory.extend(); +export default factory.extend({ + + withChildren: trait({ + afterCreate(hostCatalog, server) { + const scope = hostCatalog.scope; + // Hosts and host sets are supposed to be associated to a host catalog. + // For simplicity of mocks, we don't actually associate them here. + server.createList('host-set', 3, { scope, hostCatalog }); + server.createList('host', 10, { scope, hostCatalog }); + } + }) + +}); diff --git a/ui/core/mirage/models/host-set.js b/ui/core/mirage/models/host-set.js new file mode 100644 index 000000000..89aba81e6 --- /dev/null +++ b/ui/core/mirage/models/host-set.js @@ -0,0 +1,7 @@ +import { Model, belongsTo } from 'ember-cli-mirage'; + +export default Model.extend({ + + hostCatalog: belongsTo() + +}); diff --git a/ui/core/mirage/models/host.js b/ui/core/mirage/models/host.js new file mode 100644 index 000000000..89aba81e6 --- /dev/null +++ b/ui/core/mirage/models/host.js @@ -0,0 +1,7 @@ +import { Model, belongsTo } from 'ember-cli-mirage'; + +export default Model.extend({ + + hostCatalog: belongsTo() + +}); diff --git a/ui/core/mirage/scenarios/default.js b/ui/core/mirage/scenarios/default.js index 5a87be352..a4fec0451 100644 --- a/ui/core/mirage/scenarios/default.js +++ b/ui/core/mirage/scenarios/default.js @@ -32,11 +32,7 @@ export default function(server) { server.db.scopes.where({type: 'project'}).forEach(({ id, type }) => { const scope = { id, type }; - server.createList('host-catalog', 2, { scope }); - // Hosts and host sets are supposed to be associated to a host catalog. - // For simplicity of mocks, we don't actually associate them here. - server.createList('host-set', 3, { scope }); - server.createList('host', 10, { scope }); + server.createList('host-catalog', 2, { scope }, 'withChildren'); }); }