Skip to content
Open
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
67 changes: 67 additions & 0 deletions tests/integration/model-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,71 @@ module('Integration - Model', function (hooks) {
assert.strictEqual(jupiter.name, 'Jupiter');
assert.strictEqual(jupiter.hasName, true);
});

test('hasOne contains type, id, and remoteId for loaded record', async function (assert) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test passes

await store.addRecord<Planet>({
type: 'planet',
remoteId: '3',
name: 'Mars'
});

await store.source.update((t) => {
return t.addRecord({
type: 'moon',
id: '4-1',
attributes: {
name: 'Phobos'
},
relationships: {
planet: {
data: t.$normalizeRecordIdentity({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure this correctly simulates what happens in a real app that's using a jsonapi source that gets back a server generated id here, but it does reproduce the same behavior I'm seeing in a real app.

type: 'planet',
key: 'remoteId',
value: '3'
})
}
}
});
});

let phobos = await store.query<Moon>((qb) =>
qb.findRecord({
type: 'moon',
id: '4-1'
})
);
assert.strictEqual(phobos.planet?.type, 'planet', 'has expected type');
assert.ok(phobos.planet?.id, 'has an id');
assert.strictEqual(phobos.planet?.remoteId, '3', 'has expected remoteId');
});

test('hasOne contains type, id, and remoteId for unloaded record', async function (assert) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails

await store.source.update((t) => {
return t.addRecord({
type: 'moon',
id: '4-1',
attributes: {
name: 'Phobos'
},
relationships: {
planet: {
data: t.$normalizeRecordIdentity({
type: 'planet',
key: 'remoteId',
value: '3'
})
}
}
});
});
let phobos = await store.query<Moon>((qb) =>
qb.findRecord({
type: 'moon',
id: '4-1'
})
);
assert.strictEqual(phobos.planet?.type, 'planet', 'has expected type');
assert.ok(phobos.planet?.id, 'has an id');
assert.strictEqual(phobos.planet?.remoteId, '3', 'has expected remoteId');
});
});