v2.13.24
danielspaniel
released this
16 Feb 00:49
·
231 commits
to master
since this release
Streamline manualSetup usage to only need this:
hooks.beforeEach(async function() {
manualSetup(this); // <= easy peasy
]);
Add support for links tags in a payload ( for async belongsTo/hasMany relationships )
- Links can be setup in factories
import FactoryGuy from 'ember-data-factory-guy';
FactoryGuy.define("user", {
default: { // the () around the links objects is needed
company: (f) => ({links: `/users/${f.id}/company`})
},
traits: {
// luckily traits can use functions, so the settup is easy
propertiesLink: (f) => {
f.properties = {links: `/users/${f.id}/properties`}
}
}
});
- or, you can pass the links values when you make / build a model like:
let user1 = make('user', {properties: {links: '/users/1/properties'}});
let user2 = build('user', {properties: {links: '/users/2/properties'}});
- Then use mock and build / buildList to return a payload
let user = make('user', 'propertiesLink');
let propertiesLink = user.hasMany('properties').link();
let noProperties = buildList('property', 0);
mock({url: propertiesLink}).returns(noProperties);
- For future I would like to have a nicer way to mock those links
- [ Open to ideas ]
// maybe something like this ??
let user = make('user', 'propertiesLink');
let noProperties = buildList('property', 0);
mockLinks(user, 'properties').returns(noProperties);