chore: add host/host set mock relationship to host catalog

This commit is contained in:
Randall Morey committed 2020-08-19 16:12:53 -04:00
1 parent 96f5cda869
commit 31cea94fba
5 files changed
+51 -16

No files matched your search

+22 -10
View File
@@ -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.
+14 -1
View File
@@ -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 });
}
})
});
+7
View File
@@ -0,0 +1,7 @@
import { Model, belongsTo } from 'ember-cli-mirage';
export default Model.extend({
hostCatalog: belongsTo()
});
+7
View File
@@ -0,0 +1,7 @@
import { Model, belongsTo } from 'ember-cli-mirage';
export default Model.extend({
hostCatalog: belongsTo()
});
+1 -5
View File
@@ -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');
});
}