Skip to content

Commit

Permalink
review with lucie
Browse files Browse the repository at this point in the history
  • Loading branch information
xrutayisire committed Dec 13, 2024
1 parent 1586479 commit a39ef40
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/resolveMigrationDocumentData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down
20 changes: 20 additions & 0 deletions test/writeClient-migrate-patch-contentRelationship.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -91,6 +98,19 @@ testMigrationFieldPatching<ContentRelationshipField>(
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,
Expand Down

0 comments on commit a39ef40

Please sign in to comment.