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: refactor: Remove last usages of run in adapter find tests #6944

Merged
merged 2 commits into from
Jan 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 29 additions & 34 deletions packages/-ember-data/tests/integration/adapter/find-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { run } from '@ember/runloop';

import { module, test } from 'qunit';
import { all, defer, Promise, reject, resolve } from 'rsvp';
import { all, allSettled, Promise, reject, resolve } from 'rsvp';

import Adapter from 'ember-data/adapter';
import JSONAPISerializer from 'ember-data/serializers/json-api';
Expand All @@ -13,7 +11,7 @@ import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in
module('integration/adapter/find - Finding Records', function(hooks) {
setupTest(hooks);

testInDebug('It raises an assertion when `undefined` is passed as id (#1705)', function(assert) {
testInDebug('It raises an assertion when `undefined` is passed as id (#1705)', async function(assert) {
const Person = Model.extend({
name: attr('string'),
});
Expand All @@ -24,12 +22,12 @@ module('integration/adapter/find - Finding Records', function(hooks) {

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

assert.expectAssertion(() => {
store.find('person', undefined);
await assert.expectAssertion(async () => {
await store.find('person', undefined);
}, `You cannot pass 'undefined' as id to the store's find method`);

assert.expectAssertion(() => {
store.find('person', null);
await assert.expectAssertion(async () => {
await store.find('person', null);
}, `You cannot pass 'null' as id to the store's find method`);
});

Expand Down Expand Up @@ -74,7 +72,7 @@ module('integration/adapter/find - Finding Records', function(hooks) {
store.findRecord('person', '1');
});

test('When a single record is requested multiple times, all .findRecord() calls are resolved after the promise is resolved', function(assert) {
test('When a single record is requested multiple times, all .findRecord() calls are resolved after the promise is resolved', async function(assert) {
const Person = Model.extend({
name: attr('string'),
});
Expand All @@ -83,40 +81,41 @@ module('integration/adapter/find - Finding Records', function(hooks) {
this.owner.register('adapter:application', Adapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());

const deferred = defer();
let resolveFindRecordPromise;
let findRecordPromise = new Promise(resolve => (resolveFindRecordPromise = resolve));

this.owner.register(
'adapter:person',
Adapter.extend({
findRecord() {
return deferred.promise;
return findRecordPromise;
},
})
);

this.owner.register('serializer:application', JSONAPISerializer.extend());
let store = this.owner.lookup('service:store');

const store = this.owner.lookup('service:store');
const requestOne = store.findRecord('person', '1').then(person => {
assert.equal(person.get('id'), '1');
assert.equal(person.get('name'), 'Braaaahm Dale');
let firstPlayerRequest = store.findRecord('person', '1').then(function(firstPlayerRequest) {
assert.strictEqual(firstPlayerRequest.id, '1');
assert.strictEqual(firstPlayerRequest.name, 'Totono Grisales');
});
const requestTwo = store.findRecord('person', '1').then(post => {
assert.equal(post.get('id'), '1');
assert.equal(post.get('name'), 'Braaaahm Dale');

let secondPlayerRequest = store.findRecord('person', '1').then(function(secondPlayerRequest) {
assert.strictEqual(secondPlayerRequest.id, '1');
assert.strictEqual(secondPlayerRequest.name, 'Totono Grisales');
});

deferred.resolve({
resolveFindRecordPromise({
data: {
id: '1',
type: 'person',
attributes: {
name: 'Braaaahm Dale',
name: 'Totono Grisales',
},
},
});

return Promise.all([requestOne, requestTwo]);
await allSettled([firstPlayerRequest, secondPlayerRequest]);
});

test('When a single record is requested, and the promise is rejected, .findRecord() is rejected.', async function(assert) {
Expand Down Expand Up @@ -231,7 +230,7 @@ module('integration/adapter/find - Finding Records', function(hooks) {
}
});

testInDebug('warns when returned record has different id', function(assert) {
testInDebug('warns when returned record has different id', async function(assert) {
const Person = Model.extend({
name: attr('string'),
});
Expand All @@ -258,13 +257,9 @@ module('integration/adapter/find - Finding Records', function(hooks) {

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

assert.expectWarning(
() =>
run(() => {
store.findRecord('person', 'me');
}),
/You requested a record of type 'person' with id 'me' but the adapter returned a payload with primary data having an id of '1'/
);
await assert.expectWarning(async () => {
await store.findRecord('person', 'me');
}, /You requested a record of type 'person' with id 'me' but the adapter returned a payload with primary data having an id of '1'/);
});

testInDebug('coerces ids before warning when returned record has different id', async function(assert) {
Expand Down Expand Up @@ -303,12 +298,12 @@ module('integration/adapter/find - Finding Records', function(hooks) {

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

assert.expectNoWarning(
() => run(() => store.findRecord('person', '1')),
await assert.expectNoWarning(
async () => await store.findRecord('person', '1'),
/You requested a record of type 'person' with id '1' but the adapter returned a payload with primary data having an id of '1'/
);
assert.expectNoWarning(
() => run(() => store.findRecord('person', '1')),
await assert.expectNoWarning(
async () => await store.findRecord('person', '1'),
/You requested a record of type 'person' with id '1' but the adapter returned a payload with primary data having an id of '1'/
);
});
Expand Down