Add ember-cli-mirage addon
This commit is contained in:
parent
09637d5e07
commit
725d3b00da
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"predef": [
|
"predef": [
|
||||||
|
"server",
|
||||||
"document",
|
"document",
|
||||||
"window",
|
"window",
|
||||||
"-Promise",
|
"-Promise",
|
||||||
|
|
115
app/mirage/config.js
Normal file
115
app/mirage/config.js
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
export default function() {
|
||||||
|
let _turnIntoV3Singular = function(type, record) {
|
||||||
|
record['@type'] = type;
|
||||||
|
record['@href'] = `/${type}/${record.id}`
|
||||||
|
|
||||||
|
return record;
|
||||||
|
};
|
||||||
|
|
||||||
|
let turnIntoV3 = function(type, payload) {
|
||||||
|
let response;
|
||||||
|
if(Ember.isArray(payload)) {
|
||||||
|
let records = payload.map( (record) => { return _turnIntoV3Singular(type, record) } );
|
||||||
|
|
||||||
|
let pluralized = Ember.String.pluralize(type);
|
||||||
|
response = {};
|
||||||
|
response['@type'] = pluralized;
|
||||||
|
response['@href'] = `/${pluralized}`
|
||||||
|
response[pluralized] = records;
|
||||||
|
} else {
|
||||||
|
response = _turnIntoV3Singular(type, payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.get('/v3/repos', function(db, request) {
|
||||||
|
return turnIntoV3('repository', db.repositories);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.get('/v3/repos', function(db, request) {
|
||||||
|
return turnIntoV3('repository', db.repositories);
|
||||||
|
});
|
||||||
|
|
||||||
|
// These comments are here to help you get started. Feel free to delete them.
|
||||||
|
|
||||||
|
/*
|
||||||
|
Config (with defaults).
|
||||||
|
|
||||||
|
Note: these only affect routes defined *after* them!
|
||||||
|
*/
|
||||||
|
// this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server
|
||||||
|
// this.namespace = ''; // make this `api`, for example, if your API is namespaced
|
||||||
|
// this.timing = 400; // delay for each request, automatically set to 0 during testing
|
||||||
|
|
||||||
|
/*
|
||||||
|
Route shorthand cheatsheet
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
GET shorthands
|
||||||
|
|
||||||
|
// Collections
|
||||||
|
this.get('/contacts');
|
||||||
|
this.get('/contacts', 'users');
|
||||||
|
this.get('/contacts', ['contacts', 'addresses']);
|
||||||
|
|
||||||
|
// Single objects
|
||||||
|
this.get('/contacts/:id');
|
||||||
|
this.get('/contacts/:id', 'user');
|
||||||
|
this.get('/contacts/:id', ['contact', 'addresses']);
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
POST shorthands
|
||||||
|
|
||||||
|
this.post('/contacts');
|
||||||
|
this.post('/contacts', 'user'); // specify the type of resource to be created
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
PUT shorthands
|
||||||
|
|
||||||
|
this.put('/contacts/:id');
|
||||||
|
this.put('/contacts/:id', 'user'); // specify the type of resource to be updated
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
DELETE shorthands
|
||||||
|
|
||||||
|
this.del('/contacts/:id');
|
||||||
|
this.del('/contacts/:id', 'user'); // specify the type of resource to be deleted
|
||||||
|
|
||||||
|
// Single object + related resources. Make sure parent resource is first.
|
||||||
|
this.del('/contacts/:id', ['contact', 'addresses']);
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function fallback. Manipulate data in the db via
|
||||||
|
|
||||||
|
- db.{collection}
|
||||||
|
- db.{collection}.find(id)
|
||||||
|
- db.{collection}.where(query)
|
||||||
|
- db.{collection}.update(target, attrs)
|
||||||
|
- db.{collection}.remove(target)
|
||||||
|
|
||||||
|
// Example: return a single object with related models
|
||||||
|
this.get('/contacts/:id', function(db, request) {
|
||||||
|
var contactId = +request.params.id;
|
||||||
|
|
||||||
|
return {
|
||||||
|
contact: db.contacts.find(contactId),
|
||||||
|
addresses: db.addresses.where({contact_id: contactId})
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
You can optionally export a config that is only loaded during tests
|
||||||
|
export function testConfig() {
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
20
app/mirage/factories/contact.js
Normal file
20
app/mirage/factories/contact.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
This is an example factory definition.
|
||||||
|
|
||||||
|
Create more files in this directory to define additional factories.
|
||||||
|
*/
|
||||||
|
import Mirage/*, {faker} */ from 'ember-cli-mirage';
|
||||||
|
|
||||||
|
export default Mirage.Factory.extend({
|
||||||
|
// name: 'Pete', // strings
|
||||||
|
// age: 20, // numbers
|
||||||
|
// tall: true, // booleans
|
||||||
|
|
||||||
|
// email: function(i) { // and functions
|
||||||
|
// return 'person' + i + '@test.com';
|
||||||
|
// },
|
||||||
|
|
||||||
|
// firstName: faker.name.firstName, // using faker
|
||||||
|
// lastName: faker.name.firstName,
|
||||||
|
// zipCode: faker.address.zipCode
|
||||||
|
});
|
7
app/mirage/factories/repository.js
Normal file
7
app/mirage/factories/repository.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import Mirage from 'ember-cli-mirage';
|
||||||
|
|
||||||
|
export default Mirage.Factory.extend({
|
||||||
|
slug: 'travis-ci/travis-web',
|
||||||
|
githubLanguage: 'ruby',
|
||||||
|
active: true
|
||||||
|
});
|
7
app/mirage/scenarios/default.js
Normal file
7
app/mirage/scenarios/default.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export default function(/* server */) {
|
||||||
|
|
||||||
|
// Seed your development database using your factories. This
|
||||||
|
// data will not be loaded in your tests.
|
||||||
|
|
||||||
|
// server.createList('contact', 10);
|
||||||
|
}
|
|
@ -15,8 +15,10 @@
|
||||||
"moment": "~2.9.0",
|
"moment": "~2.9.0",
|
||||||
"jquery-timeago": "~1.4.1",
|
"jquery-timeago": "~1.4.1",
|
||||||
"pusher": "~2.2.3",
|
"pusher": "~2.2.3",
|
||||||
"pretender": "0.1.0",
|
"ember-resolver": "~0.1.20",
|
||||||
"ember-resolver": "~0.1.20"
|
"pretender": "~0.10.1",
|
||||||
|
"lodash": "~3.7.0",
|
||||||
|
"Faker": "~3.0.0"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"ember": "2.2.1",
|
"ember": "2.2.1",
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
|
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
|
||||||
"ember-cli-inject-live-reload": "^1.3.1",
|
"ember-cli-inject-live-reload": "^1.3.1",
|
||||||
"ember-cli-inline-images": "^0.0.4",
|
"ember-cli-inline-images": "^0.0.4",
|
||||||
|
"ember-cli-mirage": "0.1.11",
|
||||||
|
"ember-cli-page-object": "1.0.0",
|
||||||
"ember-cli-pendo": "drogus/ember-cli-pendo",
|
"ember-cli-pendo": "drogus/ember-cli-pendo",
|
||||||
"ember-cli-pretender": "0.3.1",
|
"ember-cli-pretender": "0.3.1",
|
||||||
"ember-cli-qunit": "^1.2.1",
|
"ember-cli-qunit": "^1.2.1",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"predef": [
|
"predef": [
|
||||||
|
"server",
|
||||||
"document",
|
"document",
|
||||||
"window",
|
"window",
|
||||||
"location",
|
"location",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user