From 7846398135d28b45fefb7dbf1bb0cf16c4b4ab49 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 25 Aug 2020 11:54:36 -0400 Subject: [PATCH] chore: Update target mirage config to include hostsets --- ui/core/mirage/config.js | 20 ++++++++++++++++++++ ui/core/mirage/factories/target.js | 13 ++++++++++++- ui/core/mirage/models/host-set.js | 1 + ui/core/mirage/scenarios/default.js | 4 ++-- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index 56ebd68d0..68ef3f031 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -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)); diff --git a/ui/core/mirage/factories/target.js b/ui/core/mirage/factories/target.js index b664ff88a..9746158f2 100644 --- a/ui/core/mirage/factories/target.js +++ b/ui/core/mirage/factories/target.js @@ -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}); + } + }) + +}); diff --git a/ui/core/mirage/models/host-set.js b/ui/core/mirage/models/host-set.js index 2f78f5510..3aa8fbf7e 100644 --- a/ui/core/mirage/models/host-set.js +++ b/ui/core/mirage/models/host-set.js @@ -2,6 +2,7 @@ import { Model, belongsTo, hasMany } from 'ember-cli-mirage'; export default Model.extend({ + target: belongsTo(), hostCatalog: belongsTo(), hosts: hasMany() diff --git a/ui/core/mirage/scenarios/default.js b/ui/core/mirage/scenarios/default.js index 439b9fd01..5c835dadf 100644 --- a/ui/core/mirage/scenarios/default.js +++ b/ui/core/mirage/scenarios/default.js @@ -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'); }); - + }