diff --git a/src/lib/resolveMigrationDocumentData.ts b/src/lib/resolveMigrationDocumentData.ts index 16c0f1e1..1938e533 100644 --- a/src/lib/resolveMigrationDocumentData.ts +++ b/src/lib/resolveMigrationDocumentData.ts @@ -54,7 +54,13 @@ export async function resolveMigrationContentRelationship( } } - return { link_type: LinkType.Document, id: relation.id } + // This is only called when resolveMigrationContentRelationship recursively + // calls itself from the statement above and the resolved content relation + // is a Prismic document value. + return { + link_type: LinkType.Document, + id: relation.id, + } } return { link_type: LinkType.Document } diff --git a/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap b/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap index 337e410a..4944facd 100644 --- a/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap +++ b/test/__snapshots__/writeClient-migrate-patch-contentRelationship.test.ts.snap @@ -266,6 +266,97 @@ exports[`patches content relationship fields (from Prismic) > withText > static } `; +exports[`patches content relationship fields (from Prismic) > withVariant > group 1`] = ` +{ + "group": [ + { + "field": { + "id": "other.id-fromPrismic", + "link_type": "Document", + "variant": "Secondary", + }, + }, + ], +} +`; + +exports[`patches content relationship fields (from Prismic) > withVariant > shared slice 1`] = ` +{ + "slices": [ + { + "id": "9b9dd0f2c3f", + "items": [ + { + "field": { + "id": "other.id-fromPrismic", + "link_type": "Document", + "variant": "Secondary", + }, + }, + ], + "primary": { + "field": { + "id": "other.id-fromPrismic", + "link_type": "Document", + "variant": "Secondary", + }, + "group": [ + { + "field": { + "id": "other.id-fromPrismic", + "link_type": "Document", + "variant": "Secondary", + }, + }, + ], + }, + "slice_label": null, + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", + }, + ], +} +`; + +exports[`patches content relationship fields (from Prismic) > withVariant > slice 1`] = ` +{ + "slices": [ + { + "id": "5306297c5ed", + "items": [ + { + "field": { + "id": "other.id-fromPrismic", + "link_type": "Document", + "variant": "Secondary", + }, + }, + ], + "primary": { + "field": { + "id": "other.id-fromPrismic", + "link_type": "Document", + "variant": "Secondary", + }, + }, + "slice_label": "Vel", + "slice_type": "hac_habitasse", + }, + ], +} +`; + +exports[`patches content relationship fields (from Prismic) > withVariant > static zone 1`] = ` +{ + "field": { + "id": "other.id-fromPrismic", + "link_type": "Document", + "variant": "Secondary", + }, +} +`; + exports[`patches content relationship fields > existing > group 1`] = ` { "group": [ @@ -525,6 +616,97 @@ exports[`patches content relationship fields > existingLongFormWithText > static } `; +exports[`patches content relationship fields > existingLongFormWithVariant > group 1`] = ` +{ + "group": [ + { + "field": { + "id": "other.id-existing", + "link_type": "Document", + "variant": "Secondary", + }, + }, + ], +} +`; + +exports[`patches content relationship fields > existingLongFormWithVariant > shared slice 1`] = ` +{ + "slices": [ + { + "id": "9b9dd0f2c3f", + "items": [ + { + "field": { + "id": "other.id-existing", + "link_type": "Document", + "variant": "Secondary", + }, + }, + ], + "primary": { + "field": { + "id": "other.id-existing", + "link_type": "Document", + "variant": "Secondary", + }, + "group": [ + { + "field": { + "id": "other.id-existing", + "link_type": "Document", + "variant": "Secondary", + }, + }, + ], + }, + "slice_label": null, + "slice_type": "nunc", + "variation": "ullamcorper", + "version": "8bfc905", + }, + ], +} +`; + +exports[`patches content relationship fields > existingLongFormWithVariant > slice 1`] = ` +{ + "slices": [ + { + "id": "5306297c5ed", + "items": [ + { + "field": { + "id": "other.id-existing", + "link_type": "Document", + "variant": "Secondary", + }, + }, + ], + "primary": { + "field": { + "id": "other.id-existing", + "link_type": "Document", + "variant": "Secondary", + }, + }, + "slice_label": "Vel", + "slice_type": "hac_habitasse", + }, + ], +} +`; + +exports[`patches content relationship fields > existingLongFormWithVariant > static zone 1`] = ` +{ + "field": { + "id": "other.id-existing", + "link_type": "Document", + "variant": "Secondary", + }, +} +`; + exports[`patches content relationship fields > lazyExisting > group 1`] = ` { "group": [ diff --git a/test/writeClient-migrate-patch-contentRelationship.test.ts b/test/writeClient-migrate-patch-contentRelationship.test.ts index 40c926f3..46334e83 100644 --- a/test/writeClient-migrate-patch-contentRelationship.test.ts +++ b/test/writeClient-migrate-patch-contentRelationship.test.ts @@ -25,6 +25,13 @@ testMigrationFieldPatching< text: "foo", } }, + existingLongFormWithVariant: ({ existingDocuments }) => { + return { + link_type: LinkType.Document, + id: existingDocuments[0], + variant: "Secondary", + } + }, otherCreate: ({ otherCreateDocument }) => otherCreateDocument, lazyExisting: ({ existingDocuments }) => { return () => existingDocuments[0] @@ -91,6 +98,19 @@ testMigrationFieldPatching( text: "foo", } }, + withVariant: ({ ctx, otherFromPrismicDocument }) => { + const contentRelationship = ctx.mock.value.link({ + type: LinkType.Document, + }) + // `migrationDocuments` contains documents from "another repository" + contentRelationship.id = + otherFromPrismicDocument.originalPrismicDocument!.id + + return { + ...contentRelationship, + variant: "Secondary", + } + }, broken: () => { return { link_type: LinkType.Document,