Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -346,22 +346,33 @@ module(
if (consumerSaveCount === 1) {
// the first time we save the consumer we set the relationship to null
// as we are still waiting for the other realm to assign an ID to the new linked card
assert.strictEqual(doc.included!.length, 1);
assert.strictEqual(
doc.included![0].id,
`${testRealmURL}Pet/mango`,
"the side loaded resources don't include the newly created card yet",
let newFriendLink = (
doc.data?.relationships?.['friends.1'] as
| { links?: { self?: string | null } }
| undefined
)?.links?.self;
assert.notOk(
newFriendLink,
'the "friends.1" relationship names nothing while the new card is unsaved',
);
assert.notOk(
doc.included,
'and the save answers with the consumer alone, side-loading none of its links',
);
}
if (consumerSaveCount === 2) {
// as soon as the other realm assigns an id to the linked card we then
// save the consumer with a relationship to the linked card's id
assert.deepEqual(
doc.data?.relationships?.['friends.1'],
{
links: { self: newLinkId! },
data: { type: 'card', id: newLinkId! },
},
// A write echoes relationships as the card stores them, so the
// link is what it names — the resolved target a readback would
// have added is not part of this answer.
assert.strictEqual(
(
doc.data?.relationships?.['friends.1'] as
| { links?: { self?: string | null } }
| undefined
)?.links?.self,
newLinkId!,
'the "friends.1" relationship was populated with the linked card\'s new id',
);
consumerSaved.fulfill();
Expand Down
36 changes: 8 additions & 28 deletions packages/host/tests/integration/components/card-copy-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ module('Integration | card-copy', function (hooks) {
});

test<TestContextWithSave>('can copy a card that has a relative link to card in source realm', async function (assert) {
assert.expect(15);
assert.expect(12);
await setCardInOperatorModeState(
[`${testRealmURL}index`],
[`${testRealm2URL}index`],
Expand Down Expand Up @@ -1030,21 +1030,11 @@ module('Integration | card-copy', function (hooks) {
links: {
self: `${testRealmURL}Pet/mango`,
},
data: {
type: 'card',
id: `${testRealmURL}Pet/mango`,
},
},
});
assert.strictEqual(json.included?.length, 1);
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
let included = json.included?.[0]!;
assert.strictEqual(included.id, `${testRealmURL}Pet/mango`);
assert.deepEqual(included.meta.adoptsFrom, {
module: rri('../pet'),
name: 'Pet',
});
assert.deepEqual(included.meta.realmURL, testRealmURL);
// A write answers with the written card alone, so the linked pet is
// named by the relationship above and not carried as a resource.
assert.strictEqual(json.included, undefined);
});

await click(
Expand Down Expand Up @@ -1112,7 +1102,7 @@ module('Integration | card-copy', function (hooks) {
});

test<TestContextWithSave>('can copy a card that has a link to card in destination realm', async function (assert) {
assert.expect(15);
assert.expect(12);
await setCardInOperatorModeState(
[`${testRealmURL}index`],
[`${testRealm2URL}index`],
Expand Down Expand Up @@ -1164,21 +1154,11 @@ module('Integration | card-copy', function (hooks) {
links: {
self: `../Pet/paper`, // we should recognize that the link is now in the same realm and should be a relative path
},
data: {
type: 'card',
id: `${testRealm2URL}Pet/paper`,
},
},
});
assert.strictEqual(json.included?.length, 1);
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
let included = json.included?.[0]!;
assert.strictEqual(included.id, `${testRealm2URL}Pet/paper`);
assert.deepEqual(included.meta.adoptsFrom, {
module: testRRI('pet'),
name: 'Pet',
});
assert.deepEqual(included.meta.realmURL, testRealm2URL);
// A write answers with the written card alone, so the linked pet is
// named by the relationship above and not carried as a resource.
assert.strictEqual(json.included, undefined);
});

let realmEventTimestampStart = Date.now();
Expand Down
169 changes: 0 additions & 169 deletions packages/host/tests/integration/realm-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,6 @@ module('Integration | realm', function (hooks) {
assert.strictEqual(response.status, 201, 'successful http status');
let json = await response.json();
let id = json.data.id.split('/').pop()!;
let ownerCreatedAt = await getFileCreatedAt(realm, 'dir/owner.json');
let petCreatedAt = await getFileCreatedAt(realm, `Pet/${id}.json`);
assert.ok(uuidValidate(id), 'card ID is a UUID');
assert.deepEqual(json, {
Expand All @@ -775,10 +774,6 @@ module('Integration | realm', function (hooks) {
links: {
self: `../dir/owner`,
},
data: {
type: 'card',
id: `${testRealmURL}dir/owner`,
},
},
},
meta: {
Expand All @@ -797,38 +792,6 @@ module('Integration | realm', function (hooks) {
self: `${testRealmURL}Pet/${id}`,
},
},
included: [
{
type: 'card',
id: `${testRealmURL}dir/owner`,
attributes: {
cardDescription: 'Person',
email: null,
posts: null,
cardThumbnailURL: null,
firstName: 'Hassan',
lastName: 'Abdel-Rahman',
cardTitle: 'Hassan Abdel-Rahman',
fullName: 'Hassan Abdel-Rahman',
cardInfo,
},
meta: {
adoptsFrom: {
module: `${testModuleRealm}person`,
name: 'Person',
},
lastModified: adapter.lastModifiedMap.get(
`${testRealmURL}dir/owner.json`,
),
resourceCreatedAt: ownerCreatedAt!,
realmInfo: testRealmInfo,
realmURL: testRealmURL,
},
links: {
self: `./owner`,
},
},
],
});
let fileRef = await adapter.openFile(`Pet/${id}.json`);
if (!fileRef) {
Expand Down Expand Up @@ -1270,8 +1233,6 @@ module('Integration | realm', function (hooks) {
},
});
let resourceCreatedAt = await getFileCreatedAt(realm, 'jackie.json');
let friendCreatedAt = await getFileCreatedAt(realm, 'dir/friend.json');
let vanGoghCreatedAt = await getFileCreatedAt(realm, 'dir/van-gogh.json');
let response = await handle(
realm,
new Request(`${testRealmURL}jackie`, {
Expand Down Expand Up @@ -1318,17 +1279,9 @@ module('Integration | realm', function (hooks) {
relationships: {
'pets.0': {
links: { self: `./dir/van-gogh` },
data: {
id: `${testRealmURL}dir/van-gogh`,
type: 'card',
},
},
friend: {
links: { self: `./dir/friend` },
data: {
id: `${testRealmURL}dir/friend`,
type: 'card',
},
},
},
meta: {
Expand All @@ -1344,63 +1297,6 @@ module('Integration | realm', function (hooks) {
resourceCreatedAt: resourceCreatedAt!,
},
},
included: [
{
type: 'card',
id: `${testRealmURL}dir/friend`,
links: { self: `./friend` },
attributes: {
cardDescription: 'Person',
email: null,
posts: null,
cardThumbnailURL: null,
firstName: 'Hassan',
lastName: 'Abdel-Rahman',
fullName: 'Hassan Abdel-Rahman',
cardTitle: 'Hassan Abdel-Rahman',
cardInfo,
},
meta: {
adoptsFrom: {
module: `${testModuleRealm}person`,
name: 'Person',
},
lastModified: adapter.lastModifiedMap.get(
`${testRealmURL}dir/friend.json`,
),
resourceCreatedAt: friendCreatedAt!,
realmInfo: testRealmInfo,
realmURL: testRealmURL,
},
},
{
type: 'card',
id: `${testRealmURL}dir/van-gogh`,
links: { self: `./van-gogh` },
attributes: {
firstName: 'Van Gogh',
cardTitle: 'Van Gogh',
cardDescription: null,
cardThumbnailURL: null,
cardInfo,
},
relationships: {
owner: { links: { self: null } },
},
meta: {
adoptsFrom: {
module: `${testModuleRealm}pet`,
name: 'Pet',
},
lastModified: adapter.lastModifiedMap.get(
`${testRealmURL}dir/van-gogh.json`,
),
resourceCreatedAt: vanGoghCreatedAt!,
realmInfo: testRealmInfo,
realmURL: testRealmURL,
},
},
],
});
let fileRef = await adapter.openFile('jackie.json');
if (!fileRef) {
Expand Down Expand Up @@ -1537,24 +1433,12 @@ module('Integration | realm', function (hooks) {
relationships: {
'pets.0': {
links: { self: `./dir/mango` },
data: {
id: `${testRealmURL}dir/mango`,
type: 'card',
},
},
'pets.1': {
links: { self: `./dir/van-gogh` },
data: {
id: `${testRealmURL}dir/van-gogh`,
type: 'card',
},
},
friend: {
links: { self: `./dir/friend` },
data: {
id: `${testRealmURL}dir/friend`,
type: 'card',
},
},
},
meta: {
Expand Down Expand Up @@ -1661,11 +1545,9 @@ module('Integration | realm', function (hooks) {
relationships: {
'pets.0': {
links: { self: `./dir/mango` },
data: { id: `${testRealmURL}dir/mango`, type: 'card' },
},
'pets.1': {
links: { self: `./dir/van-gogh` },
data: { id: `${testRealmURL}dir/van-gogh`, type: 'card' },
},
},
meta: {
Expand Down Expand Up @@ -1774,7 +1656,6 @@ module('Integration | realm', function (hooks) {
assert.deepEqual(json.data.relationships, {
'inners.0.other': {
links: { self: `./2` },
data: { id: `${testRealmURL}2`, type: 'card' },
},
});
assert.deepEqual(
Expand Down Expand Up @@ -2008,14 +1889,9 @@ module('Integration | realm', function (hooks) {
relationships: {
'pets.0': {
links: { self: `./dir/van-gogh` },
data: { id: `${testRealmURL}dir/van-gogh`, type: 'card' },
},
friend: {
links: { self: `./dir/different-friend` },
data: {
id: `${testRealmURL}dir/different-friend`,
type: 'card',
},
},
},
meta: {
Expand Down Expand Up @@ -2151,17 +2027,9 @@ module('Integration | realm', function (hooks) {
relationships: {
friend: {
links: { self: `./dir/different-friend` },
data: {
id: `${testRealmURL}dir/different-friend`,
type: 'card',
},
},
'pets.0': {
links: { self: `./dir/van-gogh` },
data: {
id: `${testRealmURL}dir/van-gogh`,
type: 'card',
},
},
},
meta: {
Expand Down Expand Up @@ -2271,7 +2139,6 @@ module('Integration | realm', function (hooks) {
assert.strictEqual(response.status, 200, 'successful http status');
let json = await response.json();
let mangoCreatedAt = await getFileCreatedAt(realm, 'dir/mango.json');
let marikoCreatedAt = await getFileCreatedAt(realm, 'dir/mariko.json');
assert.deepEqual(json, {
data: {
type: 'card',
Expand All @@ -2288,10 +2155,6 @@ module('Integration | realm', function (hooks) {
links: {
self: `./mariko`,
},
data: {
type: 'card',
id: `${testRealmURL}dir/mariko`,
},
},
},
meta: {
Expand All @@ -2310,38 +2173,6 @@ module('Integration | realm', function (hooks) {
self: `${testRealmURL}dir/mango`,
},
},
included: [
{
type: 'card',
id: `${testRealmURL}dir/mariko`,
attributes: {
firstName: 'Mariko',
lastName: 'Abdel-Rahman',
fullName: 'Mariko Abdel-Rahman',
cardTitle: 'Mariko Abdel-Rahman',
cardDescription: 'Person',
email: null,
posts: null,
cardThumbnailURL: null,
cardInfo,
},
meta: {
adoptsFrom: {
module: `${testModuleRealm}person`,
name: 'Person',
},
lastModified: adapter.lastModifiedMap.get(
`${testRealmURL}dir/mariko.json`,
),
resourceCreatedAt: marikoCreatedAt!,
realmInfo: testRealmInfo,
realmURL: testRealmURL,
},
links: {
self: `./mariko`,
},
},
],
});
let fileRef = await adapter.openFile('dir/mango.json');
if (!fileRef) {
Expand Down
Loading
Loading