diff --git a/addons/api/addon/adapters/application.js b/addons/api/addon/adapters/application.js index 71c109cb0..3bd3342a1 100644 --- a/addons/api/addon/adapters/application.js +++ b/addons/api/addon/adapters/application.js @@ -1,6 +1,8 @@ import RESTAdapter from '@ember-data/adapter/rest'; import config from 'ember-get-config'; import { get } from '@ember/object'; +import { dasherize } from '@ember/string'; +import { pluralize } from 'ember-inflector'; export default class ApplicationAdapter extends RESTAdapter { // =attributes @@ -21,6 +23,17 @@ export default class ApplicationAdapter extends RESTAdapter { // =methods + /** + * Transforms the type to a dasherized string used in our API paths. + * + * @override + * @param {string} type + * @return {string} + */ + pathForType(type) { + return dasherize(pluralize(type)); + } + /** * Overrides default ajax method by rewritting PUT requests as PATCH. * PATCH is the request method used by our API for updates. diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index ce0e06960..de1cadb6c 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -9,24 +9,22 @@ export default function() { // delay for each request, automatically set to 0 during testing this.timing = 350; - /* - Shorthand cheatsheet: - - this.get('/posts'); - this.post('/posts'); - this.get('/posts/:id'); - this.put('/posts/:id'); // or this.patch - this.del('/posts/:id'); - - https://www.ember-cli-mirage.com/docs/route-handlers/shorthands - */ - + // Allow any configured API host to passthrough, which is useful in + // development for testing against a locally running backend. if (config.api.host) this.passthrough(`${config.api.host}/**`); this.passthrough(); + // project this.get('/orgs/:org_id/projects'); this.post('/orgs/:org_id/projects'); this.get('/orgs/:org_id/projects/:id'); this.patch('/orgs/:org_id/projects/:id'); this.del('/orgs/:org_id/projects/:id'); + + // host-catalog + this.get('/orgs/:org_id/projects/:project_id/host-catalogs'); + this.post('/orgs/:org_id/projects/:project_id/host-catalogs'); + this.get('/orgs/:org_id/projects/:project_id/host-catalogs/:id'); + this.patch('/orgs/:org_id/projects/:project_id/host-catalogs/:id'); + this.del('/orgs/:org_id/projects/:project_id/host-catalogs/:id'); } diff --git a/ui/core/mirage/factories/host-catalog.js b/ui/core/mirage/factories/host-catalog.js new file mode 100644 index 000000000..ffd635036 --- /dev/null +++ b/ui/core/mirage/factories/host-catalog.js @@ -0,0 +1,3 @@ +import factory from '../generated/factories/host-catalog'; + +export default factory.extend(); diff --git a/ui/core/mirage/generated/factories/host-catalog.js b/ui/core/mirage/generated/factories/host-catalog.js new file mode 100644 index 000000000..daf2d356f --- /dev/null +++ b/ui/core/mirage/generated/factories/host-catalog.js @@ -0,0 +1,16 @@ +import { Factory } from 'ember-cli-mirage'; +import { random, date } from 'faker'; + +/** + * GeneratedHostCatalogModelFactory + */ +export default Factory.extend({ + + type: 'static', + name: () => random.words(), + description: () => random.words(), + created_time: () => date.recent(), + updated_time: () => date.recent(), + disabled: () => random.boolean(), + +}); diff --git a/ui/core/mirage/scenarios/default.js b/ui/core/mirage/scenarios/default.js index 070bbc1ee..fbf47a0b6 100644 --- a/ui/core/mirage/scenarios/default.js +++ b/ui/core/mirage/scenarios/default.js @@ -1,5 +1,14 @@ export default function(server) { + // Scope resources (org and project) have their relationship modelled. + server.createList('project', 3); + // For simplicity, other resources have their relationships modelled _except_ + // their relationships to scope. These leads to the situation where the UI + // displays _all subresources_ as if they belong to _every scope_. This is + // a tradeoff due to the complexity of relationship modelling. + + server.createList('host-catalog', 3); + } diff --git a/ui/core/mirage/serializers/host-catalog.js b/ui/core/mirage/serializers/host-catalog.js new file mode 100644 index 000000000..e7b237047 --- /dev/null +++ b/ui/core/mirage/serializers/host-catalog.js @@ -0,0 +1,5 @@ +import ApplicationSerializer from './application'; + +export default ApplicationSerializer.extend({ + modelName: 'host-catalog' +});