Skip to content

Commit 5eaa445

Browse files
committed
Failing test for remoteId on unloaded relationship with data
In orbitjs#400 @dgeb suggested that even unloaded records should have a type, id, and (if configured) remoteId key when accessed via a relationship that loaded with a `data` property. These tests demonstrate that that works when the related record is already loaded, but fails when it is not.
1 parent c98f1fa commit 5eaa445

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/integration/model-test.ts

+67
Original file line numberDiff line numberDiff line change
@@ -680,4 +680,71 @@ module('Integration - Model', function (hooks) {
680680
assert.strictEqual(jupiter.name, 'Jupiter');
681681
assert.strictEqual(jupiter.hasName, true);
682682
});
683+
684+
test('hasOne contains type, id, and remoteId for loaded record', async function (assert) {
685+
await store.addRecord<Planet>({
686+
type: 'planet',
687+
remoteId: '3',
688+
name: 'Mars'
689+
});
690+
691+
await store.source.update((t) => {
692+
return t.addRecord({
693+
type: 'moon',
694+
id: '4-1',
695+
attributes: {
696+
name: 'Phobos'
697+
},
698+
relationships: {
699+
planet: {
700+
data: t.$normalizeRecordIdentity({
701+
type: 'planet',
702+
key: 'remoteId',
703+
value: '3'
704+
})
705+
}
706+
}
707+
});
708+
});
709+
710+
let phobos = await store.query<Moon>((qb) =>
711+
qb.findRecord({
712+
type: 'moon',
713+
id: '4-1'
714+
})
715+
);
716+
assert.strictEqual(phobos.planet?.type, 'planet', 'has expected type');
717+
assert.ok(phobos.planet?.id, 'has an id');
718+
assert.strictEqual(phobos.planet?.remoteId, '3', 'has expected remoteId');
719+
});
720+
721+
test('hasOne contains type, id, and remoteId for unloaded record', async function (assert) {
722+
await store.source.update((t) => {
723+
return t.addRecord({
724+
type: 'moon',
725+
id: '4-1',
726+
attributes: {
727+
name: 'Phobos'
728+
},
729+
relationships: {
730+
planet: {
731+
data: t.$normalizeRecordIdentity({
732+
type: 'planet',
733+
key: 'remoteId',
734+
value: '3'
735+
})
736+
}
737+
}
738+
});
739+
});
740+
let phobos = await store.query<Moon>((qb) =>
741+
qb.findRecord({
742+
type: 'moon',
743+
id: '4-1'
744+
})
745+
);
746+
assert.strictEqual(phobos.planet?.type, 'planet', 'has expected type');
747+
assert.ok(phobos.planet?.id, 'has an id');
748+
assert.strictEqual(phobos.planet?.remoteId, '3', 'has expected remoteId');
749+
});
683750
});

0 commit comments

Comments
 (0)