chore: Update target mirage config to include hostsets

This commit is contained in:
Susmitha Girumala committed 2020-08-25 11:54:36 -04:00
1 parent 990c3609ed
commit 7846398135
4 files changed
+35 -3

No files matched your search

+20
View File
@@ -131,6 +131,26 @@ export default function() {
this.patch('/scopes/:scope_id/targets/:id');
this.del('/scopes/:scope_id/targets/:id');
// host-set in a target
this.get('/scopes/:scope_id/targets/:targetId/host-sets', function ({ hostSets }, { params: { targetId } }) {
return hostSets.where({ targetId });
});
this.post('/scopes/:scope_id/targets/:targetId/host-sets', function ({ hostSets }, { params: { targetId } }) {
const attrs = this.normalizedRequestAttrs();
attrs.targetId = targetId;
return hostSets.create(attrs);
});
this.get('/scopes/:scope_id/targets/:targetId/host-sets/:id');
this.patch('/scopes/:scope_id/targets/:targetId/host-sets/:id');
this.del('/scopes/:scope_id/targets/:targetId/host-sets/:id');
this.post('/scopes/:scope_id/targets/:targetId/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.
// this.get('/scopes/:scope_id/projects', () => new Response(505));
+12 -1
View File
@@ -1,3 +1,14 @@
import factory from '../generated/factories/target';
import { trait } from 'ember-cli-mirage';
export default factory.extend();
export default factory.extend({
withChildren: trait({
afterCreate(target, server) {
const scope = target.scope;
const hosts = server.createList('host', 10, { scope });
server.createList('host-set', 3, { scope, target , hosts});
}
})
});
+1
View File
@@ -2,6 +2,7 @@ import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
export default Model.extend({
target: belongsTo(),
hostCatalog: belongsTo(),
hosts: hasMany()
+2 -2
View File
@@ -33,7 +33,7 @@ export default function(server) {
server.db.scopes.where({type: 'project'}).forEach(({ id, type }) => {
const scope = { id, type };
server.createList('host-catalog', 2, { scope }, 'withChildren');
server.createList('target', 2, { scope });
server.createList('target', 2, { scope }, 'withChildren');
});
}