-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX reload] fix sync belongsTo reload w/dematerialize (#6158)
- Loading branch information
Showing
2 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
packages/-ember-data/tests/integration/relationships/reload-error-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { setupTest } from 'ember-qunit'; | ||
import { module, test } from 'qunit'; | ||
import Model, { belongsTo, attr } from '@ember-data/model'; | ||
import EmberObject from '@ember/object'; | ||
import { reject } from 'rsvp'; | ||
|
||
module('Relationships | unloading new records', function(hooks) { | ||
setupTest(hooks); | ||
let store; | ||
let entryNode; | ||
|
||
class ErrorAdapter extends EmberObject { | ||
shouldBackgroundReloadRecord() { | ||
return false; | ||
} | ||
shouldBackgroundReloadAll() { | ||
return false; | ||
} | ||
shouldReloadAll() { | ||
return false; | ||
} | ||
shouldReloadRecord() { | ||
return false; | ||
} | ||
findRecord() { | ||
return reject(new Error(`Bad Request`)); | ||
} | ||
} | ||
|
||
class Node extends Model { | ||
@attr() name; | ||
@belongsTo('node', { inverse: null, async: false }) parent; | ||
@belongsTo('node', { inverse: null, async: true }) relatedGraph; | ||
} | ||
|
||
hooks.beforeEach(function() { | ||
const { owner } = this; | ||
owner.register('model:node', Node); | ||
owner.register('adapter:application', ErrorAdapter); | ||
store = owner.lookup('service:store'); | ||
|
||
entryNode = store.push({ | ||
data: { | ||
type: 'node', | ||
id: '2', | ||
attributes: { name: 'entry-node' }, | ||
relationships: { | ||
parent: { data: { type: 'node', id: '1' } }, | ||
relatedGraph: { data: { type: 'node', id: '3' } }, | ||
}, | ||
}, | ||
included: [ | ||
{ | ||
type: 'node', | ||
id: '1', | ||
attributes: { name: 'root' }, | ||
}, | ||
{ | ||
type: 'node', | ||
id: '3', | ||
attributes: { name: 'an async relatedGraph entry' }, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('Reloading a sync belongsTo returns the error thrown', async function(assert) { | ||
try { | ||
await entryNode.belongsTo('parent').reload(); | ||
assert.ok(false, 'No error thrown'); | ||
} catch (e) { | ||
assert.equal(e.message, 'Bad Request', 'We caught the correct error'); | ||
} | ||
}); | ||
|
||
test('Reloading an async belongsTo returns the error thrown', async function(assert) { | ||
try { | ||
await entryNode.belongsTo('relatedGraph').reload(); | ||
assert.ok(false, 'No error thrown'); | ||
} catch (e) { | ||
assert.equal(e.message, 'Bad Request', 'We caught the correct error'); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters