-
-
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.
fix: dont early exit loop when filtering duplicates from relationship…
… updates (#7882)
- Loading branch information
Showing
8 changed files
with
179 additions
and
61 deletions.
There are no files selected for viewing
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
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
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
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
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
119 changes: 119 additions & 0 deletions
119
packages/record-data/tests/integration/graph/operations-test.ts
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,119 @@ | ||
import { settled } from '@ember/test-helpers'; | ||
|
||
import { module, test } from 'qunit'; | ||
|
||
import { setupTest } from 'ember-qunit'; | ||
|
||
import Model, { attr, hasMany } from '@ember-data/model'; | ||
import { graphFor, ManyRelationship } from '@ember-data/record-data/-private'; | ||
import Store from '@ember-data/store'; | ||
|
||
module('Integration | Graph | Operations', function (hooks) { | ||
setupTest(hooks); | ||
|
||
test('updateRelationship operation filters duplicates', async function (assert) { | ||
const { owner } = this; | ||
|
||
class App extends Model { | ||
@attr name; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
@hasMany('config', { async: false, inverse: null }) configs; | ||
} | ||
|
||
class Config extends Model { | ||
@attr name; | ||
} | ||
|
||
owner.register('service:store', Store); | ||
owner.register('model:app', App); | ||
owner.register('model:config', Config); | ||
const store = owner.lookup('service:store') as Store; | ||
const graph = graphFor(store); | ||
const appIdentifier = store.identifierCache.getOrCreateRecordIdentifier({ type: 'app', id: '1' }); | ||
|
||
graph.push({ | ||
op: 'updateRelationship', | ||
field: 'configs', | ||
record: appIdentifier, | ||
value: { | ||
data: [ | ||
{ type: 'config', id: '1' }, | ||
{ type: 'config', id: '1' }, | ||
{ type: 'config', id: '1' }, | ||
{ type: 'config', id: '2' }, | ||
{ type: 'config', id: '3' }, | ||
{ type: 'config', id: '4' }, | ||
], | ||
}, | ||
}); | ||
await settled(); | ||
|
||
const data = graph.get(appIdentifier, 'configs') as ManyRelationship; | ||
assert.deepEqual( | ||
JSON.parse(JSON.stringify(data.getData())), | ||
{ | ||
data: [ | ||
{ type: 'config', id: '1', lid: '@ember-data:lid-config-1' }, | ||
{ type: 'config', id: '2', lid: '@ember-data:lid-config-2' }, | ||
{ type: 'config', id: '3', lid: '@ember-data:lid-config-3' }, | ||
{ type: 'config', id: '4', lid: '@ember-data:lid-config-4' }, | ||
], | ||
}, | ||
'we have the expected data' | ||
); | ||
}); | ||
|
||
test('replaceRelatedRecords operation filters duplicates in a local replace', async function (assert) { | ||
const { owner } = this; | ||
|
||
class App extends Model { | ||
@attr name; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
@hasMany('config', { async: false, inverse: null }) configs; | ||
} | ||
|
||
class Config extends Model { | ||
@attr name; | ||
} | ||
|
||
owner.register('service:store', Store); | ||
owner.register('model:app', App); | ||
owner.register('model:config', Config); | ||
const store = owner.lookup('service:store') as Store; | ||
const graph = graphFor(store); | ||
const appIdentifier = store.identifierCache.getOrCreateRecordIdentifier({ type: 'app', id: '1' }); | ||
const configIdentifier1 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'config', id: '1' }); | ||
const configIdentifier2 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'config', id: '2' }); | ||
const configIdentifier3 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'config', id: '3' }); | ||
const configIdentifier4 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'config', id: '4' }); | ||
|
||
graph.update({ | ||
op: 'replaceRelatedRecords', | ||
field: 'configs', | ||
record: appIdentifier, | ||
value: [ | ||
configIdentifier1, | ||
configIdentifier1, | ||
configIdentifier1, | ||
configIdentifier2, | ||
configIdentifier3, | ||
configIdentifier4, | ||
], | ||
}); | ||
await settled(); | ||
|
||
const data = graph.get(appIdentifier, 'configs') as ManyRelationship; | ||
assert.deepEqual( | ||
JSON.parse(JSON.stringify(data.getData())), | ||
{ | ||
data: [ | ||
{ type: 'config', id: '1', lid: '@ember-data:lid-config-1' }, | ||
{ type: 'config', id: '2', lid: '@ember-data:lid-config-2' }, | ||
{ type: 'config', id: '3', lid: '@ember-data:lid-config-3' }, | ||
{ type: 'config', id: '4', lid: '@ember-data:lid-config-4' }, | ||
], | ||
}, | ||
'we have the expected data' | ||
); | ||
}); | ||
}); |
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
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