From 709163929e9bde8a091e69dde7b7c75fa42b407e Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 6 Jan 2022 16:48:18 +0100 Subject: [PATCH 1/3] update package (#477) --- addon/mixins/loadable-model.js | 2 +- addon/mixins/loadable-store.js | 2 +- addon/mixins/loadable.js | 2 +- addon/services/storefront.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addon/mixins/loadable-model.js b/addon/mixins/loadable-model.js index a113f38c..a1b8b7d6 100644 --- a/addon/mixins/loadable-model.js +++ b/addon/mixins/loadable-model.js @@ -1,5 +1,5 @@ import Mixin from '@ember/object/mixin'; -import { deprecate } from '@ember/application/deprecations'; +import { deprecate } from '@ember/debug' import { assert } from '@ember/debug'; import { resolve } from 'rsvp'; import { isArray } from '@ember/array'; diff --git a/addon/mixins/loadable-store.js b/addon/mixins/loadable-store.js index 7c617217..14b0dc40 100644 --- a/addon/mixins/loadable-store.js +++ b/addon/mixins/loadable-store.js @@ -1,5 +1,5 @@ import Mixin from '@ember/object/mixin'; -import { deprecate } from '@ember/application/deprecations'; +import { deprecate } from '@ember/debug' import { resolve } from 'rsvp'; import Coordinator from 'ember-data-storefront/-private/coordinator'; diff --git a/addon/mixins/loadable.js b/addon/mixins/loadable.js index e6bc0c8f..4f73ac1f 100644 --- a/addon/mixins/loadable.js +++ b/addon/mixins/loadable.js @@ -1,5 +1,5 @@ import Mixin from '@ember/object/mixin'; -import { deprecate } from '@ember/application/deprecations'; +import { deprecate } from '@ember/debug' import { on } from '@ember/object/evented'; import LoadableModel from './loadable-model'; diff --git a/addon/services/storefront.js b/addon/services/storefront.js index 0a3fa54b..1b7bb563 100644 --- a/addon/services/storefront.js +++ b/addon/services/storefront.js @@ -1,5 +1,5 @@ import Service, { inject as service } from '@ember/service'; -import { deprecate } from '@ember/application/deprecations'; +import { deprecate } from '@ember/debug' // do not delete this service! it's being used to communicte cached payloads // between the client and the browser From 414d632d9928ec033bda84a986f0a45a57cebd5a Mon Sep 17 00:00:00 2001 From: Ryan Toronto Date: Sat, 19 Feb 2022 11:00:48 -0500 Subject: [PATCH 2/3] 0.18.2-ember4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b693367a..d9df52f6 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" From 494544b6c89b73bd6125aeafae7bc9046ffe3ddd Mon Sep 17 00:00:00 2001 From: Jeff Keen Date: Wed, 5 Oct 2022 09:06:31 -0500 Subject: [PATCH 3/3] Linter fixes --- .eslintrc.js | 16 ++- addon/-private/cache.js | 6 +- addon/-private/coordinator.js | 30 +++--- addon/-private/record-array-query.js | 16 ++- addon/-private/record-query.js | 18 ++-- addon/-private/utils/get-key.js | 31 +++--- addon/adapters/application.js | 2 +- .../assert-must-preload/component.js | 8 +- .../inject-storefront.js | 2 +- .../instance-initializers/mixin-storefront.js | 2 +- addon/mixins/fastboot-adapter.js | 52 ++++++--- addon/mixins/snapshottable.js | 63 +++++++---- addon/services/storefront.js | 1 + .../inject-storefront.js | 5 +- app/instance-initializers/mixin-storefront.js | 5 +- app/transitions.js | 2 +- config/deploy.js | 6 +- config/ember-try.js | 78 +++++++------- config/environment.js | 4 +- ember-cli-build.js | 9 +- fastboot-tests/adapter-test.js | 81 ++++++++------ .../ember-data-storefront.js | 8 +- index.js | 6 +- server/.eslintrc.js | 4 +- server/index.js | 8 +- server/mocks/posts.js | 20 ++-- testem.js | 16 ++- tests/acceptance/load-all-test.js | 16 ++- tests/acceptance/load-relationship-test.js | 14 ++- tests/dummy/app/adapters/post.js | 6 +- tests/dummy/app/app.js | 2 +- tests/dummy/app/models/author.js | 1 - tests/dummy/app/models/comment.js | 2 - tests/dummy/app/models/homepage-item.js | 2 - tests/dummy/app/models/itemizable.js | 2 - tests/dummy/app/models/post.js | 2 - tests/dummy/app/models/tag.js | 2 - .../guides/data-fetching/demo-1/component.js | 4 +- .../guides/data-fetching/demo-2/component.js | 6 +- .../demo-1/component.js | 4 +- .../demo-2/component.js | 4 +- tests/dummy/app/router.js | 10 +- tests/dummy/config/environment.js | 14 +-- tests/dummy/config/targets.js | 4 +- tests/dummy/mirage/config.js | 17 +-- tests/dummy/mirage/factories/comment.js | 3 +- tests/dummy/mirage/factories/post.js | 6 +- tests/dummy/mirage/scenarios/default.js | 6 +- tests/dummy/mirage/serializers/application.js | 2 - tests/dummy/mirage/serializers/post.js | 8 +- tests/helpers/start-mirage.js | 8 +- tests/integration/-private/cache-test.js | 33 +++--- .../integration/changing-data-render-test.js | 22 ++-- .../components/assert-must-preload-test.js | 67 ++++++------ .../components/load-records-example-test.js | 27 ++--- tests/integration/helpers/mirage-server.js | 6 +- .../mixins/loadable-model/has-loaded-test.js | 27 +++-- .../mixins/loadable-model/load-test.js | 68 ++++++------ .../mixins/loadable-model/sideload-test.js | 46 ++++---- .../has-loaded-includes-for-record-test.js | 101 ++++++++++-------- .../mixins/loadable-store/load-record-test.js | 75 ++++++------- .../loadable-store/load-records-test.js | 80 ++++++++------ tests/unit/services/store-test.js | 30 +++--- 63 files changed, 649 insertions(+), 577 deletions(-) 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/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 42e182d4..b6917006 100644 --- a/addon/services/storefront.js +++ b/addon/services/storefront.js @@ -1,5 +1,6 @@ import Service, { inject as service } from '@ember/service'; import { deprecate } from '@ember/debug'; +import { tracked } from '@glimmer/tracking'; // do not delete this service! it's being used to communicte cached payloads // between the client and the browser 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/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') + ); }); });