Skip to content

Commit

Permalink
test: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Dec 17, 2024
1 parent c95b19d commit c0f32ef
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/lib/getOptionalLinkProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const getOptionalLinkProperties = (
): OptionalLinkProperties => {
const res: OptionalLinkProperties = {}

if ("variant" in input) {
res.variant = input.variant
}

if ("text" in input) {
res.text = input.text
}
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
27 changes: 23 additions & 4 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 @@ -86,11 +93,23 @@ testMigrationFieldPatching<ContentRelationshipField>(
contentRelationship.id =
otherFromPrismicDocument.originalPrismicDocument!.id

// TODO: Remove when link text PR is merged
// @ts-expect-error - Future-proofing for link text
contentRelationship.text = "foo"
return {
...contentRelationship,
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
return {
...contentRelationship,
variant: "Secondary",
}
},
broken: () => {
return {
Expand Down

0 comments on commit c0f32ef

Please sign in to comment.