Skip to content

Commit

Permalink
adds test for #8125
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Aug 18, 2022
1 parent 1ed3ee7 commit 260b7a5
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/-ember-data/tests/integration/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,46 @@ module('integration/store - findRecord', function (hooks) {
assert.strictEqual(car.model, 'Princess', 'Updated car record is returned');
});

test('multiple calls to store#findRecord return the cached record without firing new requests', async function (assert) {
assert.expect(3);

this.owner.unregister('serializer:application');
let adapter = store.adapterFor('application');
let calls = 0;

adapter.shouldReloadRecord = () => false;
adapter.shouldBackgroundReloadRecord = () => false;

adapter.findRecord = () => {
if (calls++ === 0) {
return resolve({
data: {
type: 'car',
id: '1',
attributes: {
make: 'BMC',
model: 'Mini',
},
},
});
}
assert.ok(false, 'should not call findRecord');
throw 'unexpected call';
};

const proxiedCar = store.findRecord('car', '1');
const car = await proxiedCar;

assert.strictEqual(car.model, 'Mini', 'car record is returned from cache');
const proxiedCar2 = store.findRecord('car', '1');
assert.strictEqual(proxiedCar2.get('model'), undefined, 'car record is returned from cache');
// assert.strictEqual(proxiedCar2.get('model'), 'Mini', 'car record is returned from cache');
const car2 = await proxiedCar2;

assert.strictEqual(car2?.model, 'Mini', 'car record is returned from cache');
assert.strictEqual(car, car2, 'we found the same car');
});

test('store#findRecord { reload: true } ignores cached record and reloads record from server', async function (assert) {
assert.expect(2);

Expand Down

0 comments on commit 260b7a5

Please sign in to comment.