From c7f1b6830e2e874ee470e62eb65a27b1abf0cdd1 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Fri, 14 Aug 2020 10:46:17 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20add=20host=20set=20mock?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/host-catalogs/host-catalog.js | 16 ++++++++++++++++ ui/core/mirage/config.js | 8 ++++++++ ui/core/mirage/factories/host-catalog.js | 15 ++++++++++++++- ui/core/mirage/factories/host-set.js | 3 +++ ui/core/mirage/factories/scope.js | 2 +- ui/core/mirage/generated/factories/host-set.js | 17 +++++++++++++++++ ui/core/mirage/scenarios/default.js | 2 +- 7 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 ui/core/mirage/factories/host-set.js create mode 100644 ui/core/mirage/generated/factories/host-set.js 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 f54947470..d25608633 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 @@ -1,4 +1,20 @@ import Route from '@ember/routing/route'; export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogRoute extends Route { + + // =methods + + /** + * Load a host catalog. + * @param {object} params + * @param {string} params.host_catalog_id + * @return {HostCatalogModel} + */ + async model({ host_catalog_id }) { + const { id: scopeID } = this.modelFor('scopes.scope'); + 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 73342c6b0..89159b0e0 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -88,6 +88,14 @@ export default function() { this.patch('/scopes/:scope_id/host-catalogs/:id'); this.del('/scopes/:scope_id/host-catalogs/: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'); + // 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/host-catalog.js b/ui/core/mirage/factories/host-catalog.js index ffd635036..d2f84b3c5 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({ + + /** + * Create catalogs with associated host sets and hosts. + */ + withChildren: trait({ + afterCreate(record, server) { + const host_set_ids = server.createList('host-set', 3).map(set => set.id); + record.update({ host_set_ids }); + } + }) + +}); diff --git a/ui/core/mirage/factories/host-set.js b/ui/core/mirage/factories/host-set.js new file mode 100644 index 000000000..2f12361c6 --- /dev/null +++ b/ui/core/mirage/factories/host-set.js @@ -0,0 +1,3 @@ +import factory from '../generated/factories/host-set'; + +export default factory.extend(); diff --git a/ui/core/mirage/factories/scope.js b/ui/core/mirage/factories/scope.js index 703e80ad4..d60486d15 100644 --- a/ui/core/mirage/factories/scope.js +++ b/ui/core/mirage/factories/scope.js @@ -14,7 +14,7 @@ export default factory.extend({ }, 'withChildren'); } if (record.type === 'org') { - server.createList('scope', 5, { + server.createList('scope', 3, { type: 'project', scope: { id: record.id, type: record.type } }); diff --git a/ui/core/mirage/generated/factories/host-set.js b/ui/core/mirage/generated/factories/host-set.js new file mode 100644 index 000000000..95636bda0 --- /dev/null +++ b/ui/core/mirage/generated/factories/host-set.js @@ -0,0 +1,17 @@ +import { Factory } from 'ember-cli-mirage'; +import { random, date } from 'faker'; + +/** + * GeneratedHostSetModelFactory + */ +export default Factory.extend({ + + type: 'static', + name: () => random.words(), + description: () => random.words(), + created_time: () => date.recent(), + updated_time: () => date.recent(), + version: () => random.number(), + size: () => random.number(), + +}); diff --git a/ui/core/mirage/scenarios/default.js b/ui/core/mirage/scenarios/default.js index 6f8e29775..9215e8a80 100644 --- a/ui/core/mirage/scenarios/default.js +++ b/ui/core/mirage/scenarios/default.js @@ -27,7 +27,7 @@ export default function(server) { server.db.scopes.where({type: 'project'}).forEach(projectScope => { const scope = { id: projectScope.id, type: projectScope.type }; - server.createList('host-catalog', 2, { scope }); + server.createList('host-catalog', 2, { scope }, 'withChildren'); }); }