From 983870e0e137a84f9a4d969910cee0a29f5fe982 Mon Sep 17 00:00:00 2001 From: Sam Selikoff Date: Sat, 22 Jun 2019 01:35:13 -0400 Subject: [PATCH] Failing test --- tests/dummy/app/mixins/itemizable.js | 3 ++ tests/dummy/app/models/homepage-item.js | 7 ++++ .../loadable-store/load-records-test.js | 34 ++++++++----------- 3 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 tests/dummy/app/mixins/itemizable.js create mode 100644 tests/dummy/app/models/homepage-item.js diff --git a/tests/dummy/app/mixins/itemizable.js b/tests/dummy/app/mixins/itemizable.js new file mode 100644 index 00000000..9aa7bf67 --- /dev/null +++ b/tests/dummy/app/mixins/itemizable.js @@ -0,0 +1,3 @@ +import Mixin from '@ember/object/mixin'; + +export default Mixin.create({}); diff --git a/tests/dummy/app/models/homepage-item.js b/tests/dummy/app/models/homepage-item.js new file mode 100644 index 00000000..991dd51c --- /dev/null +++ b/tests/dummy/app/models/homepage-item.js @@ -0,0 +1,7 @@ +import DS from 'ember-data'; + +export default DS.Model.extend({ + + itemizable: DS.belongsTo({ polymorphic: true }), + +}); diff --git a/tests/integration/mixins/loadable-store/load-records-test.js b/tests/integration/mixins/loadable-store/load-records-test.js index 26823116..6151966f 100644 --- a/tests/integration/mixins/loadable-store/load-records-test.js +++ b/tests/integration/mixins/loadable-store/load-records-test.js @@ -2,7 +2,6 @@ import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; import { waitUntil } from '@ember/test-helpers'; import MirageServer from 'dummy/tests/integration/helpers/mirage-server'; -import { Model, hasMany, belongsTo } from 'ember-cli-mirage'; import LoadableStore from 'ember-data-storefront/mixins/loadable-store'; module('Integration | Mixins | LoadableStore | loadRecords', function(hooks) { @@ -10,24 +9,7 @@ module('Integration | Mixins | LoadableStore | loadRecords', function(hooks) { hooks.beforeEach(function() { this.server = new MirageServer({ - models: { - post: Model.extend({ - comments: hasMany(), - author: belongsTo(), - tags: hasMany() - }), - comment: Model.extend({ - post: belongsTo(), - author: belongsTo() - }), - tag: Model.extend({ - posts: hasMany() - }), - author: Model.extend({ - comments: hasMany(), - posts: hasMany() - }) - }, + discoverEmberDataModels: true, baseConfig() { this.resource('posts'); } @@ -146,6 +128,20 @@ 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) { + server.logging = true; + 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' }); + + 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) { let serverPost = this.server.create('post', { title: 'My post' });