Skip to content

Commit

Permalink
[CHORE] refactor: Remove runloop usage in integration/store-tests mod…
Browse files Browse the repository at this point in the history
…ule deleteRecord (#6713)

* chore: refactor: Remove runloop usage in integration/store-tests module deleteRecord

* chore: refactor: await for async assertion
  • Loading branch information
dmuneras authored and runspired committed Nov 11, 2019
1 parent 67043ba commit 6784ede
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions packages/-ember-data/tests/integration/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -990,53 +990,51 @@ module('integration/store - findAll', function(hooks) {
module('integration/store - deleteRecord', function(hooks) {
setupTest(hooks);

hooks.beforeEach(function() {
test('Using store#deleteRecord should mark the model for removal', function(assert) {
assert.expect(3);

this.owner.register('model:person', Person);
this.owner.register('model:car', Car);
this.owner.register('adapter:application', RESTAdapter.extend());
this.owner.register('serializer:application', RESTSerializer.extend());
});

test('Using store#deleteRecord should mark the model for removal', function(assert) {
assert.expect(3);

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

let person;

run(() => {
store.push({
data: {
type: 'person',
id: '1',
attributes: {
name: 'Tom Dale',
},
store.push({
data: {
type: 'person',
id: '1',
attributes: {
name: 'Tom Dale',
},
});
person = store.peekRecord('person', 1);
},
});

assert.ok(store.hasRecordForId('person', 1), 'expected the record to be in the store');
person = store.peekRecord('person', '1');

assert.ok(store.hasRecordForId('person', '1'), 'expected the record to be in the store');

let personDeleteRecord = tap(person, 'deleteRecord');

run(() => store.deleteRecord(person));
store.deleteRecord(person);

assert.equal(personDeleteRecord.called.length, 1, 'expected person.deleteRecord to have been called');
assert.ok(person.get('isDeleted'), 'expect person to be isDeleted');
assert.ok(person.isDeleted, 'expect person to be isDeleted');
});

test('Store should accept a null value for `data`', function(assert) {
assert.expect(0);

this.owner.register('adapter:application', RESTAdapter.extend());
this.owner.register('serializer:application', RESTSerializer.extend());

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

run(() => {
store.push({
data: null,
});
});
try {
store.push({ data: null });
} catch (_error) {
assert.ok(false, 'push null value for `data` to store throws an error');
}
});

testInDebug('store#findRecord that returns an array should assert', function(assert) {
Expand All @@ -1048,19 +1046,22 @@ module('integration/store - deleteRecord', function(hooks) {

this.owner.register('adapter:application', ApplicationAdapter);
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('model:car', Car);

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

assert.expectAssertion(() => {
run(() => {
store.findRecord('car', 1);
});
assert.expectAssertion(async () => {
await store.findRecord('car', '1');
}, /expected the primary data returned from a 'findRecord' response to be an object but instead it found an array/);
});

testInDebug('store#didSaveRecord should assert when the response to a save does not include the id', function(
testInDebug('store#didSaveRecord should assert when the response to a save does not include the id', async function(
assert
) {
this.owner.register('model:car', Car);
this.owner.register('adapter:application', RESTAdapter.extend());
this.owner.register('serializer:application', RESTSerializer.extend());

let store = this.owner.lookup('service:store');
let adapter = store.adapterFor('application');

Expand All @@ -1070,8 +1071,8 @@ module('integration/store - deleteRecord', function(hooks) {

let car = store.createRecord('car');

assert.expectAssertion(() => {
run(() => car.save());
await assert.expectAssertion(async () => {
await car.save();
}, /Your car record was saved to the server, but the response does not have an id and no id has been set client side. Records must have ids. Please update the server response to provide an id in the response or generate the id on the client side either before saving the record or while normalizing the response./);

// This is here to transition the model out of the inFlight state to avoid
Expand Down

0 comments on commit 6784ede

Please sign in to comment.