Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Continuing InternalModel Burndown #8055

Merged
merged 16 commits into from
Jul 25, 2022
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ module.exports = {
'packages/store/addon/-private/system/internal-model-map.ts',
'packages/store/addon/-private/system/identity-map.ts',
'packages/store/addon/-private/system/fetch-manager.ts',
'packages/store/addon/-private/system/ds-model-store.ts',
'packages/store/addon/-private/system/core-store.ts',
'packages/store/addon/-private/system/coerce-id.ts',
'packages/store/addon/-private/index.ts',
Expand Down
4 changes: 0 additions & 4 deletions packages/-ember-data/.ember-cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
const { setEdition } = require('@ember/edition-utils');

setEdition('octane');

module.exports = {
/**
Ember CLI sends analytics information by default. The data is completely
Expand Down
15 changes: 0 additions & 15 deletions packages/-ember-data/node-tests/fixtures/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,11 @@ module.exports = {
'(private) @ember-data/store SnapshotRecordArray#_snapshots',
'(private) @ember-data/store SnapshotRecordArray#constructor',
'(private) @ember-data/store Store#_backburner',
'(private) @ember-data/store Store#_fetchAll',
'(private) @ember-data/store Store#_generateId',
'(private) @ember-data/store Store#_hasModelFor',
'(private) @ember-data/store Store#_load',
'(private) @ember-data/store Store#_push',
'(private) @ember-data/store Store#_reloadRecord',
'(private) @ember-data/store Store#defaultAdapter',
'(private) @ember-data/store Store#didSaveRecord',
'(private) @ember-data/store Store#find',
'(private) @ember-data/store Store#findBelongsTo',
'(private) @ember-data/store Store#findByIds',
'(private) @ember-data/store Store#findHasMany',
'(private) @ember-data/store Store#findMany',
'(private) @ember-data/store Store#flushPendingSave',
'(private) @ember-data/store Store#init',
'(private) @ember-data/store Store#recordForId',
'(private) @ember-data/store Store#recordWasError',
'(private) @ember-data/store Store#recordWasInvalid',
'(private) @ember-data/store Store#scheduleSave',
'(private) @ember-data/store Store#setRecordId',
'(public) @ember-data/adapter Adapter#coalesceFindRequests',
'(public) @ember-data/adapter Adapter#createRecord',
Expand Down Expand Up @@ -362,7 +348,6 @@ module.exports = {
'(public) @ember-data/store StableRecordIdentifier#id',
'(public) @ember-data/store StableRecordIdentifier#lid',
'(public) @ember-data/store StableRecordIdentifier#type',
'(public) @ember-data/store Store#adapter',
'(public) @ember-data/store Store#adapterFor',
'(public) @ember-data/store Store#createRecord',
'(public) @ember-data/store Store#createRecordDataFor',
Expand Down
3 changes: 3 additions & 0 deletions packages/-ember-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
"ember-addon": {
"configPath": "tests/dummy/config"
},
"ember": {
"edition": "octane"
},
"volta": {
"node": "16.16.0",
"yarn": "1.22.19"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,9 @@ module('async belongs-to rendering tests', function (hooks) {
<p>{{this.sedona.parent.name}}</p>
`);

let parent = await sedona.get('parent');
let parent = await sedona.parent;
await parent.destroyRecord();

let newParent = await sedona.get('parent');

await settled();
let newParent = await sedona.parent;

assert.strictEqual(newParent, null, 'We no longer have a parent');
assert.strictEqual(
Expand Down Expand Up @@ -487,7 +484,9 @@ module('async belongs-to rendering tests', function (hooks) {
data: people.dict['5:has-parent-no-children'],
});

adapter.setupPayloads(assert, [new ServerError([], 'hard error while finding <person>5:has-parent-no-children')]);
adapter.setupPayloads(assert, [
new ServerError([], 'hard error while finding <person>5:has-parent-no-children.parent'),
]);

// render
this.set('sedona', sedona);
Expand All @@ -500,7 +499,7 @@ module('async belongs-to rendering tests', function (hooks) {
assert.ok(true, 'Children promise did reject');
assert.strictEqual(
e.message,
'hard error while finding <person>5:has-parent-no-children',
'hard error while finding <person>5:has-parent-no-children.parent',
'Rejection has the correct message'
);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@ember-data/adapter/json-api';
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { settled } from '@ember/test-helpers';

import { module, test } from 'qunit';
import { resolve } from 'rsvp';

Expand Down Expand Up @@ -77,11 +75,7 @@ module('integration/adapter/store-adapter - client-side delete', function (hooks

await book2.destroyRecord({ adapterOptions: { clientSideDelete: true } });

book2.unloadRecord();

await settled();

assert.false(store.hasRecordForId('book', '2'), 'book 2 unloaded');
assert.strictEqual(store.peekRecord('book', '2'), null, 'book 2 unloaded');
assert.deepEqual(bookstore.books.mapBy('id'), ['1'], 'one book client-side deleted');

store.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ module('integration/adapter/find - Finding Records', function (hooks) {
assert.ok(false, 'We expected to throw but did not');
} catch (e) {
assert.ok(true, 'The rejection handler was called');
assert.notOk(store.hasRecordForId('person', '1'), 'The record has been unloaded');
assert.strictEqual(store.peekRecord('person', '1'), null, 'The record has been unloaded');
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ module('integration/adapter/record_persistence - Persisting Records', function (
assert.true(tom.isDeleted, 'record is marked as deleted');
});

test('An adapter can notify the store that a record was updated and provide new data by calling `didSaveRecord`.', async function (assert) {
test('An adapter can notify the store that a record was updated and provide new data.', async function (assert) {
class Person extends Model {
@attr('string') updatedAt;
@attr('string') name;
Expand Down Expand Up @@ -250,25 +250,25 @@ module('integration/adapter/record_persistence - Persisting Records', function (
assert.strictEqual(savedYehuda, yehuda, 'The record is correct');
assert.false(tom.hasDirtyAttributes, 'Tom is not dirty after saving record');
assert.false(yehuda.hasDirtyAttributes, 'Yehuda is not dirty after dsaving record');
assert.strictEqual(tom.name, 'Tom Dale', 'name attribute should reflect value of hash passed to didSaveRecords');
assert.strictEqual(tom.name, 'Tom Dale', 'name attribute should reflect value of hash returned from the request');
assert.strictEqual(
tom.updatedAt,
'now',
'updatedAt attribute should reflect value of hash passed to didSaveRecords'
'updatedAt attribute should reflect value of hash returned from the request'
);
assert.strictEqual(
yehuda.name,
'Yehuda Katz',
'name attribute should reflect value of hash passed to didSaveRecords'
'name attribute should reflect value of hash returned from the request'
);
assert.strictEqual(
yehuda.updatedAt,
'now!',
'updatedAt attribute should reflect value of hash passed to didSaveRecords'
'updatedAt attribute should reflect value of hash returned from the request'
);
});

test('An adapter can notify the store that records were deleted by calling `didSaveRecords`.', async function (assert) {
test('An adapter can notify the store that records were deleted', async function (assert) {
class Person extends Model {
@attr('string') updatedAt;
@attr('string') name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { setupTest } from 'ember-qunit';
import RESTAdapter from '@ember-data/adapter/rest';
import Model, { belongsTo, hasMany } from '@ember-data/model';
import RESTSerializer from '@ember-data/serializer/rest';
import { recordIdentifierFor } from '@ember-data/store';
import deepCopy from '@ember-data/unpublished-test-infra/test-support/deep-copy';
import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug';

Expand Down Expand Up @@ -1940,7 +1939,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) {
ajaxError('error', 401);

try {
await store.find('post', '1');
await store.findRecord('post', '1');
} catch (reason) {
assert.ok(true, 'promise should be rejected');
assert.ok(reason instanceof DS.UnauthorizedError, 'reason should be an instance of DS.UnauthorizedError');
Expand All @@ -1949,7 +1948,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) {
ajaxError('error', 403);

try {
await store.find('post', '1');
await store.findRecord('post', '1');
} catch (reason) {
assert.ok(true, 'promise should be rejected');
assert.ok(reason instanceof DS.ForbiddenError, 'reason should be an instance of DS.ForbiddenError');
Expand All @@ -1958,7 +1957,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) {
ajaxError('error', 404);

try {
await store.find('post', '1');
await store.findRecord('post', '1');
} catch (reason) {
assert.ok(true, 'promise should be rejected');
assert.ok(reason instanceof DS.NotFoundError, 'reason should be an instance of DS.NotFoundError');
Expand All @@ -1967,7 +1966,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) {
ajaxError('error', 409);

try {
await store.find('post', '1');
await store.findRecord('post', '1');
} catch (reason) {
assert.ok(true, 'promise should be rejected');
assert.ok(reason instanceof DS.ConflictError, 'reason should be an instance of DS.ConflictError');
Expand All @@ -1976,7 +1975,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) {
ajaxError('error', 500);

try {
await store.find('post', '1');
await store.findRecord('post', '1');
} catch (reason) {
assert.ok(true, 'promise should be rejected');
assert.ok(reason instanceof DS.ServerError, 'reason should be an instance of DS.ServerError');
Expand Down Expand Up @@ -2091,10 +2090,6 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) {
},
(reason) => {
assert.ok(/saved to the server/.test(reason.message));
// Workaround for #7371 to get the record a correct state before teardown
let identifier = recordIdentifierFor(post);
let im = store._internalModelForResource(identifier);
store.didSaveRecord(im, { data: { id: '1', type: 'post' } }, 'createRecord');
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function moveRecordOutOfInFlight(record) {
// TODO this would be made nicer by a cancellation API
let pending = store.getRequestStateService().getPendingRequestsForRecord(_internalModel.identifier);
pending.splice(0, pending.length); // release the requests
store.recordWasError(_internalModel, new Error());
_internalModel.adapterDidError(new Error());
}

module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test', function (hooks) {
Expand Down Expand Up @@ -210,7 +210,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration
});
});

test('calling store.didSaveRecord can provide an optional hash', async function (assert) {
test('additional new values can be returned on store save', async function (assert) {
let store = this.owner.lookup('service:store');
let adapter = store.adapterFor('application');
let Person = store.modelFor('person');
Expand Down
32 changes: 20 additions & 12 deletions packages/-ember-data/tests/integration/multiple-stores-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ module('integration/multiple_stores - Multiple Stores Tests', function (hooks) {
);

andromedaStore.push(normalizedAndromedaPayload);
assert.true(andromedaStore.hasRecordForId('super-villain', '1'), 'superVillain should exist in service:store');
assert.notStrictEqual(
andromedaStore.peekRecord('super-villain', '1'),
null,
'superVillain should exist in service:store'
);

const normalizedCartWheelPayload = cartwheelSerializer.normalizeResponse(
cartwheelStore,
Expand All @@ -146,7 +150,11 @@ module('integration/multiple_stores - Multiple Stores Tests', function (hooks) {
);

cartwheelStore.push(normalizedCartWheelPayload);
assert.true(cartwheelStore.hasRecordForId('super-villain', '1'), 'superVillain should exist in store:store-a');
assert.notStrictEqual(
cartwheelStore.peekRecord('super-villain', '1'),
null,
'superVillain should exist in store:store-a'
);

const normalizedCigarPayload = cigarSerializer.normalizeResponse(
cigarStore,
Expand All @@ -157,7 +165,11 @@ module('integration/multiple_stores - Multiple Stores Tests', function (hooks) {
);
cigarStore.push(normalizedCigarPayload);

assert.true(cigarStore.hasRecordForId('super-villain', '1'), 'superVillain should exist in store:store-b');
assert.notStrictEqual(
cigarStore.peekRecord('super-villain', '1'),
null,
'superVillain should exist in store:store-b'
);
});

test('each store should have a unique instance of the serializers', function (assert) {
Expand All @@ -169,13 +181,11 @@ module('integration/multiple_stores - Multiple Stores Tests', function (hooks) {
const andromedaSerializer = andromedaStore.serializerFor('home-planet');
const cigarSerializer = cigarStore.serializerFor('home-planet');

assert.strictEqual(
andromedaSerializer.store,
andromedaStore,
"andromedaSerializer's store prop should be andromedaStore"
assert.notStrictEqual(
andromedaSerializer,
cigarSerializer,
'andromedaStore and cigarStore should be unique instances'
);
assert.strictEqual(cigarSerializer.store, cigarStore, "cigarSerializer's store prop should be cigarStore");
assert.notEqual(andromedaSerializer, cigarSerializer, 'andromedaStore and cigarStore should be unique instances');
});

test('each store should have a unique instance of the adapters', function (assert) {
Expand All @@ -187,8 +197,6 @@ module('integration/multiple_stores - Multiple Stores Tests', function (hooks) {
const andromedaAdapter = andromedaStore.adapterFor('home-planet');
const cigarAdapter = cigarStore.adapterFor('home-planet');

assert.strictEqual(andromedaAdapter.store, andromedaStore);
assert.strictEqual(cigarAdapter.store, cigarStore);
assert.notEqual(andromedaAdapter, cigarAdapter);
assert.notStrictEqual(andromedaAdapter, cigarAdapter, 'the adapters are unique');
});
});
60 changes: 0 additions & 60 deletions packages/-ember-data/tests/integration/record-array-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,66 +44,6 @@ module('unit/record-array - RecordArray', function (hooks) {
store = owner.lookup('service:store');
});

test('a record array is backed by records', async function (assert) {
assert.expect(3);
this.owner.register(
'adapter:application',
Adapter.extend({
shouldBackgroundReloadRecord() {
return false;
},
})
);

store.push({
data: [
{
type: 'person',
id: '1',
attributes: {
name: 'Scumbag Dale',
},
},
{
type: 'person',
id: '2',
attributes: {
name: 'Scumbag Katz',
},
},
{
type: 'person',
id: '3',
attributes: {
name: 'Scumbag Bryn',
},
},
],
});

let records = await store.findByIds('person', [1, 2, 3]);
let expectedResults = {
data: [
{ id: '1', type: 'person', attributes: { name: 'Scumbag Dale' } },
{ id: '2', type: 'person', attributes: { name: 'Scumbag Katz' } },
{ id: '3', type: 'person', attributes: { name: 'Scumbag Bryn' } },
],
};

for (let i = 0, l = expectedResults.data.length; i < l; i++) {
let {
id,
attributes: { name },
} = expectedResults.data[i];

assert.deepEqual(
records[i].getProperties('id', 'name'),
{ id, name },
'a record array materializes objects on demand'
);
}
});

test('acts as a live query', async function (assert) {
let recordArray = store.peekAll('person');

Expand Down
Loading