chore: 🤖 add host-catalog mock API
This commit is contained in:
6 files changed
+56
-12
No files matched your search
@@ -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.
|
||||
|
||||
+10
-12
@@ -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');
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import factory from '../generated/factories/host-catalog';
|
||||
|
||||
export default factory.extend();
|
||||
@@ -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(),
|
||||
|
||||
});
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import ApplicationSerializer from './application';
|
||||
|
||||
export default ApplicationSerializer.extend({
|
||||
modelName: 'host-catalog'
|
||||
});
|
||||
Reference in new issue
Block a user