ember-data-factory-guy
Version:
Factories for testing Ember applications using EmberData
43 lines (38 loc) • 949 B
JavaScript
import { isEmpty } from '@ember/utils';
import BasePayload from './base-payload';
export default class extends BasePayload {
/**
Can't add to included array for JSON payloads since they have
no includes or sideloaded relationships
Meta not working at the moment for this serializer even though
it is being included here in the payload
*/
add(more) {
if (more.meta) {
this.addMeta(more.meta);
}
return this.json;
}
getObjectKeys(key) {
let attrs = this.json;
if (isEmpty(key)) {
return JSON.parse(JSON.stringify(attrs));
}
return attrs[key];
}
getListKeys(key) {
let attrs = this.json;
if (isEmpty(key)) {
return JSON.parse(JSON.stringify(attrs));
}
if (typeof key === 'number') {
return attrs[key];
}
if (key === 'firstObject') {
return attrs[0];
}
if (key === 'lastObject') {
return attrs[attrs.length - 1];
}
}
}