Skip to content

Commit

Permalink
chore: remove no-longer-needed misdirection for IdentifierCache lookup (
Browse files Browse the repository at this point in the history
#7862)

* chore: remove no-longer-needed misdirection for IdentifierCache lookup

* lint and docs fixes

* simplify prop access

* fix tests and bump qunit/testem version
  • Loading branch information
runspired authored Feb 11, 2022
1 parent cae5433 commit 1829495
Show file tree
Hide file tree
Showing 32 changed files with 133 additions and 152 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"pre-commit": "^1.2.2",
"pretender": "^3.4.3",
"prettier": "^2.2.1",
"qunit": "^2.15.0",
"qunit": "^2.17.0",
"qunit-dom": "^2.0.0",
"rimraf": "^3.0.2",
"rsvp": "^4.8.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/-ember-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"json-typescript": "^1.1.0",
"loader.js": "^4.7.0",
"pretender": "^3.4.3",
"qunit": "^2.15.0",
"qunit": "^2.17.0",
"qunit-dom": "^2.0.0",
"typescript": "~4.3.2",
"webpack": "^5.37.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

import Store from '@ember-data/store';
import { identifierCacheFor } from '@ember-data/store/-private';
import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug';

module('Integration | Identifiers - cache', function (hooks) {
Expand All @@ -13,7 +12,7 @@ module('Integration | Identifiers - cache', function (hooks) {
hooks.beforeEach(function () {
this.owner.register(`service:store`, Store);
store = this.owner.lookup('service:store');
cache = identifierCacheFor(store);
cache = store.identifierCache;
});

module('getOrCreateRecordIdentifier()', function () {
Expand Down Expand Up @@ -46,7 +45,7 @@ module('Integration | Identifiers - cache', function (hooks) {
name: 'Moomin',
},
};
const cache = identifierCacheFor(store);
const cache = store.identifierCache;
const identifier = cache.getOrCreateRecordIdentifier(houseHash);

assert.strictEqual(
Expand All @@ -64,7 +63,7 @@ module('Integration | Identifiers - cache', function (hooks) {
name: 'Moomin',
},
};
const cache = identifierCacheFor(store);
const cache = store.identifierCache;
const identifier = cache.getOrCreateRecordIdentifier(houseHash);

assert.strictEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Store, {
setIdentifierResetMethod,
setIdentifierUpdateMethod,
} from '@ember-data/store';
import { identifierCacheFor } from '@ember-data/store/-private';
import type {
IdentifierBucket,
ResourceData,
Expand All @@ -28,14 +27,12 @@ import type {

module('Integration | Identifiers - configuration', function (hooks) {
setupTest(hooks);
let store: Store;

hooks.beforeEach(function () {
const { owner } = this;

owner.register('adapter:application', JSONAPIAdapter.extend());
owner.register('serializer:application', JSONAPISerializer.extend());

class User extends Model {
@attr()
declare firstName: string;
Expand All @@ -48,8 +45,6 @@ module('Integration | Identifiers - configuration', function (hooks) {
owner.register('model:user', User);
owner.register('service:store', Store);

store = owner.lookup('service:store');

let localIdInc = 9000;
const generationMethod = (resource: ResourceData | { type: string }) => {
if (!('type' in resource) || typeof resource.type !== 'string' || resource.type.length < 1) {
Expand Down Expand Up @@ -78,6 +73,7 @@ module('Integration | Identifiers - configuration', function (hooks) {
});

test(`The configured generation method is used for pushed records`, async function (assert) {
const store = this.owner.lookup('service:store');
const record = store.push({
data: {
type: 'user',
Expand Down Expand Up @@ -113,6 +109,7 @@ module('Integration | Identifiers - configuration', function (hooks) {

setIdentifierGenerationMethod(generationMethod);

const store = this.owner.lookup('service:store');
const newRecord = store.createRecord('user', {
firstName: 'James',
username: '@cthoburn',
Expand Down Expand Up @@ -169,6 +166,7 @@ module('Integration | Identifiers - configuration', function (hooks) {

setIdentifierUpdateMethod(updateMethod);

const store = this.owner.lookup('service:store');
const record = store.createRecord('user', { firstName: 'Chris', username: '@runspired', age: 31 });
const identifier = recordIdentifierFor(record);
assert.strictEqual(
Expand Down Expand Up @@ -232,6 +230,7 @@ module('Integration | Identifiers - configuration', function (hooks) {

setIdentifierUpdateMethod(updateMethod);

const store = this.owner.lookup('service:store');
const record = store.createRecord('user', { id: '1', firstName: 'Chris', username: '@runspired', age: 31 });
const identifier = recordIdentifierFor(record);
assert.strictEqual(
Expand Down Expand Up @@ -295,6 +294,7 @@ module('Integration | Identifiers - configuration', function (hooks) {

setIdentifierUpdateMethod(updateMethod);

const store = this.owner.lookup('service:store');
const record: any = store.push({
data: {
id: '1',
Expand Down Expand Up @@ -333,6 +333,7 @@ module('Integration | Identifiers - configuration', function (hooks) {
resetMethodCalled = true;
});

const store = this.owner.lookup('service:store');
run(() => store.destroy());
assert.ok(resetMethodCalled, 'We called the reset method when the application was torn down');
});
Expand Down Expand Up @@ -381,17 +382,18 @@ module('Integration | Identifiers - configuration', function (hooks) {
testMethod(identifier);
});

const store = this.owner.lookup('service:store');
const userByUsernamePromise = store.findRecord('user', '@runspired');
const userByIdPromise = store.findRecord('user', '1');

assert.strictEqual(generateLidCalls, 2, 'We generated two lids');
generateLidCalls = 0;

const originalUserByUsernameIdentifier = identifierCacheFor(store).getOrCreateRecordIdentifier({
const originalUserByUsernameIdentifier = store.identifierCache.getOrCreateRecordIdentifier({
type: 'user',
id: '@runspired',
});
const originalUserByIdIdentifier = identifierCacheFor(store).getOrCreateRecordIdentifier({
const originalUserByIdIdentifier = store.identifierCache.getOrCreateRecordIdentifier({
type: 'user',
id: '1',
});
Expand Down Expand Up @@ -429,22 +431,21 @@ module('Integration | Identifiers - configuration', function (hooks) {
});

test(`The forget method is called when a record deletion is fully persisted and the record unloaded`, async function (assert) {
const adapter = store.adapterFor('application');

adapter.deleteRecord = () => {
return resolve({
data: null,
});
};

let forgetMethodCalls = 0;
let expectedIdentifier;

setIdentifierForgetMethod((identifier) => {
forgetMethodCalls++;
assert.ok(expectedIdentifier === identifier, `We forgot the expected identifier ${expectedIdentifier}`);
});
const store = this.owner.lookup('service:store');
const adapter = store.adapterFor('application');

adapter.deleteRecord = () => {
return resolve({
data: null,
});
};
const user: any = store.push({
data: {
type: 'user',
Expand Down Expand Up @@ -510,6 +511,7 @@ module('Integration | Identifiers - configuration', function (hooks) {
});

// no retainers
const store = this.owner.lookup('service:store');
const freeWillie: any = store.push({
data: {
type: 'user',
Expand Down
Loading

0 comments on commit 1829495

Please sign in to comment.