diff --git a/.eslintrc.js b/.eslintrc.js
index f8cb81b5..23b0222d 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -10,25 +10,23 @@ module.exports = {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
- legacyDecorators: true
- }
+ legacyDecorators: true,
+ },
},
- plugins: [
- 'ember'
- ],
+ plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:prettier/recommended',
],
env: {
- browser: true
+ browser: true,
},
rules: {
'ember/no-jquery': 'off',
'ember/no-mixins': 'off',
'ember/no-new-mixins': 'off',
- 'no-useless-escape': 'off'
+ 'no-useless-escape': 'off',
},
overrides: [
// node files
@@ -46,11 +44,11 @@ module.exports = {
'./tests/dummy/config/**/*.js',
],
parserOptions: {
- sourceType: 'script'
+ sourceType: 'script',
},
env: {
browser: false,
- node: true
+ node: true,
},
plugins: ['node'],
extends: ['plugin:node/recommended'],
diff --git a/addon/-private/cache.js b/addon/-private/cache.js
index 5bbf03d8..0a36052d 100644
--- a/addon/-private/cache.js
+++ b/addon/-private/cache.js
@@ -1,10 +1,9 @@
-import { queryCacheKey, cacheKey } from './utils/get-key';
+import { queryCacheKey, cacheKey } from './utils/get-key';
/*
A cache for queries.
*/
export default class Cache {
-
constructor() {
this.store = {};
}
@@ -21,7 +20,6 @@ export default class Cache {
}
all() {
- return Object.keys(this.store).map(key => this.store[key]);
+ return Object.keys(this.store).map((key) => this.store[key]);
}
-
}
diff --git a/addon/-private/coordinator.js b/addon/-private/coordinator.js
index a33823af..94cb7191 100644
--- a/addon/-private/coordinator.js
+++ b/addon/-private/coordinator.js
@@ -5,19 +5,18 @@ import { get } from '@ember/object';
// cleans options so that the resulting object only contains
// data we want to send to the server as query params.
-let _cleanParams = function(options) {
+let _cleanParams = function (options) {
let clean = { ...{}, ...options };
delete clean.reload;
delete clean.backgroundReload;
return clean;
-}
+};
/*
I know how to retrieve queries from the cache, and also assemble queries that
are not in the cache but can be derived from them.
*/
export default class Coordinator {
-
constructor(store) {
this.store = store;
this.recordCache = new Cache();
@@ -52,9 +51,9 @@ export default class Coordinator {
}
queryFor(...args) {
- return args.length === 3 ?
- this.recordQueryFor(...args) :
- this.recordArrayQueryFor(...args);
+ return args.length === 3
+ ? this.recordQueryFor(...args)
+ : this.recordArrayQueryFor(...args);
}
dump() {
@@ -65,7 +64,9 @@ export default class Coordinator {
}
recordHasIncludes(type, id, includesString) {
- let query = this._assembleRecordQuery(type, id, { include: includesString });
+ let query = this._assembleRecordQuery(type, id, {
+ include: includesString,
+ });
let nonLoadedIncludes = this._nonLoadedIncludesForQuery(query);
return nonLoadedIncludes.length === 0;
@@ -99,16 +100,17 @@ export default class Coordinator {
}
_nonLoadedIncludesForQuery(query) {
- let loadedIncludes = get(this, `loadedIncludes.${query.type}.${query.id}`) || [];
+ let loadedIncludes =
+ get(this, `loadedIncludes.${query.type}.${query.id}`) || [];
let includesString = query.params.include || '';
return includesString
.split(',')
- .filter(include => !!include)
- .filter(include => {
- return !loadedIncludes.find(loadedInclude => {
+ .filter((include) => !!include)
+ .filter((include) => {
+ return !loadedIncludes.find((loadedInclude) => {
return loadedInclude.indexOf(include) === 0;
- })
+ });
});
}
@@ -123,7 +125,8 @@ export default class Coordinator {
_updateLoadedIncludesWithQuery(query) {
this.loadedIncludes[query.type] = this.loadedIncludes[query.type] || {};
- this.loadedIncludes[query.type][query.id] = this.loadedIncludes[query.type][query.id] || [];
+ this.loadedIncludes[query.type][query.id] =
+ this.loadedIncludes[query.type][query.id] || [];
let currentIncludes = this.loadedIncludes[query.type][query.id];
let nonLoadedIncludes = this._nonLoadedIncludesForQuery(query);
@@ -131,5 +134,4 @@ export default class Coordinator {
this.loadedIncludes[query.type][query.id] = newLoadedIncludes;
}
-
}
diff --git a/addon/-private/record-array-query.js b/addon/-private/record-array-query.js
index fab407ad..ab53d03b 100644
--- a/addon/-private/record-array-query.js
+++ b/addon/-private/record-array-query.js
@@ -1,5 +1,4 @@
export default class RecordArrayQuery {
-
constructor(store, type, params = {}) {
this.store = store;
this.type = type;
@@ -13,14 +12,12 @@ export default class RecordArrayQuery {
if (this.value) {
promise = this.value.update();
-
} else {
- promise = this.store.query(this.type, this.params)
- .then(records => {
- this.value = records;
+ promise = this.store.query(this.type, this.params).then((records) => {
+ this.value = records;
- return records;
- });
+ return records;
+ });
}
return promise;
@@ -30,13 +27,12 @@ export default class RecordArrayQuery {
let includes = this.params && this.params.include;
let models = this.value;
- if (includes && models) {
+ if (includes && models) {
models
- .filter(model => model.trackLoadedIncludes)
+ .filter((model) => model.trackLoadedIncludes)
.forEach((model) => {
model.trackLoadedIncludes(includes);
});
}
}
-
}
diff --git a/addon/-private/record-query.js b/addon/-private/record-query.js
index 39e5618e..b7c050cb 100644
--- a/addon/-private/record-query.js
+++ b/addon/-private/record-query.js
@@ -1,5 +1,4 @@
export default class RecordQuery {
-
constructor(store, type, id, params = {}) {
this.store = store;
this.type = type;
@@ -8,9 +7,10 @@ export default class RecordQuery {
// if we have no params, we can use the model from
// the store if it exists, nice lil shortcut here.
- this.value = Object.keys(this.params).length === 0 ?
- this.store.peekRecord(type, id) :
- null;
+ this.value =
+ Object.keys(this.params).length === 0
+ ? this.store.peekRecord(type, id)
+ : null;
}
run() {
@@ -18,12 +18,10 @@ export default class RecordQuery {
// a blocking promise, so we force reload true.
let options = { ...{ reload: true }, ...this.params };
- return this.store.findRecord(this.type, this.id, options)
- .then(record => {
- this.value = record;
+ return this.store.findRecord(this.type, this.id, options).then((record) => {
+ this.value = record;
- return record;
- });
+ return record;
+ });
}
-
}
diff --git a/addon/-private/utils/get-key.js b/addon/-private/utils/get-key.js
index 5b7ea27c..03ce489a 100644
--- a/addon/-private/utils/get-key.js
+++ b/addon/-private/utils/get-key.js
@@ -1,13 +1,13 @@
-let _serializeParams = function(params={}, prefix) {
+let _serializeParams = function (params = {}, prefix) {
const query = Object.keys(params)
.sort()
.map((key) => {
- const value = params[key];
+ const value = params[key];
if (Array.isArray(params)) {
key = `${prefix}[]`;
} else if (params === Object(params)) {
- key = (prefix ? `${prefix}[${key}]` : key);
+ key = prefix ? `${prefix}[${key}]` : key;
}
if (typeof value === 'object' && value !== null) {
@@ -20,28 +20,23 @@ let _serializeParams = function(params={}, prefix) {
return [].concat.apply([], query).join('&');
};
-let serializeObject = function(params) {
+let serializeObject = function (params) {
return _serializeParams(params);
};
-let queryCacheKey = function(query) {
+let queryCacheKey = function (query) {
return cacheKey([query.type, query.id, query.params]);
};
-let cacheKey = function(args) {
+let cacheKey = function (args) {
return args
- .map(part => typeof part === "object" ? serializeObject(part) : part)
- .filter(part => !!part)
+ .map((part) => (typeof part === 'object' ? serializeObject(part) : part))
+ .filter((part) => !!part)
.join('::');
-}
+};
-let shoeboxize = function(key) {
+let shoeboxize = function (key) {
return key.replace(/&/g, '--'); // IDGAF
-}
-
-export {
- serializeObject,
- queryCacheKey,
- cacheKey,
- shoeboxize
-}
+};
+
+export { serializeObject, queryCacheKey, cacheKey, shoeboxize };
diff --git a/addon/adapters/application.js b/addon/adapters/application.js
index d9fae4d5..09a6c6ca 100644
--- a/addon/adapters/application.js
+++ b/addon/adapters/application.js
@@ -1,3 +1,3 @@
import JSONAPIAdapter from '@ember-data/adapter/json-api';
-export default class ApplicationAdapter extends JSONAPIAdapter {}
\ No newline at end of file
+export default class ApplicationAdapter extends JSONAPIAdapter {}
diff --git a/addon/components/assert-must-preload/component.js b/addon/components/assert-must-preload/component.js
index 6fb1826d..50be8c26 100644
--- a/addon/components/assert-must-preload/component.js
+++ b/addon/components/assert-must-preload/component.js
@@ -2,8 +2,7 @@ import Component from '@glimmer/component';
import { assert } from '@ember/debug';
export default class AssertMustPreloadComponent extends Component {
-
-/**
+ /**
_This component relies on JSON:API, and assumes that your server supports JSON:API includes._
_ only works on models that have included the LoadableModel mixin._
@@ -32,7 +31,9 @@ export default class AssertMustPreloadComponent extends Component {
const { model, includes } = this.args;
let parentComponent = this.parentView;
- let parentName = parentComponent ? parentComponent._debugContainerKey : 'template';
+ let parentName = parentComponent
+ ? parentComponent._debugContainerKey
+ : 'template';
let includesString = includes.join(',');
assert(
@@ -45,5 +46,4 @@ export default class AssertMustPreloadComponent extends Component {
model.hasLoaded(includesString)
);
}
-
}
diff --git a/addon/instance-initializers/inject-storefront.js b/addon/instance-initializers/inject-storefront.js
index 6ed9a1bc..baaa22a2 100644
--- a/addon/instance-initializers/inject-storefront.js
+++ b/addon/instance-initializers/inject-storefront.js
@@ -6,5 +6,5 @@ export function initialize(appInstance) {
export default {
name: 'inject-storefront',
after: 'mixin-storefront',
- initialize
+ initialize,
};
diff --git a/addon/instance-initializers/mixin-storefront.js b/addon/instance-initializers/mixin-storefront.js
index e4e82411..bb050271 100644
--- a/addon/instance-initializers/mixin-storefront.js
+++ b/addon/instance-initializers/mixin-storefront.js
@@ -9,5 +9,5 @@ export function initialize(appInstance) {
export default {
name: 'mixin-storefront',
after: 'ember-data',
- initialize
+ initialize,
};
diff --git a/addon/mixins/fastboot-adapter.js b/addon/mixins/fastboot-adapter.js
index a3e14909..b63afc88 100644
--- a/addon/mixins/fastboot-adapter.js
+++ b/addon/mixins/fastboot-adapter.js
@@ -3,7 +3,10 @@
import Mixin from '@ember/object/mixin';
import { inject as service } from '@ember/service';
import { resolve } from 'rsvp';
-import { cacheKey, shoeboxize } from 'ember-data-storefront/-private/utils/get-key';
+import {
+ cacheKey,
+ shoeboxize,
+} from 'ember-data-storefront/-private/utils/get-key';
import { getOwner } from '@ember/application';
/**
This mixin adds fastboot support to your data adapter. It provides no
@@ -39,11 +42,15 @@ export default Mixin.create({
ajax(url, type, options = {}) {
let cachedPayload = this._getStorefrontBoxedQuery(type, url, options.data);
- let maybeAddToShoebox = this._makeStorefrontQueryBoxer(type, url, options.data);
-
- return cachedPayload ?
- resolve(JSON.parse(cachedPayload)) :
- this._super(...arguments).then(maybeAddToShoebox);
+ let maybeAddToShoebox = this._makeStorefrontQueryBoxer(
+ type,
+ url,
+ options.data
+ );
+
+ return cachedPayload
+ ? resolve(JSON.parse(cachedPayload))
+ : this._super(...arguments).then(maybeAddToShoebox);
},
_makeStorefrontQueryBoxer(type, url, params) {
@@ -51,14 +58,16 @@ export default Mixin.create({
let isFastboot = fastboot && fastboot.isFastBoot;
let cache = this.storefront.fastbootDataRequests;
- return function(response) {
+ return function (response) {
if (isFastboot) {
- let key = shoeboxize(cacheKey([type, url.replace(/^.*\/\/[^\/]+/, ''), params]));
+ let key = shoeboxize(
+ cacheKey([type, url.replace(/^.*\/\/[^\/]+/, ''), params])
+ );
cache[key] = JSON.stringify(response);
}
return response;
- }
+ };
},
_getStorefrontBoxedQuery(type, url, params) {
@@ -69,11 +78,22 @@ export default Mixin.create({
let box = shoebox && shoebox.retrieve('ember-data-storefront');
const config = getOwner(this).resolveRegistration('config:environment');
- const maxAgeMinutes = config.storefront ? config.storefront.maxAge : undefined;
-
- if (!isFastboot && box && box.queries && Object.keys(box.queries).length > 0) {
- const shouldUseShoebox = maxAgeMinutes === undefined || this.isDateValid(box.created, maxAgeMinutes);
- let key = shoeboxize(cacheKey([type, url.replace(/^.*\/\/[^\/]+/, ''), params]));
+ const maxAgeMinutes = config.storefront
+ ? config.storefront.maxAge
+ : undefined;
+
+ if (
+ !isFastboot &&
+ box &&
+ box.queries &&
+ Object.keys(box.queries).length > 0
+ ) {
+ const shouldUseShoebox =
+ maxAgeMinutes === undefined ||
+ this.isDateValid(box.created, maxAgeMinutes);
+ let key = shoeboxize(
+ cacheKey([type, url.replace(/^.*\/\/[^\/]+/, ''), params])
+ );
if (shouldUseShoebox) {
payload = box.queries[key];
@@ -86,5 +106,5 @@ export default Mixin.create({
isDateValid(createdString, maxAgeMinutes) {
return (new Date() - new Date(createdString)) / 1000 / 60 < maxAgeMinutes;
- }
-})
+ },
+});
diff --git a/addon/mixins/loadable-model.js b/addon/mixins/loadable-model.js
index 66c04bba..1c37ffe1 100644
--- a/addon/mixins/loadable-model.js
+++ b/addon/mixins/loadable-model.js
@@ -32,7 +32,6 @@ import { camelize } from '@ember/string';
@public
*/
export default Mixin.create({
-
init() {
this._super(...arguments);
this.set('_loadedReferences', {});
@@ -48,7 +47,7 @@ export default Mixin.create({
return this.sideload(...args);
},
- /**
+ /**
`sideload` gives you an explicit way to asynchronously sideload related data.
```js
@@ -100,12 +99,12 @@ export default Mixin.create({
if (typeof possibleOptions === 'string') {
options = {
- include: args.join(',')
+ include: args.join(','),
};
} else {
options = {
...possibleOptions,
- ...{ include: args.slice(0,-1).join(',') }
+ ...{ include: args.slice(0, -1).join(',') },
};
}
@@ -167,7 +166,7 @@ export default Mixin.create({
}
}
- return promise.then(data => {
+ return promise.then((data) => {
// need to track that we loaded this relationship, since relying on the reference's
// value existing is not enough
this._loadedReferences[name] = true;
@@ -192,7 +191,9 @@ export default Mixin.create({
@private
*/
_getRelationshipInfo(name) {
- let relationshipInfo = get(this.constructor, `relationshipsByName`).get(name);
+ let relationshipInfo = get(this.constructor, `relationshipsByName`).get(
+ name
+ );
assert(
`You tried to load the relationship ${name} for a ${this.constructor.modelName}, but that relationship does not exist [ember-data-storefront]`,
@@ -250,7 +251,7 @@ export default Mixin.create({
if (info.kind === 'hasMany') {
models = reference.value() || [];
} else if (info.kind === 'belongsTo') {
- models = reference.value() ? [ reference.value() ] : [];
+ models = reference.value() ? [reference.value()] : [];
}
return models;
@@ -266,7 +267,7 @@ export default Mixin.create({
@private
*/
trackLoadedIncludes(includes) {
- includes.split(",").forEach(path => this._trackLoadedIncludePath(path));
+ includes.split(',').forEach((path) => this._trackLoadedIncludePath(path));
},
/**
@@ -282,7 +283,7 @@ export default Mixin.create({
@private
*/
_trackLoadedIncludePath(path) {
- let [firstInclude, ...rest] = path.split(".");
+ let [firstInclude, ...rest] = path.split('.');
let relationship = camelize(firstInclude);
if (this._hasNamedRelationship(relationship)) {
@@ -290,8 +291,8 @@ export default Mixin.create({
if (rest.length) {
this._getRelationshipModels(relationship)
- .filter(model => model.trackLoadedIncludes)
- .forEach(model => model.trackLoadedIncludes(rest.join('.')));
+ .filter((model) => model.trackLoadedIncludes)
+ .forEach((model) => model.trackLoadedIncludes(rest.join('.')));
}
}
},
@@ -307,9 +308,7 @@ export default Mixin.create({
@private
*/
_graphHasLoaded(includes) {
- return includes
- .split(",")
- .every(path => this._graphHasLoadedPath(path));
+ return includes.split(',').every((path) => this._graphHasLoadedPath(path));
},
/**
@@ -321,19 +320,20 @@ export default Mixin.create({
@private
*/
_graphHasLoadedPath(includePath) {
- let [firstInclude, ...rest] = includePath.split(".");
+ let [firstInclude, ...rest] = includePath.split('.');
let relationship = camelize(firstInclude);
let reference = this._getReference(relationship);
let hasLoaded = reference && this._hasLoadedReference(relationship);
if (rest.length === 0) {
return hasLoaded;
-
} else {
let models = this._getRelationshipModels(relationship);
- let childrenHaveLoaded = models.every(model => {
- return model.trackLoadedIncludes && model._graphHasLoaded(rest.join("."));
+ let childrenHaveLoaded = models.every((model) => {
+ return (
+ model.trackLoadedIncludes && model._graphHasLoaded(rest.join('.'))
+ );
});
return hasLoaded && childrenHaveLoaded;
@@ -362,8 +362,12 @@ export default Mixin.create({
*/
hasLoaded(includesString) {
let modelName = this.constructor.modelName;
- return this.store.hasLoadedIncludesForRecord(modelName, this.id, includesString) ||
- this._graphHasLoaded(includesString);
- }
-
+ return (
+ this.store.hasLoadedIncludesForRecord(
+ modelName,
+ this.id,
+ includesString
+ ) || this._graphHasLoaded(includesString)
+ );
+ },
});
diff --git a/addon/mixins/loadable-store.js b/addon/mixins/loadable-store.js
index b83d589f..5dbf519e 100644
--- a/addon/mixins/loadable-store.js
+++ b/addon/mixins/loadable-store.js
@@ -12,7 +12,6 @@ import Coordinator from 'ember-data-storefront/-private/coordinator';
@public
*/
export default Mixin.create({
-
init() {
this._super(...arguments);
@@ -53,17 +52,17 @@ export default Mixin.create({
@return {Promise} a promise resolving with the record array
@public
*/
- loadRecords(type, options={}) {
+ loadRecords(type, options = {}) {
let query = this.coordinator.recordArrayQueryFor(type, options);
let shouldBlock = options.reload || !query.value;
- let shouldBackgroundReload = (options.backgroundReload !== undefined) ? options.backgroundReload : true;
+ let shouldBackgroundReload =
+ options.backgroundReload !== undefined ? options.backgroundReload : true;
let promise;
let fetcher;
if (shouldBlock) {
promise = query.run();
fetcher = promise;
-
} else {
promise = resolve(query.value);
@@ -123,15 +122,15 @@ export default Mixin.create({
@return {Promise} a promise resolving with the record array
@public
*/
- loadRecord(type, id, options={}) {
+ loadRecord(type, id, options = {}) {
let query = this.coordinator.recordQueryFor(type, id, options);
let shouldBlock = options.reload || !query.value;
- let shouldBackgroundReload = (options.backgroundReload !== undefined) ? options.backgroundReload : true;
+ let shouldBackgroundReload =
+ options.backgroundReload !== undefined ? options.backgroundReload : true;
let promise;
if (shouldBlock) {
promise = query.run();
-
} else {
promise = resolve(query.value);
@@ -169,6 +168,5 @@ export default Mixin.create({
*/
resetCache() {
this.coordinator = new Coordinator(this);
- }
-
+ },
});
diff --git a/addon/mixins/loadable.js b/addon/mixins/loadable.js
index 9718df92..a7cc0749 100644
--- a/addon/mixins/loadable.js
+++ b/addon/mixins/loadable.js
@@ -4,13 +4,11 @@ import { on } from '@ember/object/evented';
import LoadableModel from './loadable-model';
export default Mixin.create(LoadableModel, {
-
- showDeprecations: on('init', function() {
+ showDeprecations: on('init', function () {
deprecate(
'The Loadable mixin has been renamed to LoadableMixin. Please change all instances of Loadable in your app to LoadableMixin. Loadable will be removed in 1.0.',
false,
{ id: 'ember-data-storefront.loadable', until: '1.0.0' }
);
- })
-
+ }),
});
diff --git a/addon/mixins/snapshottable.js b/addon/mixins/snapshottable.js
index 2bd473d2..76272d12 100644
--- a/addon/mixins/snapshottable.js
+++ b/addon/mixins/snapshottable.js
@@ -3,7 +3,6 @@ import { isArray } from '@ember/array';
import Mixin from '@ember/object/mixin';
export default Mixin.create({
-
/*
Graph for a post looks like
@@ -32,32 +31,45 @@ export default Mixin.create({
}
}
*/
- takeSnapshot(graph={}) {
+ takeSnapshot(graph = {}) {
let snapshot = { model: this, relationships: {} };
- Object.keys(graph).forEach(key => {
+ Object.keys(graph).forEach((key) => {
let node = graph[key];
let relationship = this.get(key);
if (isArray(relationship)) {
- snapshot.relationships[key] = relationship.map(model => ({ model, relationships: {} }));
+ snapshot.relationships[key] = relationship.map((model) => ({
+ model,
+ relationships: {},
+ }));
} else {
- snapshot.relationships[key] = { model: relationship, relationships: {} };
+ snapshot.relationships[key] = {
+ model: relationship,
+ relationships: {},
+ };
}
// call all this recursively instead
if (typeof node === 'object') {
- Object.keys(node).forEach(subkey => {
+ Object.keys(node).forEach((subkey) => {
let namedRelationshipMeta = snapshot.relationships[key];
if (namedRelationshipMeta) {
if (isArray(namedRelationshipMeta)) {
- namedRelationshipMeta.forEach(relationshipSnapshot => {
+ namedRelationshipMeta.forEach((relationshipSnapshot) => {
let nestedRelationship = relationshipSnapshot.model.get(subkey);
if (isArray(nestedRelationship)) {
- relationshipSnapshot.relationships[subkey] = nestedRelationship.map(model => ({ model, relationships: {} }));
+ relationshipSnapshot.relationships[subkey] =
+ nestedRelationship.map((model) => ({
+ model,
+ relationships: {},
+ }));
} else {
- relationshipSnapshot.relationships[subkey] = { model: nestedRelationship, relationships: {} };
+ relationshipSnapshot.relationships[subkey] = {
+ model: nestedRelationship,
+ relationships: {},
+ };
}
// check the node (would be handled by recursive call)
@@ -67,9 +79,16 @@ export default Mixin.create({
let nestedRelationship = namedRelationshipMeta.model.get(subkey);
if (isArray(nestedRelationship)) {
- namedRelationshipMeta.relationships[subkey] = nestedRelationship.map(model => ({ model, relationships: {} }));
+ namedRelationshipMeta.relationships[subkey] =
+ nestedRelationship.map((model) => ({
+ model,
+ relationships: {},
+ }));
} else {
- namedRelationshipMeta.relationships[subkey] = { model: nestedRelationship, relationships: {} };
+ namedRelationshipMeta.relationships[subkey] = {
+ model: nestedRelationship,
+ relationships: {},
+ };
}
}
}
@@ -106,15 +125,21 @@ export default Mixin.create({
restoreSnapshot(snapshot) {
snapshot.model && snapshot.model.rollbackAttributes();
- Object.keys(snapshot.relationships).forEach(key => {
+ Object.keys(snapshot.relationships).forEach((key) => {
let relationshipSnapshot = snapshot.relationships[key];
if (isArray(relationshipSnapshot)) {
- this.set(key, relationshipSnapshot.map(meta => meta.model));
- relationshipSnapshot.forEach(rSnapshot => {
+ this.set(
+ key,
+ relationshipSnapshot.map((meta) => meta.model)
+ );
+ relationshipSnapshot.forEach((rSnapshot) => {
let model = rSnapshot.model;
model.rollbackAttributes();
if (Object.keys(rSnapshot.relationships).length) {
- assert(`You're trying to restore a snapshot on a ${model._debugContainerKey} but that model isn't snapshottable. Be sure to include the Snapshottable mixin.`, model.restoreSnapshot !== undefined);
+ assert(
+ `You're trying to restore a snapshot on a ${model._debugContainerKey} but that model isn't snapshottable. Be sure to include the Snapshottable mixin.`,
+ model.restoreSnapshot !== undefined
+ );
model.restoreSnapshot(rSnapshot);
}
});
@@ -128,11 +153,13 @@ export default Mixin.create({
}
if (Object.keys(relationshipSnapshot.relationships).length) {
- assert(`You're trying to restore a snapshot on a ${model._debugContainerKey} but that model isn't snapshottable. Be sure to include the Snapshottable mixin.`, model.restoreSnapshot !== undefined);
+ assert(
+ `You're trying to restore a snapshot on a ${model._debugContainerKey} but that model isn't snapshottable. Be sure to include the Snapshottable mixin.`,
+ model.restoreSnapshot !== undefined
+ );
model.restoreSnapshot(relationshipSnapshot);
}
}
});
- }
-
+ },
});
diff --git a/addon/services/storefront.js b/addon/services/storefront.js
index 950ec0ed..b6917006 100644
--- a/addon/services/storefront.js
+++ b/addon/services/storefront.js
@@ -58,7 +58,10 @@ export default class StorefrontService extends Service {
deprecate(
'The storefront service has been deprecated, please use store.hasLoadedIncludesForRecord instead. Will be removed in 1.0.',
false,
- { id: 'ember-data-storefront.storefront-has-loaded-includes-for-record', until: '1.0.0' }
+ {
+ id: 'ember-data-storefront.storefront-has-loaded-includes-for-record',
+ until: '1.0.0',
+ }
);
return this.store.hasLoadedIncludesForRecord(...arguments);
@@ -73,5 +76,4 @@ export default class StorefrontService extends Service {
return this.store.resetCache(...arguments);
}
-
}
diff --git a/app/instance-initializers/inject-storefront.js b/app/instance-initializers/inject-storefront.js
index cc377974..dae8639b 100644
--- a/app/instance-initializers/inject-storefront.js
+++ b/app/instance-initializers/inject-storefront.js
@@ -1 +1,4 @@
-export { default, initialize } from 'ember-data-storefront/instance-initializers/inject-storefront';
+export {
+ default,
+ initialize,
+} from 'ember-data-storefront/instance-initializers/inject-storefront';
diff --git a/app/instance-initializers/mixin-storefront.js b/app/instance-initializers/mixin-storefront.js
index d8cc4ac1..08f65bec 100644
--- a/app/instance-initializers/mixin-storefront.js
+++ b/app/instance-initializers/mixin-storefront.js
@@ -1 +1,4 @@
-export { default, initialize } from 'ember-data-storefront/instance-initializers/mixin-storefront';
+export {
+ default,
+ initialize,
+} from 'ember-data-storefront/instance-initializers/mixin-storefront';
diff --git a/app/transitions.js b/app/transitions.js
index f1300faf..9e8fa5de 100644
--- a/app/transitions.js
+++ b/app/transitions.js
@@ -1,4 +1,4 @@
-export default function(){
+export default function () {
// Add your transitions here, like:
// this.transition(
// this.fromRoute('people.index'),
diff --git a/config/deploy.js b/config/deploy.js
index c3119ab8..9ff76f5a 100644
--- a/config/deploy.js
+++ b/config/deploy.js
@@ -1,12 +1,12 @@
/* eslint-env node */
'use strict';
-module.exports = function(deployTarget) {
+module.exports = function (deployTarget) {
let ENV = {
build: {},
git: {
- repo: 'git@github.com:embermap/ember-data-storefront.git'
- }
+ repo: 'git@github.com:embermap/ember-data-storefront.git',
+ },
};
if (deployTarget === 'development') {
diff --git a/config/ember-try.js b/config/ember-try.js
index e6c09bf9..c897e844 100644
--- a/config/ember-try.js
+++ b/config/ember-try.js
@@ -1,74 +1,74 @@
-"use strict";
+'use strict';
-const getChannelURL = require("ember-source-channel-url");
+const getChannelURL = require('ember-source-channel-url');
-module.exports = function() {
+module.exports = function () {
return Promise.all([
- getChannelURL("release"),
- getChannelURL("beta"),
- getChannelURL("canary")
- ]).then(urls => {
+ getChannelURL('release'),
+ getChannelURL('beta'),
+ getChannelURL('canary'),
+ ]).then((urls) => {
return {
useYarn: true,
scenarios: [
{
- name: "ember-lts-3.12",
+ name: 'ember-lts-3.12',
npm: {
devDependencies: {
- "ember-source": "~3.12.0",
- "ember-data": "~3.12.0"
+ 'ember-source': '~3.12.0',
+ 'ember-data': '~3.12.0',
},
resolutions: {
- "ember-data": "~3.12.0"
- }
- }
+ 'ember-data': '~3.12.0',
+ },
+ },
},
{
- name: "ember-lts-3.16",
+ name: 'ember-lts-3.16',
npm: {
devDependencies: {
- "ember-source": "~3.16.0",
- "ember-data": "~3.16.0"
+ 'ember-source': '~3.16.0',
+ 'ember-data': '~3.16.0',
},
resolutions: {
- "ember-data": "~3.16.0"
- }
- }
+ 'ember-data': '~3.16.0',
+ },
+ },
},
{
- name: "ember-release",
+ name: 'ember-release',
npm: {
devDependencies: {
- "ember-source": urls[0],
- "ember-data": "latest"
- }
- }
+ 'ember-source': urls[0],
+ 'ember-data': 'latest',
+ },
+ },
},
{
- name: "ember-beta",
+ name: 'ember-beta',
npm: {
devDependencies: {
- "ember-source": urls[1],
- "ember-data": "beta"
- }
- }
+ 'ember-source': urls[1],
+ 'ember-data': 'beta',
+ },
+ },
},
{
- name: "ember-canary",
+ name: 'ember-canary',
npm: {
devDependencies: {
- "ember-source": urls[2],
- "ember-data": "canary"
- }
- }
+ 'ember-source': urls[2],
+ 'ember-data': 'canary',
+ },
+ },
},
{
- name: "ember-default",
+ name: 'ember-default',
npm: {
- devDependencies: {}
- }
- }
- ]
+ devDependencies: {},
+ },
+ },
+ ],
};
});
};
diff --git a/config/environment.js b/config/environment.js
index 0dfaed47..331ab30d 100644
--- a/config/environment.js
+++ b/config/environment.js
@@ -1,5 +1,5 @@
'use strict';
-module.exports = function(/* environment, appConfig */) {
- return { };
+module.exports = function (/* environment, appConfig */) {
+ return {};
};
diff --git a/ember-cli-build.js b/ember-cli-build.js
index 6c4effc0..47e9fe9a 100644
--- a/ember-cli-build.js
+++ b/ember-cli-build.js
@@ -2,14 +2,11 @@
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
-module.exports = function(defaults) {
+module.exports = function (defaults) {
let app = new EmberAddon(defaults, {
svgJar: {
- sourceDirs: [
- 'public',
- 'tests/dummy/public'
- ]
- }
+ sourceDirs: ['public', 'tests/dummy/public'],
+ },
});
/*
diff --git a/fastboot-tests/adapter-test.js b/fastboot-tests/adapter-test.js
index 4b152c51..e79efdaf 100644
--- a/fastboot-tests/adapter-test.js
+++ b/fastboot-tests/adapter-test.js
@@ -3,7 +3,7 @@
const FastBoot = require('fastboot');
const { execFileSync } = require('child_process');
const { module: Qmodule, test } = require('qunit');
-const jsdom = require("jsdom");
+const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const postsRouter = require('../server/mocks/posts');
const express = require('express');
@@ -12,17 +12,17 @@ const express = require('express');
execFileSync('node', ['./node_modules/.bin/ember', 'build']);
let visitOptions = {
- request: { headers: { host: 'localhost:4201' } }
+ request: { headers: { host: 'localhost:4201' } },
};
-Qmodule('Fastboot', function(hooks) {
+Qmodule('Fastboot', function (hooks) {
let fastboot;
let server;
- hooks.before(async function() {
+ hooks.before(async function () {
fastboot = new FastBoot({
distPath: 'dist',
- resilient: false
+ resilient: false,
});
let app = express();
@@ -30,27 +30,35 @@ Qmodule('Fastboot', function(hooks) {
server = app.listen(4201);
});
- hooks.after(async function() {
+ hooks.after(async function () {
server.close();
});
- test('A fastboot rendered app should display loadRecords data fetched by the server', async function(assert) {
- let page = await fastboot.visit('/fastboot-tests/load-all-posts', visitOptions);
+ test('A fastboot rendered app should display loadRecords data fetched by the server', async function (assert) {
+ let page = await fastboot.visit(
+ '/fastboot-tests/load-all-posts',
+ visitOptions
+ );
let html = await page.html();
let dom = new JSDOM(html);
- let post1 = dom.window.document.querySelector('[data-test-id=post-title-1]');
+ let post1 = dom.window.document.querySelector(
+ '[data-test-id=post-title-1]'
+ );
assert.equal(post1.textContent.trim(), 'Hello from Ember CLI HTTP Mocks');
});
- test('A fastboot rendered app should put storefront loadRecords queries in the shoebox', async function(assert) {
- let page = await fastboot.visit('/fastboot-tests/load-all-posts', visitOptions);
+ test('A fastboot rendered app should put storefront loadRecords queries in the shoebox', async function (assert) {
+ let page = await fastboot.visit(
+ '/fastboot-tests/load-all-posts',
+ visitOptions
+ );
let html = await page.html();
let dom = new JSDOM(html);
- let shoebox = dom.window.document
- .querySelector('#shoebox-ember-data-storefront')
- .textContent;
+ let shoebox = dom.window.document.querySelector(
+ '#shoebox-ember-data-storefront'
+ ).textContent;
let cache = JSON.parse(shoebox);
let keys = Object.keys(cache.queries);
@@ -59,8 +67,11 @@ Qmodule('Fastboot', function(hooks) {
assert.ok(cache.queries['GET::/posts::filter[popular]=true']);
});
- test('A fastboot rendered app should display loadRecord data fetched by the server', async function(assert) {
- let page = await fastboot.visit('/fastboot-tests/load-record-post/1', visitOptions);
+ test('A fastboot rendered app should display loadRecord data fetched by the server', async function (assert) {
+ let page = await fastboot.visit(
+ '/fastboot-tests/load-record-post/1',
+ visitOptions
+ );
let html = await page.html();
let dom = new JSDOM(html);
let post1 = dom.window.document.querySelector('[data-test-id=post-title]');
@@ -68,14 +79,17 @@ Qmodule('Fastboot', function(hooks) {
assert.equal(post1.textContent.trim(), 'Hello from Ember CLI HTTP Mocks');
});
- test('A fastboot rendered app should put storefront loadRecords queries in the shoebox', async function(assert) {
- let page = await fastboot.visit('/fastboot-tests/load-record-post/1', visitOptions);
+ test('A fastboot rendered app should put storefront loadRecords queries in the shoebox', async function (assert) {
+ let page = await fastboot.visit(
+ '/fastboot-tests/load-record-post/1',
+ visitOptions
+ );
let html = await page.html();
let dom = new JSDOM(html);
- let shoebox = dom.window.document
- .querySelector('#shoebox-ember-data-storefront')
- .textContent;
+ let shoebox = dom.window.document.querySelector(
+ '#shoebox-ember-data-storefront'
+ ).textContent;
let cache = JSON.parse(shoebox);
let keys = Object.keys(cache.queries);
@@ -84,23 +98,31 @@ Qmodule('Fastboot', function(hooks) {
assert.ok(cache.queries['GET::/posts/1']);
});
- test('A fastboot rendered app should display findAll data fetched by the server', async function(assert) {
- let page = await fastboot.visit('/fastboot-tests/find-all-posts', visitOptions);
+ test('A fastboot rendered app should display findAll data fetched by the server', async function (assert) {
+ let page = await fastboot.visit(
+ '/fastboot-tests/find-all-posts',
+ visitOptions
+ );
let html = await page.html();
let dom = new JSDOM(html);
- let post1 = dom.window.document.querySelector('[data-test-id=post-title-1]');
+ let post1 = dom.window.document.querySelector(
+ '[data-test-id=post-title-1]'
+ );
assert.equal(post1.textContent.trim(), 'Hello from Ember CLI HTTP Mocks');
});
- test('A fastboot rendered app should put findAll queries in the shoebox', async function(assert) {
- let page = await fastboot.visit('/fastboot-tests/find-all-posts', visitOptions);
+ test('A fastboot rendered app should put findAll queries in the shoebox', async function (assert) {
+ let page = await fastboot.visit(
+ '/fastboot-tests/find-all-posts',
+ visitOptions
+ );
let html = await page.html();
let dom = new JSDOM(html);
- let shoebox = dom.window.document
- .querySelector('#shoebox-ember-data-storefront')
- .textContent;
+ let shoebox = dom.window.document.querySelector(
+ '#shoebox-ember-data-storefront'
+ ).textContent;
let cache = JSON.parse(shoebox);
let keys = Object.keys(cache.queries);
@@ -108,5 +130,4 @@ Qmodule('Fastboot', function(hooks) {
assert.equal(keys.length, 1);
assert.ok(cache.queries['GET::/posts::include=comments']);
});
-
});
diff --git a/fastboot/instance-initializers/ember-data-storefront.js b/fastboot/instance-initializers/ember-data-storefront.js
index 7c22d102..547ff988 100644
--- a/fastboot/instance-initializers/ember-data-storefront.js
+++ b/fastboot/instance-initializers/ember-data-storefront.js
@@ -1,7 +1,5 @@
export function initialize(applicationInstance) {
- let shoebox = applicationInstance
- .lookup('service:fastboot')
- .get('shoebox');
+ let shoebox = applicationInstance.lookup('service:fastboot').get('shoebox');
let storefront = applicationInstance.lookup('service:storefront');
@@ -11,11 +9,11 @@ export function initialize(applicationInstance) {
},
get queries() {
return storefront.get('fastbootDataRequests');
- }
+ },
});
}
export default {
name: 'ember-data-storefront',
- initialize
+ initialize,
};
diff --git a/index.js b/index.js
index e0e3d0f6..442b62d7 100644
--- a/index.js
+++ b/index.js
@@ -24,7 +24,7 @@ module.exports = {
}
this.app = app;
- this.addonConfig = this.app.project.config(app.env)['ember-data-storefront'] || {};
- }
-
+ this.addonConfig =
+ this.app.project.config(app.env)['ember-data-storefront'] || {};
+ },
};
diff --git a/package.json b/package.json
index f4bc0a3b..0f83b3fd 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "ember-data-storefront",
- "version": "0.18.1",
+ "version": "0.18.2-ember4.0",
"description": "Predictable data-loading APIs for Ember Data",
"keywords": [
"ember-addon"
diff --git a/server/.eslintrc.js b/server/.eslintrc.js
index 1147d299..1a4431d8 100644
--- a/server/.eslintrc.js
+++ b/server/.eslintrc.js
@@ -1,5 +1,5 @@
module.exports = {
env: {
- node: true
- }
+ node: true,
+ },
};
diff --git a/server/index.js b/server/index.js
index b4b418c6..fd379004 100644
--- a/server/index.js
+++ b/server/index.js
@@ -10,13 +10,13 @@
// });
// };
-module.exports = function(app) {
- const globSync = require('glob').sync;
- const mocks = globSync('./mocks/**/*.js', { cwd: __dirname }).map(require);
+module.exports = function (app) {
+ const globSync = require('glob').sync;
+ const mocks = globSync('./mocks/**/*.js', { cwd: __dirname }).map(require);
// Log proxy requests
const morgan = require('morgan');
app.use(morgan('dev'));
- mocks.forEach(route => route(app));
+ mocks.forEach((route) => route(app));
};
diff --git a/server/mocks/posts.js b/server/mocks/posts.js
index 20e75650..0b5c4909 100644
--- a/server/mocks/posts.js
+++ b/server/mocks/posts.js
@@ -1,33 +1,33 @@
/* eslint-env node */
'use strict';
-module.exports = function(app) {
+module.exports = function (app) {
const express = require('express');
let postsRouter = express.Router();
- postsRouter.get('/', function(req, res) {
+ postsRouter.get('/', function (req, res) {
res.send({
data: [
{
type: 'posts',
id: 1,
attributes: {
- title: 'Hello from Ember CLI HTTP Mocks'
- }
- }
- ]
+ title: 'Hello from Ember CLI HTTP Mocks',
+ },
+ },
+ ],
});
});
- postsRouter.get('/1', function(req, res) {
+ postsRouter.get('/1', function (req, res) {
res.send({
data: {
type: 'posts',
id: 1,
attributes: {
- title: 'Hello from Ember CLI HTTP Mocks'
- }
- }
+ title: 'Hello from Ember CLI HTTP Mocks',
+ },
+ },
});
});
diff --git a/testem.js b/testem.js
index 49f53fee..ed2f3712 100644
--- a/testem.js
+++ b/testem.js
@@ -3,12 +3,8 @@
module.exports = {
test_page: 'tests/index.html?hidepassed',
disable_watching: true,
- launch_in_ci: [
- 'Chrome'
- ],
- launch_in_dev: [
- 'Chrome'
- ],
+ launch_in_ci: ['Chrome'],
+ launch_in_dev: ['Chrome'],
browser_start_timeout: 120,
browser_args: {
Chrome: {
@@ -20,8 +16,8 @@ module.exports = {
'--disable-software-rasterizer',
'--mute-audio',
'--remote-debugging-port=0',
- '--window-size=1440,900'
- ].filter(Boolean)
- }
- }
+ '--window-size=1440,900',
+ ].filter(Boolean),
+ },
+ },
};
diff --git a/tests/acceptance/load-all-test.js b/tests/acceptance/load-all-test.js
index f4758f5d..ae9902e7 100644
--- a/tests/acceptance/load-all-test.js
+++ b/tests/acceptance/load-all-test.js
@@ -1,12 +1,10 @@
import { module, test } from 'qunit';
-import { visit, click, find, waitUntil } from "@ember/test-helpers";
+import { visit, click, find, waitUntil } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { startMirage } from 'dummy/initializers/ember-cli-mirage';
function t(...args) {
- return args
- .map(arg => `[data-test-id="${arg}"]`)
- .join(' ');
+ return args.map((arg) => `[data-test-id="${arg}"]`).join(' ');
}
async function domHasChanged(selector) {
@@ -15,23 +13,23 @@ async function domHasChanged(selector) {
let currentUi = find(selector).textContent;
return currentUi !== previousUi;
- })
+ });
}
-module('Acceptance | data fetching docs', function(hooks) {
+module('Acceptance | data fetching docs', function (hooks) {
let server;
setupApplicationTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
server = startMirage();
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
server.shutdown();
});
- test('data fetching guide', async function(assert) {
+ test('data fetching guide', async function (assert) {
// need our data fetching to be slow for these tests.
server.timing = 1000;
diff --git a/tests/acceptance/load-relationship-test.js b/tests/acceptance/load-relationship-test.js
index c6143a06..7ca5163b 100644
--- a/tests/acceptance/load-relationship-test.js
+++ b/tests/acceptance/load-relationship-test.js
@@ -3,23 +3,27 @@ import { visit, click } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import startMirage from 'dummy/tests/helpers/start-mirage';
-module('Acceptance | load relationship', function(hooks) {
+module('Acceptance | load relationship', function (hooks) {
setupApplicationTest(hooks);
startMirage(hooks);
- test('the load demo works', async function(assert) {
+ test('the load demo works', async function (assert) {
await visit('/docs/guides/working-with-relationships');
await click('[data-test-id=load-comments]');
- assert.dom('[data-test-id=load-comments-count]').hasText('The post has 3 comments.');
+ assert
+ .dom('[data-test-id=load-comments-count]')
+ .hasText('The post has 3 comments.');
});
- test('the sideload demo works', async function(assert) {
+ test('the sideload demo works', async function (assert) {
await visit('/docs/guides/working-with-relationships');
await click('[data-test-id=sideload-comments]');
- assert.dom('[data-test-id=sideload-comments-count]').hasText('The post has 5 comments.');
+ assert
+ .dom('[data-test-id=sideload-comments-count]')
+ .hasText('The post has 5 comments.');
});
});
diff --git a/tests/dummy/app/adapters/post.js b/tests/dummy/app/adapters/post.js
index fcb72482..fec94e45 100644
--- a/tests/dummy/app/adapters/post.js
+++ b/tests/dummy/app/adapters/post.js
@@ -1,8 +1,8 @@
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import FastbootAdapter from 'ember-data-storefront/mixins/fastboot-adapter';
-export default class PostAdapter extends JSONAPIAdapter.extend(FastbootAdapter) {
-
+export default class PostAdapter extends JSONAPIAdapter.extend(
+ FastbootAdapter
+) {
// namespace: 'foo'
-
}
diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js
index 07fdabfc..4e004cdd 100644
--- a/tests/dummy/app/app.js
+++ b/tests/dummy/app/app.js
@@ -16,7 +16,7 @@ export default class App extends Application {
// We'll ignore the empty tag name warning for test selectors since we have
// empty tag names for pass through components.
-registerWarnHandler(function(message, { id }, next) {
+registerWarnHandler(function (message, { id }, next) {
if (id !== 'ember-test-selectors.empty-tag-name') {
next(...arguments);
}
diff --git a/tests/dummy/app/models/author.js b/tests/dummy/app/models/author.js
index 8cdb72aa..43361375 100644
--- a/tests/dummy/app/models/author.js
+++ b/tests/dummy/app/models/author.js
@@ -5,5 +5,4 @@ export default class AuthorModel extends Model {
@hasMany() comments;
@belongsTo() post;
-
}
diff --git a/tests/dummy/app/models/comment.js b/tests/dummy/app/models/comment.js
index e77d353f..bcbb5e97 100644
--- a/tests/dummy/app/models/comment.js
+++ b/tests/dummy/app/models/comment.js
@@ -2,8 +2,6 @@ import ItemizableModel from './itemizable';
import { belongsTo } from '@ember-data/model';
export default class CommentModel extends ItemizableModel {
-
@belongsTo() post;
@belongsTo() author;
-
}
diff --git a/tests/dummy/app/models/homepage-item.js b/tests/dummy/app/models/homepage-item.js
index 0070f79b..f296211f 100644
--- a/tests/dummy/app/models/homepage-item.js
+++ b/tests/dummy/app/models/homepage-item.js
@@ -1,7 +1,5 @@
import Model, { belongsTo } from '@ember-data/model';
export default class HomepageItemModel extends Model {
-
@belongsTo({ polymorphic: true }) itemizable;
-
}
diff --git a/tests/dummy/app/models/itemizable.js b/tests/dummy/app/models/itemizable.js
index 3fc2658f..669befe2 100644
--- a/tests/dummy/app/models/itemizable.js
+++ b/tests/dummy/app/models/itemizable.js
@@ -1,9 +1,7 @@
import Model, { attr, hasMany } from '@ember-data/model';
export default class ItemizableModel extends Model {
-
@attr('string') text;
@hasMany() tags;
-
}
diff --git a/tests/dummy/app/models/post.js b/tests/dummy/app/models/post.js
index da9ff025..1dad4c0c 100644
--- a/tests/dummy/app/models/post.js
+++ b/tests/dummy/app/models/post.js
@@ -2,10 +2,8 @@ import ItemizableModel from './itemizable';
import { attr, belongsTo, hasMany } from '@ember-data/model';
export default class PostModel extends ItemizableModel {
-
@attr('string') title;
@belongsTo() author;
@hasMany() comments;
-
}
diff --git a/tests/dummy/app/models/tag.js b/tests/dummy/app/models/tag.js
index 882a3696..e0bc99ac 100644
--- a/tests/dummy/app/models/tag.js
+++ b/tests/dummy/app/models/tag.js
@@ -1,7 +1,5 @@
import Model, { hasMany } from '@ember-data/model';
export default class TagModel extends Model {
-
@hasMany() posts;
-
}
diff --git a/tests/dummy/app/pods/docs/guides/data-fetching/demo-1/component.js b/tests/dummy/app/pods/docs/guides/data-fetching/demo-1/component.js
index e41746e6..90ad462b 100644
--- a/tests/dummy/app/pods/docs/guides/data-fetching/demo-1/component.js
+++ b/tests/dummy/app/pods/docs/guides/data-fetching/demo-1/component.js
@@ -43,9 +43,9 @@ export default class Demo1Component extends Component {
// route
model() {
return this.store.findRecord('post', 1);
- }
+ },
// END-SNIPPET
- }
+ },
};
}
diff --git a/tests/dummy/app/pods/docs/guides/data-fetching/demo-2/component.js b/tests/dummy/app/pods/docs/guides/data-fetching/demo-2/component.js
index ba667be2..7ceb6222 100644
--- a/tests/dummy/app/pods/docs/guides/data-fetching/demo-2/component.js
+++ b/tests/dummy/app/pods/docs/guides/data-fetching/demo-2/component.js
@@ -35,7 +35,7 @@ export default class Demo2Component extends Component {
// route
model() {
return this.store.loadRecords('post');
- }
+ },
// END-SNIPPET
},
'/posts/1': {
@@ -43,9 +43,9 @@ export default class Demo2Component extends Component {
// route
model() {
return this.store.loadRecord('post', 1);
- }
+ },
// END-SNIPPET
- }
+ },
};
}
diff --git a/tests/dummy/app/pods/docs/guides/working-with-relationships/demo-1/component.js b/tests/dummy/app/pods/docs/guides/working-with-relationships/demo-1/component.js
index d14b9a55..672a0dad 100644
--- a/tests/dummy/app/pods/docs/guides/working-with-relationships/demo-1/component.js
+++ b/tests/dummy/app/pods/docs/guides/working-with-relationships/demo-1/component.js
@@ -25,9 +25,9 @@ export default class DocsDemo1Component extends Component {
setup() {
let tasks = {
// BEGIN-SNIPPET working-with-relationships-demo-1.js
- loadComments: task(function*() {
+ loadComments: task(function* () {
yield this.post.load('comments');
- })
+ }),
// END-SNIPPET
};
diff --git a/tests/dummy/app/pods/docs/guides/working-with-relationships/demo-2/component.js b/tests/dummy/app/pods/docs/guides/working-with-relationships/demo-2/component.js
index 862a5f1c..7e72948b 100644
--- a/tests/dummy/app/pods/docs/guides/working-with-relationships/demo-2/component.js
+++ b/tests/dummy/app/pods/docs/guides/working-with-relationships/demo-2/component.js
@@ -25,9 +25,9 @@ export default class DocsDemo2Component extends Component {
setup() {
let tasks = {
// BEGIN-SNIPPET working-with-relationships-demo-2.js
- sideloadComments: task(function*() {
+ sideloadComments: task(function* () {
yield this.post.sideload('comments');
- })
+ }),
// END-SNIPPET
};
diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js
index 58195468..30fb221a 100644
--- a/tests/dummy/app/router.js
+++ b/tests/dummy/app/router.js
@@ -6,9 +6,9 @@ export default class Router extends EmberRouter {
rootURL = config.rootURL;
}
-Router.map(function() {
- this.route('docs', function() {
- this.route('guides', function() {
+Router.map(function () {
+ this.route('docs', function () {
+ this.route('guides', function () {
this.route('data-fetching');
this.route('working-with-relationships');
this.route('avoiding-errors');
@@ -16,12 +16,12 @@ Router.map(function() {
this.route('common-data-issues');
});
- this.route('api', function() {
+ this.route('api', function () {
this.route('item', { path: '/*path' });
});
});
- this.route('fastboot-tests', function() {
+ this.route('fastboot-tests', function () {
this.route('load-all-posts');
this.route('load-record-post', { path: 'load-record-post/:post_id' });
this.route('find-all-posts');
diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js
index 9359eed8..42a97e72 100644
--- a/tests/dummy/config/environment.js
+++ b/tests/dummy/config/environment.js
@@ -1,6 +1,6 @@
'use strict';
-module.exports = function(environment) {
+module.exports = function (environment) {
let ENV = {
modulePrefix: 'dummy',
podModulePrefix: 'dummy/pods',
@@ -14,8 +14,8 @@ module.exports = function(environment) {
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
- Date: false
- }
+ Date: false,
+ },
},
APP: {
@@ -26,12 +26,12 @@ module.exports = function(environment) {
historySupportMiddleware: true,
'ember-cli-mirage': {
- enabled: true
+ enabled: true,
},
fastboot: {
- hostWhitelist: [/^localhost:\d+$/]
- }
+ hostWhitelist: [/^localhost:\d+$/],
+ },
};
if (environment === 'development') {
@@ -54,7 +54,7 @@ module.exports = function(environment) {
ENV.APP.autoboot = false;
ENV['ember-cli-mirage'] = {
- enabled: false
+ enabled: false,
};
}
diff --git a/tests/dummy/config/targets.js b/tests/dummy/config/targets.js
index f0d3303f..70922d33 100644
--- a/tests/dummy/config/targets.js
+++ b/tests/dummy/config/targets.js
@@ -3,7 +3,7 @@
const browsers = [
'last 2 Chrome versions',
'last 2 Firefox versions',
- 'last 2 Safari versions'
+ 'last 2 Safari versions',
];
// Ember's browser support policy is changing, and IE11 support will end in
@@ -22,5 +22,5 @@ const browsers = [
// }
module.exports = {
- browsers
+ browsers,
};
diff --git a/tests/dummy/mirage/config.js b/tests/dummy/mirage/config.js
index 78016eb9..f4e63e6b 100644
--- a/tests/dummy/mirage/config.js
+++ b/tests/dummy/mirage/config.js
@@ -1,7 +1,9 @@
-let genericRelationshipRouteHandler = function(schema, request) {
- let collectionName = request.url.split('/').filter(part => part !== '')[0];
+let genericRelationshipRouteHandler = function (schema, request) {
+ let collectionName = request.url.split('/').filter((part) => part !== '')[0];
let relationship = request.params.relationship;
- let modelOrCollection = schema[collectionName].find(request.params.id)[relationship];
+ let modelOrCollection = schema[collectionName].find(request.params.id)[
+ relationship
+ ];
if (modelOrCollection) {
return modelOrCollection;
@@ -10,16 +12,19 @@ let genericRelationshipRouteHandler = function(schema, request) {
}
};
-export default function() {
+export default function () {
window.server = this;
this.get('posts', {
- timing: 1000
+ timing: 1000,
});
this.get('/posts/:id');
- this.get('/posts/:id/relationships/:relationship', genericRelationshipRouteHandler);
+ this.get(
+ '/posts/:id/relationships/:relationship',
+ genericRelationshipRouteHandler
+ );
this.passthrough();
}
diff --git a/tests/dummy/mirage/factories/comment.js b/tests/dummy/mirage/factories/comment.js
index 85018979..e6cb357d 100644
--- a/tests/dummy/mirage/factories/comment.js
+++ b/tests/dummy/mirage/factories/comment.js
@@ -1,4 +1,3 @@
import { Factory } from 'ember-cli-mirage';
-export default Factory.extend({
-});
+export default Factory.extend({});
diff --git a/tests/dummy/mirage/factories/post.js b/tests/dummy/mirage/factories/post.js
index 850e5177..af0424e4 100644
--- a/tests/dummy/mirage/factories/post.js
+++ b/tests/dummy/mirage/factories/post.js
@@ -6,7 +6,7 @@ export default Factory.extend({
return `The title for post #${i + 1}`;
},
- text: "This is the text of the post.",
+ text: 'This is the text of the post.',
afterCreate(post) {
post.update({ slug: dasherize(post.title) });
@@ -15,6 +15,6 @@ export default Factory.extend({
withComments: trait({
afterCreate(post, server) {
server.createList('comment', 3, { post });
- }
- })
+ },
+ }),
});
diff --git a/tests/dummy/mirage/scenarios/default.js b/tests/dummy/mirage/scenarios/default.js
index 15019f53..002ac895 100644
--- a/tests/dummy/mirage/scenarios/default.js
+++ b/tests/dummy/mirage/scenarios/default.js
@@ -1,18 +1,18 @@
/*eslint no-console: ["error", { allow: ["log"] }] */
-export default function(server) {
+export default function (server) {
window.server = server;
server.create('post', {
id: 1,
title: 'Lorem',
- comments: server.createList('comment', 3)
+ comments: server.createList('comment', 3),
});
server.create('post', {
id: 2,
title: 'Lorem',
- comments: server.createList('comment', 5)
+ comments: server.createList('comment', 5),
});
server.create('post', { title: 'Ipsum' });
diff --git a/tests/dummy/mirage/serializers/application.js b/tests/dummy/mirage/serializers/application.js
index a2c1aab4..c0995ab1 100644
--- a/tests/dummy/mirage/serializers/application.js
+++ b/tests/dummy/mirage/serializers/application.js
@@ -1,7 +1,5 @@
import { JSONAPISerializer } from 'ember-cli-mirage';
export default class ApplicationSerializer extends JSONAPISerializer {
-
alwaysIncludeLinkageData = false;
-
}
diff --git a/tests/dummy/mirage/serializers/post.js b/tests/dummy/mirage/serializers/post.js
index 2eaf962b..c02e7e31 100644
--- a/tests/dummy/mirage/serializers/post.js
+++ b/tests/dummy/mirage/serializers/post.js
@@ -1,16 +1,14 @@
import ApplicationSerializer from './application';
export default class PostSerializer extends ApplicationSerializer {
-
links(model) {
return {
author: {
- related: `/posts/${model.id}/relationships/author`
+ related: `/posts/${model.id}/relationships/author`,
},
comments: {
- related: `/posts/${model.id}/relationships/comments`
- }
+ related: `/posts/${model.id}/relationships/comments`,
+ },
};
}
-
}
diff --git a/tests/helpers/start-mirage.js b/tests/helpers/start-mirage.js
index 50b4cb29..279ac9e1 100644
--- a/tests/helpers/start-mirage.js
+++ b/tests/helpers/start-mirage.js
@@ -1,13 +1,13 @@
import { startMirage } from 'dummy/initializers/ember-cli-mirage';
import scenario from 'dummy/mirage/scenarios/default';
-export default function(hooks) {
- hooks.beforeEach(function() {
+export default function (hooks) {
+ hooks.beforeEach(function () {
this.server = startMirage();
scenario(this.server);
- })
+ });
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
this.server.shutdown();
});
}
diff --git a/tests/integration/-private/cache-test.js b/tests/integration/-private/cache-test.js
index 4c94cdd6..126fb985 100644
--- a/tests/integration/-private/cache-test.js
+++ b/tests/integration/-private/cache-test.js
@@ -2,18 +2,18 @@ import { module, test } from 'qunit';
import Cache from 'ember-data-storefront/-private/cache';
import RecordQuery from 'ember-data-storefront/-private/record-query';
-module('Integration | Cache test', function(hooks) {
- hooks.beforeEach(function() {
+module('Integration | Cache test', function (hooks) {
+ hooks.beforeEach(function () {
this.mockStore = {
- peekRecord() {}
+ peekRecord() {},
};
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
delete this.mockStore;
});
- test('it can store a query with no params', function(assert) {
+ test('it can store a query with no params', function (assert) {
let cache = new Cache();
let query = new RecordQuery(this.mockStore, 'post', 1);
@@ -22,10 +22,10 @@ module('Integration | Cache test', function(hooks) {
assert.equal(cache.get('post', 1), query);
});
- test('it can store a query with simple params', function(assert) {
+ test('it can store a query with simple params', function (assert) {
let cache = new Cache();
let query = new RecordQuery(this.mockStore, 'post', 1, {
- testing: 123
+ testing: 123,
});
cache.put(query);
@@ -33,28 +33,28 @@ module('Integration | Cache test', function(hooks) {
assert.equal(cache.get('post', 1, { testing: 123 }), query);
});
- test("the order of the params doesn't matter", function(assert) {
+ test("the order of the params doesn't matter", function (assert) {
let cache = new Cache();
let query = new RecordQuery(this.mockStore, 'post', 1, {
key1: 'A',
- key2: 'B'
+ key2: 'B',
});
cache.put(query);
let cachedQuery = cache.get('post', 1, {
key2: 'B',
- key1: 'A'
+ key1: 'A',
});
assert.equal(cachedQuery, query);
});
- test('it can store a query with nested params', function(assert) {
+ test('it can store a query with nested params', function (assert) {
let cache = new Cache();
let query = new RecordQuery(this.mockStore, 'post', 1, {
filter: {
- testing: 123
- }
+ testing: 123,
+ },
});
cache.put(query);
@@ -62,11 +62,11 @@ module('Integration | Cache test', function(hooks) {
assert.equal(cache.get('post', 1, { filter: { testing: 123 } }), query);
});
- test('it can store a query with boolean params', function(assert) {
+ test('it can store a query with boolean params', function (assert) {
let cache = new Cache();
let query = new RecordQuery(this.mockStore, 'post', 1, {
foo: true,
- bar: false
+ bar: false,
});
cache.put(query);
@@ -74,7 +74,7 @@ module('Integration | Cache test', function(hooks) {
assert.equal(cache.get('post', 1, { foo: true, bar: false }), query);
});
- test('it should be able to get all queries out of the cache', function(assert) {
+ test('it should be able to get all queries out of the cache', function (assert) {
let cache = new Cache();
let query1 = new RecordQuery(this.mockStore, 'post', 1);
let query2 = new RecordQuery(this.mockStore, 'post', 2);
@@ -84,5 +84,4 @@ module('Integration | Cache test', function(hooks) {
assert.deepEqual(cache.all(), [query1, query2]);
});
-
});
diff --git a/tests/integration/changing-data-render-test.js b/tests/integration/changing-data-render-test.js
index 6ee811dd..9c292855 100644
--- a/tests/integration/changing-data-render-test.js
+++ b/tests/integration/changing-data-render-test.js
@@ -6,32 +6,32 @@ import MirageServer from 'dummy/tests/integration/helpers/mirage-server';
import { Model } from 'ember-cli-mirage';
import LoadableStore from 'ember-data-storefront/mixins/loadable-store';
-module('Integration | Changing data render test', function(hooks) {
+module('Integration | Changing data render test', function (hooks) {
setupRenderingTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
this.server = new MirageServer({
models: {
- post: Model.extend()
+ post: Model.extend(),
},
baseConfig() {
this.resource('posts');
- }
+ },
});
- this.store = this.owner.lookup('service:store')
+ this.store = this.owner.lookup('service:store');
this.store.reopen(LoadableStore);
this.store.resetCache();
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
this.server.shutdown();
});
- test('record queries trigger template rerenders', async function(assert) {
+ test('record queries trigger template rerenders', async function (assert) {
let serverPost = this.server.create('post', { title: 'Lorem' });
let postId = serverPost.id;
- await this.store.loadRecord('post', postId).then(post => {
+ await this.store.loadRecord('post', postId).then((post) => {
this.set('model', post);
});
@@ -51,10 +51,10 @@ module('Integration | Changing data render test', function(hooks) {
assert.dom('[data-test-title]').hasText('ipsum');
});
- test('record array queries trigger template rerenders', async function(assert) {
+ test('record array queries trigger template rerenders', async function (assert) {
this.server.createList('post', 2);
- await this.store.loadRecords('post').then(posts => {
+ await this.store.loadRecords('post').then((posts) => {
this.set('model', posts);
});
@@ -69,7 +69,7 @@ module('Integration | Changing data render test', function(hooks) {
assert.dom('li').exists({ count: 2 });
this.server.create('post');
- await this.get('model').update();
+ await this.model.update();
await settled();
assert.dom('li').exists({ count: 3 });
diff --git a/tests/integration/components/assert-must-preload-test.js b/tests/integration/components/assert-must-preload-test.js
index 0e7c09b5..843a7630 100644
--- a/tests/integration/components/assert-must-preload-test.js
+++ b/tests/integration/components/assert-must-preload-test.js
@@ -9,7 +9,7 @@ import LoadableStore from 'ember-data-storefront/mixins/loadable-store';
import Ember from 'ember';
import Model from '@ember-data/model';
-module('Integration | Component | assert must preload', function(hooks) {
+module('Integration | Component | assert must preload', function (hooks) {
setupRenderingTest(hooks);
// keep an eye on this issue:
@@ -18,14 +18,14 @@ module('Integration | Component | assert must preload', function(hooks) {
let adapterException;
let loggerError;
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
Model.reopen(LoadableModel);
- this.store = this.owner.lookup('service:store')
+ this.store = this.owner.lookup('service:store');
this.store.reopen(LoadableStore);
this.store.resetCache();
this.server = startMirage();
onerror = Ember.onerror;
- adapterException = Ember.Test.adapter.exception
+ adapterException = Ember.Test.adapter.exception;
loggerError = Ember.Logger.error;
// the next line doesn't work in 2.x due to an eslint rule
@@ -37,34 +37,35 @@ module('Integration | Component | assert must preload', function(hooks) {
let post = this.server.create('post', {
id: 1,
title: 'Post title',
- author
+ author,
});
let comments = this.server.createList('comment', 3, { post });
- comments.forEach(comment => {
+ comments.forEach((comment) => {
server.create('author', { comments: [comment] });
});
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
Ember.onerror = onerror;
Ember.Test.adapter.exception = adapterException;
Ember.Logger.error = loggerError;
this.server.shutdown();
});
- test('it errors if the relationship has not yet be loaded', async function(assert) {
+ test('it errors if the relationship has not yet be loaded', async function (assert) {
this.post = await run(() => {
return this.store.loadRecord('post', 1);
});
- let assertError = function(e) {
- let regexp = /You tried to render a .+ that accesses relationships off of a post, but that model didn't have all of its required relationships preloaded ('comments')*/;
+ let assertError = function (e) {
+ let regexp =
+ /You tried to render a .+ that accesses relationships off of a post, but that model didn't have all of its required relationships preloaded ('comments')*/;
assert.ok(e.message.match(regexp));
};
- if (this.major === "2" && (this.minor === "12" || this.minor === "16")) {
- Ember.Logger.error = function() {};
+ if (this.major === '2' && (this.minor === '12' || this.minor === '16')) {
+ Ember.Logger.error = function () {};
Ember.Test.adapter.exception = assertError;
} else {
Ember.onerror = assertError;
@@ -75,18 +76,19 @@ module('Integration | Component | assert must preload', function(hooks) {
`);
});
- test('it errors if one of the relationships has not yet be loaded', async function(assert) {
+ test('it errors if one of the relationships has not yet be loaded', async function (assert) {
this.post = await run(() => {
return this.store.loadRecord('post', 1, { include: 'author' });
});
- let assertError = function(e) {
- let regexp = /You tried to render a .+ that accesses relationships off of a post, but that model didn't have all of its required relationships preloaded ('comments')*/;
+ let assertError = function (e) {
+ let regexp =
+ /You tried to render a .+ that accesses relationships off of a post, but that model didn't have all of its required relationships preloaded ('comments')*/;
assert.ok(e.message.match(regexp));
};
- if (this.major === "2" && (this.minor === "12" || this.minor === "16")) {
- Ember.Logger.error = function() {};
+ if (this.major === '2' && (this.minor === '12' || this.minor === '16')) {
+ Ember.Logger.error = function () {};
Ember.Test.adapter.exception = assertError;
} else {
Ember.onerror = assertError;
@@ -97,18 +99,19 @@ module('Integration | Component | assert must preload', function(hooks) {
`);
});
- test('it errors if a nested relationship has not yet be loaded', async function(assert) {
+ test('it errors if a nested relationship has not yet be loaded', async function (assert) {
this.post = await run(() => {
return this.store.loadRecord('post', 1, { include: 'comments' });
});
- let assertError = function(e) {
- let regexp = /You tried to render a .+ that accesses relationships off of a post, but that model didn't have all of its required relationships preloaded ('comments.author')*/;
+ let assertError = function (e) {
+ let regexp =
+ /You tried to render a .+ that accesses relationships off of a post, but that model didn't have all of its required relationships preloaded ('comments.author')*/;
assert.ok(e.message.match(regexp));
};
- if (this.major === "2" && (this.minor === "12" || this.minor === "16")) {
- Ember.Logger.error = function() {};
+ if (this.major === '2' && (this.minor === '12' || this.minor === '16')) {
+ Ember.Logger.error = function () {};
Ember.Test.adapter.exception = assertError;
} else {
Ember.onerror = assertError;
@@ -119,7 +122,7 @@ module('Integration | Component | assert must preload', function(hooks) {
`);
});
- test('it does not error if the relationship was loaded', async function(assert) {
+ test('it does not error if the relationship was loaded', async function (assert) {
this.post = await run(() => {
return this.store.loadRecord('post', 1, { include: 'comments' });
});
@@ -132,8 +135,8 @@ module('Integration | Component | assert must preload', function(hooks) {
assert.dom('*').hasText('');
});
- module('Data loaded with loadRecords', function() {
- test('it should not error when all data is loaded', async function(assert) {
+ module('Data loaded with loadRecords', function () {
+ test('it should not error when all data is loaded', async function (assert) {
let posts = await run(() => {
return this.store.loadRecords('post', { include: 'comments' });
});
@@ -148,23 +151,24 @@ module('Integration | Component | assert must preload', function(hooks) {
`);
- assert.dom('[data-test-id="title"]').hasText("Post title");
+ assert.dom('[data-test-id="title"]').hasText('Post title');
});
- test('it should error is not all data is loaded', async function(assert) {
+ test('it should error is not all data is loaded', async function (assert) {
let posts = await run(() => {
return this.store.loadRecords('post', { include: 'comments,author' });
});
this.post = posts.get('firstObject');
- let assertError = function(e) {
- let regexp = /You tried to render a .+ that accesses relationships off of a post, but that model didn't have all of its required relationships preloaded ('comments.author')*/;
+ let assertError = function (e) {
+ let regexp =
+ /You tried to render a .+ that accesses relationships off of a post, but that model didn't have all of its required relationships preloaded ('comments.author')*/;
assert.ok(e.message.match(regexp));
};
- if (this.major === "2" && (this.minor === "12" || this.minor === "16")) {
- Ember.Logger.error = function() {};
+ if (this.major === '2' && (this.minor === '12' || this.minor === '16')) {
+ Ember.Logger.error = function () {};
Ember.Test.adapter.exception = assertError;
} else {
Ember.onerror = assertError;
@@ -175,5 +179,4 @@ module('Integration | Component | assert must preload', function(hooks) {
`);
});
});
-
});
diff --git a/tests/integration/components/load-records-example-test.js b/tests/integration/components/load-records-example-test.js
index 49a5e182..0801551e 100644
--- a/tests/integration/components/load-records-example-test.js
+++ b/tests/integration/components/load-records-example-test.js
@@ -7,30 +7,33 @@ import { inject as service } from '@ember/service';
import Model from '@ember-data/model';
import { startMirage } from 'dummy/initializers/ember-cli-mirage';
-module('Integration | Component | Load records example', function(hooks) {
+module('Integration | Component | Load records example', function (hooks) {
setupRenderingTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
this.owner.register('model:user', class extends Model {});
- this.owner.register('component:load-records', class extends Component {
- @service store;
- constructor() {
- super(...arguments);
+ this.owner.register(
+ 'component:load-records',
+ class extends Component {
+ @service store;
+ constructor() {
+ super(...arguments);
- const { modelName, params } = this.args
- this.store.loadRecords(modelName, { ...params });
+ const { modelName, params } = this.args;
+ this.store.loadRecords(modelName, { ...params });
+ }
}
- });
+ );
this.server = startMirage();
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
this.server.shutdown();
});
// This ensures users can write a component. See https://github.com/embermap/ember-data-storefront/issues/79.
- test('users should be able to invoke #loadRecords using a hash from a template', async function(assert) {
- this.server.get('/users', () => ({ data: []}));
+ test('users should be able to invoke #loadRecords using a hash from a template', async function (assert) {
+ this.server.get('/users', () => ({ data: [] }));
await render(hbs`
{
- return this.store.findRecord('post', 1)
+ return this.store.findRecord('post', 1);
});
- assert.throws(
- () => { post.load('comments.author'); },
- /The #load method only works with a single relationship/
- );
+ assert.throws(() => {
+ post.load('comments.author');
+ }, /The #load method only works with a single relationship/);
});
- test('#load errors when given a relationship name that does not exist', async function(assert) {
+ test('#load errors when given a relationship name that does not exist', async function (assert) {
let post = await run(() => {
- return this.store.findRecord('post', 1)
+ return this.store.findRecord('post', 1);
});
- assert.throws(
- () => { post.load('citations'); },
- /You tried to load the relationship citations for a post, but that relationship does not exist/
- );
+ assert.throws(() => {
+ post.load('citations');
+ }, /You tried to load the relationship citations for a post, but that relationship does not exist/);
});
- test('#load can load a belongsTo relationship', async function(assert) {
+ test('#load can load a belongsTo relationship', async function (assert) {
let requests = [];
- server.pretender.handledRequest = function(...args) {
+ server.pretender.handledRequest = function (...args) {
requests.push(args[2]);
};
@@ -66,9 +63,9 @@ module('Integration | Mixins | LoadableModel | load', function(hooks) {
assert.equal(requests[1].url, '/posts/1/relationships/author');
});
- test('#load can load a hasMany relationship', async function(assert) {
+ test('#load can load a hasMany relationship', async function (assert) {
let requests = [];
- server.pretender.handledRequest = function(...args) {
+ server.pretender.handledRequest = function (...args) {
requests.push(args[2]);
};
@@ -82,10 +79,10 @@ module('Integration | Mixins | LoadableModel | load', function(hooks) {
assert.equal(requests[1].url, '/posts/1/relationships/comments');
});
- test('#load should not use a blocking fetch if the relationship has already been loaded', async function(assert) {
+ test('#load should not use a blocking fetch if the relationship has already been loaded', async function (assert) {
let requests = [];
- server.pretender.handledRequest = function(...args) {
+ server.pretender.handledRequest = function (...args) {
requests.push(args[2]);
};
@@ -109,13 +106,15 @@ module('Integration | Mixins | LoadableModel | load', function(hooks) {
await waitUntil(() => requests.length === 2, { timeout: 5000 });
});
- test('#load should use a blocking fetch if the relationship has already been loaded, but the reload option is true', async function(assert) {
+ test('#load should use a blocking fetch if the relationship has already been loaded, but the reload option is true', async function (assert) {
let requests = [];
- server.pretender.handledRequest = function(...args) {
+ server.pretender.handledRequest = function (...args) {
requests.push(args[2]);
};
- let post = await run(() => this.store.findRecord('post', 1, { include: 'comments' }));
+ let post = await run(() =>
+ this.store.findRecord('post', 1, { include: 'comments' })
+ );
assert.equal(post.hasMany('comments').value().length, 2);
let comments = await run(() => {
@@ -127,10 +126,10 @@ module('Integration | Mixins | LoadableModel | load', function(hooks) {
assert.equal(requests[1].url, '/posts/1/relationships/comments');
});
- test('#load should not make a network request if the relationship is loaded, but backgroundReload is false', async function(assert) {
+ test('#load should not make a network request if the relationship is loaded, but backgroundReload is false', async function (assert) {
let requests = [];
- server.pretender.handledRequest = function(...args) {
+ server.pretender.handledRequest = function (...args) {
requests.push(args[2]);
};
@@ -147,14 +146,14 @@ module('Integration | Mixins | LoadableModel | load', function(hooks) {
assert.equal(requests.length, 1);
// wait 500ms and make sure there's no network request
- await new Promise(resolve => setTimeout(resolve, 500));
+ await new Promise((resolve) => setTimeout(resolve, 500));
assert.equal(requests.length, 1);
});
- test('#load should make a network request if the relationship has not been loaded, but the backgroundReload option is false', async function(assert) {
+ test('#load should make a network request if the relationship has not been loaded, but the backgroundReload option is false', async function (assert) {
let requests = [];
- server.pretender.handledRequest = function(...args) {
+ server.pretender.handledRequest = function (...args) {
requests.push(args[2]);
};
@@ -170,7 +169,7 @@ module('Integration | Mixins | LoadableModel | load', function(hooks) {
assert.equal(requests[1].url, '/posts/1/relationships/comments');
});
- test('#load should update the reference from an earlier load call', async function(assert) {
+ test('#load should update the reference from an earlier load call', async function (assert) {
let post = await run(() => this.store.findRecord('post', 1));
let comments = await run(() => post.load('comments'));
@@ -183,5 +182,4 @@ module('Integration | Mixins | LoadableModel | load', function(hooks) {
assert.equal(comments.length, 2);
await waitUntil(() => comments.length === 3);
});
-
});
diff --git a/tests/integration/mixins/loadable-model/sideload-test.js b/tests/integration/mixins/loadable-model/sideload-test.js
index 55b24632..73135726 100644
--- a/tests/integration/mixins/loadable-model/sideload-test.js
+++ b/tests/integration/mixins/loadable-model/sideload-test.js
@@ -6,10 +6,10 @@ import { startMirage } from 'dummy/initializers/ember-cli-mirage';
import LoadableModel from 'ember-data-storefront/mixins/loadable-model';
import LoadableStore from 'ember-data-storefront/mixins/loadable-store';
-module('Integration | Mixins | LoadableModel | sideload', function(hooks) {
+module('Integration | Mixins | LoadableModel | sideload', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
Model.reopen(LoadableModel);
this.server = startMirage();
@@ -21,19 +21,18 @@ module('Integration | Mixins | LoadableModel | sideload', function(hooks) {
let post = server.create('post', { id: 1, author });
server.createList('comment', 2, { post, author });
}),
+ hooks.afterEach(function () {
+ this.server.shutdown();
+ this.store = null;
+ });
- hooks.afterEach(function() {
- this.server.shutdown();
- this.store = null;
- });
-
- test('#sideload can load includes', async function(assert) {
+ test('#sideload can load includes', async function (assert) {
let requests = [];
- server.pretender.handledRequest = function(...args) {
+ server.pretender.handledRequest = function (...args) {
requests.push(args[2]);
};
- let post = await this.store.findRecord('post', 1)
+ let post = await this.store.findRecord('post', 1);
assert.equal(post.hasMany('comments').value(), null);
@@ -44,11 +43,13 @@ module('Integration | Mixins | LoadableModel | sideload', function(hooks) {
assert.equal(requests[1].url, '/posts/1?include=comments');
});
- test('#sideload returns a resolved promise if its already loaded includes, and reloads in the background', async function(assert) {
+ test('#sideload returns a resolved promise if its already loaded includes, and reloads in the background', async function (assert) {
let serverCalls = 0;
- server.pretender.handledRequest = function() { serverCalls++ };
+ server.pretender.handledRequest = function () {
+ serverCalls++;
+ };
- let post = await this.store.findRecord('post', 1)
+ let post = await this.store.findRecord('post', 1);
assert.equal(serverCalls, 1);
@@ -71,12 +72,12 @@ module('Integration | Mixins | LoadableModel | sideload', function(hooks) {
assert.equal(post.hasMany('comments').value().get('length'), 3);
});
- test('#sideload can take multiple arguments', async function(assert) {
+ test('#sideload can take multiple arguments', async function (assert) {
let tag = server.create('tag');
let miragePost = this.server.schema.posts.find(1);
- miragePost.update({ tags: [ tag ]});
+ miragePost.update({ tags: [tag] });
- let post = await this.store.findRecord('post', 1)
+ let post = await this.store.findRecord('post', 1);
await post.sideload('comments', 'tags');
@@ -84,9 +85,11 @@ module('Integration | Mixins | LoadableModel | sideload', function(hooks) {
assert.equal(post.hasMany('tags').value().get('length'), 1);
});
- test('#sideload can take options, like reload: true', async function(assert) {
+ test('#sideload can take options, like reload: true', async function (assert) {
let serverCalls = 0;
- server.pretender.handledRequest = function() { serverCalls++ };
+ server.pretender.handledRequest = function () {
+ serverCalls++;
+ };
let post = await this.store.findRecord('post', 1, { include: 'comments' });
@@ -97,10 +100,10 @@ module('Integration | Mixins | LoadableModel | sideload', function(hooks) {
assert.equal(serverCalls, 2);
});
- test('#sideload should not make a network request if the relationship is loaded, but backgroundReload is false', async function(assert) {
+ test('#sideload should not make a network request if the relationship is loaded, but backgroundReload is false', async function (assert) {
let requests = [];
- server.pretender.handledRequest = function(...args) {
+ server.pretender.handledRequest = function (...args) {
requests.push(args[2]);
};
@@ -113,9 +116,8 @@ module('Integration | Mixins | LoadableModel | sideload', function(hooks) {
assert.equal(requests.length, 1);
// wait 500ms and make sure there's no network request
- await new Promise(resolve => setTimeout(resolve, 500));
+ await new Promise((resolve) => setTimeout(resolve, 500));
assert.equal(requests.length, 1);
});
-
});
diff --git a/tests/integration/mixins/loadable-store/has-loaded-includes-for-record-test.js b/tests/integration/mixins/loadable-store/has-loaded-includes-for-record-test.js
index b0dd8d86..f309fcf3 100644
--- a/tests/integration/mixins/loadable-store/has-loaded-includes-for-record-test.js
+++ b/tests/integration/mixins/loadable-store/has-loaded-includes-for-record-test.js
@@ -5,61 +5,68 @@ import MirageServer from 'dummy/tests/integration/helpers/mirage-server';
import { run } from '@ember/runloop';
import LoadableStore from 'ember-data-storefront/mixins/loadable-store';
-module('Integration | Mixins | LoadableStore | hasLoadedIncludesForRecord', function(hooks) {
- setupTest(hooks);
+module(
+ 'Integration | Mixins | LoadableStore | hasLoadedIncludesForRecord',
+ function (hooks) {
+ setupTest(hooks);
- hooks.beforeEach(function() {
- this.server = new MirageServer({
- models: {
- // eslint-disable-next-line ember/no-new-mixins
- post: Model.extend({
- comments: hasMany(),
- tags: hasMany()
- }),
- // eslint-disable-next-line ember/no-new-mixins
- comment: Model.extend({
- post: belongsTo()
- }),
- // eslint-disable-next-line ember/no-new-mixins
- tag: Model.extend({
- posts: hasMany()
- })
- },
- baseConfig() {
- this.resource('posts');
- }
- });
+ hooks.beforeEach(function () {
+ this.server = new MirageServer({
+ models: {
+ // eslint-disable-next-line ember/no-new-mixins
+ post: Model.extend({
+ comments: hasMany(),
+ tags: hasMany(),
+ }),
+ // eslint-disable-next-line ember/no-new-mixins
+ comment: Model.extend({
+ post: belongsTo(),
+ }),
+ // eslint-disable-next-line ember/no-new-mixins
+ tag: Model.extend({
+ posts: hasMany(),
+ }),
+ },
+ baseConfig() {
+ this.resource('posts');
+ },
+ });
- this.store = this.owner.lookup('service:store')
- this.store.reopen(LoadableStore);
- this.store.resetCache();
- });
+ this.store = this.owner.lookup('service:store');
+ this.store.reopen(LoadableStore);
+ this.store.resetCache();
+ });
- hooks.afterEach(function() {
- this.server.shutdown();
- });
+ hooks.afterEach(function () {
+ this.server.shutdown();
+ });
- test('it returns true if the relationship has been loaded', async function(assert) {
- let serverPost = this.server.create('post');
- this.server.createList('comment', 3, { post: serverPost });
+ test('it returns true if the relationship has been loaded', async function (assert) {
+ let serverPost = this.server.create('post');
+ this.server.createList('comment', 3, { post: serverPost });
- await run(() => {
- return this.store.loadRecord('post', serverPost.id, {
- include: 'comments'
+ await run(() => {
+ return this.store.loadRecord('post', serverPost.id, {
+ include: 'comments',
+ });
});
+
+ assert.ok(
+ this.store.hasLoadedIncludesForRecord('post', serverPost.id, 'comments')
+ );
});
- assert.ok(this.store.hasLoadedIncludesForRecord('post', serverPost.id, 'comments'));
- });
+ test('it returns false if the relationship has not been loaded', async function (assert) {
+ let serverPost = this.server.create('post');
+ this.server.createList('comment', 3, { post: serverPost });
- test('it returns false if the relationship has not been loaded', async function(assert) {
- let serverPost = this.server.create('post');
- this.server.createList('comment', 3, { post: serverPost });
+ await run(() => {
+ return this.store.loadRecord('post', serverPost.id);
+ });
- await run(() => {
- return this.store.loadRecord('post', serverPost.id);
+ assert.notOk(
+ this.store.hasLoadedIncludesForRecord('post', serverPost.id, 'comments')
+ );
});
-
- assert.notOk(this.store.hasLoadedIncludesForRecord('post', serverPost.id, 'comments'));
- });
-});
+ }
+);
diff --git a/tests/integration/mixins/loadable-store/load-record-test.js b/tests/integration/mixins/loadable-store/load-record-test.js
index 95116db4..91057954 100644
--- a/tests/integration/mixins/loadable-store/load-record-test.js
+++ b/tests/integration/mixins/loadable-store/load-record-test.js
@@ -6,36 +6,36 @@ import { Model, hasMany, belongsTo } from 'ember-cli-mirage';
import { run } from '@ember/runloop';
import LoadableStore from 'ember-data-storefront/mixins/loadable-store';
-module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
+module('Integration | Mixins | LoadableStore | loadRecord', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
this.server = new MirageServer({
models: {
// eslint-disable-next-line ember/no-new-mixins
post: Model.extend({
comments: hasMany(),
author: belongsTo(),
- tags: hasMany()
+ tags: hasMany(),
}),
// eslint-disable-next-line ember/no-new-mixins
comment: Model.extend({
post: belongsTo(),
- author: belongsTo()
+ author: belongsTo(),
}),
// eslint-disable-next-line ember/no-new-mixins
tag: Model.extend({
- posts: hasMany()
+ posts: hasMany(),
}),
// eslint-disable-next-line ember/no-new-mixins
author: Model.extend({
comments: hasMany(),
- posts: hasMany()
- })
+ posts: hasMany(),
+ }),
},
baseConfig() {
this.resource('posts');
- }
+ },
});
this.store = this.owner.lookup('service:store');
@@ -43,11 +43,11 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
this.store.resetCache();
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
this.server.shutdown();
});
- test('it can load a record', async function(assert) {
+ test('it can load a record', async function (assert) {
let serverPost = this.server.create('post');
let post = await run(() => {
@@ -57,7 +57,7 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
assert.equal(post.get('id'), serverPost.id);
});
- test('it resolves immediately with an already-loaded record, then reloads it in the background', async function(assert) {
+ test('it resolves immediately with an already-loaded record, then reloads it in the background', async function (assert) {
let serverPost = this.server.create('post', { title: 'My post' });
let serverCalls = 0;
this.server.pretender.handledRequest = () => serverCalls++;
@@ -76,14 +76,14 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
await waitUntil(() => serverCalls === 2);
});
- test('it forces already-loaded records to fetch with the reload option', async function(assert) {
+ test('it forces already-loaded records to fetch with the reload option', async function (assert) {
let serverPost = this.server.create('post');
let serverCalls = 0;
- this.server.pretender.handledRequest = function(method, url, request) {
+ this.server.pretender.handledRequest = function (method, url, request) {
serverCalls++;
// the reload qp should not be sent
- assert.ok(!request.queryParams.reload);
+ assert.notOk(request.queryParams.reload);
};
await run(() => {
@@ -97,13 +97,13 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
assert.equal(serverCalls, 2);
});
- test('it can load a record with includes', async function(assert) {
+ test('it can load a record with includes', async function (assert) {
let serverPost = this.server.create('post');
this.server.createList('comment', 3, { post: serverPost });
let post = await run(() => {
return this.store.loadRecord('post', serverPost.id, {
- include: 'comments'
+ include: 'comments',
});
});
@@ -111,17 +111,17 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
assert.equal(post.get('comments.length'), 3);
});
- test(`it resolves immediately with an already-loaded includes query, then reloads it in the background`, async function(assert) {
+ test(`it resolves immediately with an already-loaded includes query, then reloads it in the background`, async function (assert) {
let serverPost = this.server.create('post', { title: 'My post' });
this.server.createList('comment', 3, { post: serverPost });
let serverCalls = [];
- this.server.pretender.handledRequest = function(verb, url) {
+ this.server.pretender.handledRequest = function (verb, url) {
serverCalls.push(url);
};
await run(() => {
return this.store.loadRecord('post', serverPost.id, {
- include: 'comments'
+ include: 'comments',
});
});
@@ -129,7 +129,7 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
let post = await run(() => {
return this.store.loadRecord('post', serverPost.id, {
- include: 'comments'
+ include: 'comments',
});
});
@@ -142,7 +142,7 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
assert.equal(serverCalls[1], '/posts/1?include=comments');
});
- test('it blocks when including an association for the first time', async function(assert) {
+ test('it blocks when including an association for the first time', async function (assert) {
let serverPost = this.server.create('post');
this.server.createList('comment', 3, { post: serverPost });
let serverCalls = 0;
@@ -158,7 +158,7 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
post = await run(() => {
return this.store.loadRecord('post', serverPost.id, {
- include: 'comments'
+ include: 'comments',
});
});
@@ -166,16 +166,16 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
assert.equal(post.hasMany('comments').value().get('length'), 3);
});
- test('it resolves immediately with an includes-only query whose relationships have already been loaded', async function(assert) {
+ test('it resolves immediately with an includes-only query whose relationships have already been loaded', async function (assert) {
let serverPost = this.server.create('post');
this.server.createList('comment', 3, { post: serverPost });
- this.server.createList('tag', 2, { posts: [ serverPost ] });
+ this.server.createList('tag', 2, { posts: [serverPost] });
let serverCalls = 0;
this.server.pretender.handledRequest = () => serverCalls++;
let post = await run(() => {
return this.store.loadRecord('post', serverPost.id, {
- include: 'comments'
+ include: 'comments',
});
});
@@ -184,7 +184,7 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
post = await run(() => {
return this.store.loadRecord('post', serverPost.id, {
- include: 'tags'
+ include: 'tags',
});
});
@@ -192,17 +192,17 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
post = await run(() => {
return this.store.loadRecord('post', serverPost.id, {
- include: 'tags,comments'
+ include: 'tags,comments',
});
});
assert.equal(serverCalls, 2);
});
- test('loadRecord resolves immediately if its called with no options and the record is already in the store from loadRecords, then reloads it in the background', async function(assert) {
+ test('loadRecord resolves immediately if its called with no options and the record is already in the store from loadRecords, then reloads it in the background', async function (assert) {
let serverPost = this.server.create('post', { title: 'My post' });
let serverCalls = 0;
- this.server.pretender.handledRequest = function() {
+ this.server.pretender.handledRequest = function () {
serverCalls++;
};
@@ -220,10 +220,10 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
await waitUntil(() => serverCalls === 2);
});
- test('loadRecord blocks if its called with an includes, even if the record has already been loaded from loadRecords', async function(assert) {
+ test('loadRecord blocks if its called with an includes, even if the record has already been loaded from loadRecords', async function (assert) {
let serverPost = this.server.create('post', { title: 'My post' });
let serverCalls = 0;
- this.server.pretender.handledRequest = function() {
+ this.server.pretender.handledRequest = function () {
serverCalls++;
};
@@ -233,7 +233,7 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
let post = await run(() => {
return this.store.loadRecord('post', serverPost.id, {
- include: 'comments'
+ include: 'comments',
});
});
@@ -241,11 +241,11 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
assert.equal(post.get('title'), 'My post');
});
- test('loadRecord should not refresh the model in the background if background reload is false', async function(assert) {
+ test('loadRecord should not refresh the model in the background if background reload is false', async function (assert) {
let serverPost = this.server.create('post', { title: 'My post' });
let serverCalls = 0;
- this.server.pretender.handledRequest = function() {
+ this.server.pretender.handledRequest = function () {
serverCalls++;
};
@@ -254,15 +254,16 @@ module('Integration | Mixins | LoadableStore | loadRecord', function(hooks) {
});
await run(() => {
- return this.store.loadRecord('post', serverPost.id, { backgroundReload: false });
+ return this.store.loadRecord('post', serverPost.id, {
+ backgroundReload: false,
+ });
});
assert.equal(serverCalls, 1);
// wait 500ms and make sure there's no network request
- await new Promise(resolve => setTimeout(resolve, 500));
+ await new Promise((resolve) => setTimeout(resolve, 500));
assert.equal(serverCalls, 1);
});
-
});
diff --git a/tests/integration/mixins/loadable-store/load-records-test.js b/tests/integration/mixins/loadable-store/load-records-test.js
index 0c6e500b..d98c816a 100644
--- a/tests/integration/mixins/loadable-store/load-records-test.js
+++ b/tests/integration/mixins/loadable-store/load-records-test.js
@@ -4,15 +4,15 @@ import { settled, waitUntil } from '@ember/test-helpers';
import MirageServer from 'dummy/tests/integration/helpers/mirage-server';
import LoadableStore from 'ember-data-storefront/mixins/loadable-store';
-module('Integration | Mixins | LoadableStore | loadRecords', function(hooks) {
+module('Integration | Mixins | LoadableStore | loadRecords', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
this.server = new MirageServer({
discoverEmberDataModels: true,
baseConfig() {
this.resource('posts');
- }
+ },
});
this.store = this.owner.lookup('service:store');
@@ -20,11 +20,11 @@ module('Integration | Mixins | LoadableStore | loadRecords', function(hooks) {
this.store.resetCache();
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
this.server.shutdown();
});
- test('it can load a collection', async function(assert) {
+ test('it can load a collection', async function (assert) {
let post = this.server.create('post');
let posts = await this.store.loadRecords('post');
@@ -33,7 +33,7 @@ module('Integration | Mixins | LoadableStore | loadRecords', function(hooks) {
assert.equal(posts.get('firstObject.id'), post.id);
});
- test('it resolves immediately with an already-loaded collection, then reloads it in the background', async function(assert) {
+ test('it resolves immediately with an already-loaded collection, then reloads it in the background', async function (assert) {
let serverPost = this.server.createList('post', 2);
let serverCalls = 0;
this.server.pretender.handledRequest = () => serverCalls++;
@@ -55,14 +55,14 @@ module('Integration | Mixins | LoadableStore | loadRecords', function(hooks) {
assert.equal(posts.get('length'), 3);
});
- test('it forces an already-loaded collection to fetch with the reload options', async function(assert) {
+ test('it forces an already-loaded collection to fetch with the reload options', async function (assert) {
this.server.createList('post', 3);
let serverCalls = 0;
- this.server.pretender.handledRequest = function(method, url, request) {
+ this.server.pretender.handledRequest = function (method, url, request) {
serverCalls++;
// the reload qp should not be sent
- assert.ok(!request.queryParams.reload);
+ assert.notOk(request.queryParams.reload);
};
await this.store.loadRecords('post', { reload: true });
@@ -72,14 +72,14 @@ module('Integration | Mixins | LoadableStore | loadRecords', function(hooks) {
assert.equal(posts.get('length'), 3);
});
- test('it should not make a network request for an already loaded collection that has background reload false', async function(assert) {
+ test('it should not make a network request for an already loaded collection that has background reload false', async function (assert) {
this.server.createList('post', 3);
let serverCalls = 0;
- this.server.pretender.handledRequest = function(method, url, request) {
+ this.server.pretender.handledRequest = function (method, url, request) {
serverCalls++;
// the background reload qp should not be sent
- assert.ok(!request.queryParams.backgroundReload);
+ assert.notOk(request.queryParams.backgroundReload);
};
await this.store.loadRecords('post');
@@ -88,12 +88,12 @@ module('Integration | Mixins | LoadableStore | loadRecords', function(hooks) {
assert.equal(serverCalls, 1);
// wait 500ms and make sure there's no network request
- await new Promise(resolve => setTimeout(resolve, 500));
+ await new Promise((resolve) => setTimeout(resolve, 500));
assert.equal(serverCalls, 1);
});
- test('it can load a collection with a query object', async function(assert) {
+ test('it can load a collection with a query object', async function (assert) {
let serverPosts = this.server.createList('post', 2);
let serverCalls = [];
this.server.pretender.handledRequest = (...args) => {
@@ -102,27 +102,29 @@ module('Integration | Mixins | LoadableStore | loadRecords', function(hooks) {
let posts = await this.store.loadRecords('post', {
filter: {
- testing: 123
- }
+ testing: 123,
+ },
});
assert.equal(posts.get('length'), 2);
assert.equal(posts.get('firstObject.id'), serverPosts[0].id);
assert.equal(serverCalls.length, 1);
- assert.deepEqual(serverCalls[0][2].queryParams, { "filter[testing]": "123" } );
+ assert.deepEqual(serverCalls[0][2].queryParams, {
+ 'filter[testing]': '123',
+ });
});
- test('it can load a collection with includes', async function(assert) {
+ test('it can load a collection with includes', async function (assert) {
let serverPost = this.server.create('post', {
- comments: this.server.createList('comment', 2)
+ comments: this.server.createList('comment', 2),
});
let serverCalls = [];
- this.server.pretender.handledRequest = function() {
+ this.server.pretender.handledRequest = function () {
serverCalls.push(arguments);
};
let posts = await this.store.loadRecords('post', {
- include: 'comments'
+ include: 'comments',
});
assert.equal(posts.get('length'), 1);
@@ -130,21 +132,23 @@ module('Integration | Mixins | LoadableStore | loadRecords', function(hooks) {
assert.equal(posts.get('firstObject.comments.length'), 2);
});
- test('it can load a polymorphic collection with model-specific includes', async function(assert) {
+ test('it can load a polymorphic collection with model-specific includes', async function (assert) {
this.server.get('/homepage-items');
let post = this.server.create('post');
let comment = this.server.create('comment');
this.server.create('homepage-item', { itemizable: post });
this.server.create('homepage-item', { itemizable: comment });
- await this.store.loadRecords('homepage-item', { include: 'itemizable.tags' });
+ await this.store.loadRecords('homepage-item', {
+ include: 'itemizable.tags',
+ });
assert.ok(this.store.peekRecord('post', post.id));
assert.ok(this.store.peekRecord('comment', comment.id));
});
- module('Tracking includes', function() {
- test('it will track an include', async function(assert) {
+ module('Tracking includes', function () {
+ test('it will track an include', async function (assert) {
let serverPost = this.server.create('post', { title: 'My post' });
this.server.createList('comment', 3, { post: serverPost });
@@ -153,32 +157,40 @@ module('Integration | Mixins | LoadableStore | loadRecords', function(hooks) {
assert.ok(posts.get('firstObject').hasLoaded('comments'));
});
- test('it will track a dot path include', async function(assert) {
+ test('it will track a dot path include', async function (assert) {
let serverPost = this.server.create('post', { title: 'My post' });
- let serverComments = this.server.createList('comment', 3, { post: serverPost });
+ let serverComments = this.server.createList('comment', 3, {
+ post: serverPost,
+ });
- serverComments.forEach(comment => {
+ serverComments.forEach((comment) => {
this.server.create('author', { comments: [comment] });
});
- let posts = await this.store.loadRecords('post', { include: 'comments.author' });
+ let posts = await this.store.loadRecords('post', {
+ include: 'comments.author',
+ });
assert.ok(posts.get('firstObject').hasLoaded('comments.author'));
});
- test('it will track multiple includes', async function(assert) {
+ test('it will track multiple includes', async function (assert) {
let serverAuthor = this.server.create('author');
let serverPost = this.server.create('post', {
title: 'My post',
- author: serverAuthor
+ author: serverAuthor,
+ });
+ let serverComments = this.server.createList('comment', 3, {
+ post: serverPost,
});
- let serverComments = this.server.createList('comment', 3, { post: serverPost });
- serverComments.forEach(comment => {
+ serverComments.forEach((comment) => {
this.server.create('author', { comments: [comment] });
});
- let posts = await this.store.loadRecords('post', { include: 'author,comments.author' });
+ let posts = await this.store.loadRecords('post', {
+ include: 'author,comments.author',
+ });
assert.ok(posts.get('firstObject').hasLoaded('author,comments.author'));
});
diff --git a/tests/unit/services/store-test.js b/tests/unit/services/store-test.js
index 90bf42c8..68b36824 100644
--- a/tests/unit/services/store-test.js
+++ b/tests/unit/services/store-test.js
@@ -4,42 +4,42 @@ import { Model, hasMany, belongsTo } from 'ember-cli-mirage';
import MirageServer from 'dummy/tests/integration/helpers/mirage-server';
import { run } from '@ember/runloop';
-module('Unit | Service | store', function(hooks) {
+module('Unit | Service | store', function (hooks) {
setupTest(hooks);
// has-loaded-includes-for-record-test
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
this.server = new MirageServer({
models: {
// eslint-disable-next-line ember/no-new-mixins
post: Model.extend({
comments: hasMany(),
- tags: hasMany()
+ tags: hasMany(),
}),
// eslint-disable-next-line ember/no-new-mixins
comment: Model.extend({
- post: belongsTo()
+ post: belongsTo(),
}),
// eslint-disable-next-line ember/no-new-mixins
tag: Model.extend({
- posts: hasMany()
- })
+ posts: hasMany(),
+ }),
},
baseConfig() {
this.resource('posts');
- }
+ },
});
let service = this.owner.lookup('service:store');
service.resetCache();
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
this.server.shutdown();
});
- test('it returns true if the relationship has been loaded', async function(assert) {
+ test('it returns true if the relationship has been loaded', async function (assert) {
let service = this.owner.lookup('service:store');
let serverPost = this.server.create('post');
@@ -47,14 +47,16 @@ module('Unit | Service | store', function(hooks) {
await run(() => {
return service.loadRecord('post', serverPost.id, {
- include: 'comments'
+ include: 'comments',
});
});
- assert.ok(service.hasLoadedIncludesForRecord('post', serverPost.id, 'comments'));
+ assert.ok(
+ service.hasLoadedIncludesForRecord('post', serverPost.id, 'comments')
+ );
});
- test('it returns false if the relationship has not been loaded', async function(assert) {
+ test('it returns false if the relationship has not been loaded', async function (assert) {
let service = this.owner.lookup('service:store');
let serverPost = this.server.create('post');
@@ -64,6 +66,8 @@ module('Unit | Service | store', function(hooks) {
return service.loadRecord('post', serverPost.id);
});
- assert.notOk(service.hasLoadedIncludesForRecord('post', serverPost.id, 'comments'));
+ assert.notOk(
+ service.hasLoadedIncludesForRecord('post', serverPost.id, 'comments')
+ );
});
});