-
Notifications
You must be signed in to change notification settings - Fork 42
Failing test for remoteId on unloaded relationship with data #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test passes