Skip to content

Commit 2ae670e

Browse files
authored
test(db-mongodb): unit test assertion for relationship sanitization inside blockReferences (#11195)
This PR adds a new unit test assertion to existing https://github.com/payloadcms/payload/blob/main/packages/db-mongodb/src/utilities/sanitizeRelationshipIDs.spec.ts that ensures relationships are sanitized to `ObjectID`s correctly when saved to the database for relationships inside the new `blockReferences` #10905
1 parent 779f511 commit 2ae670e

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

packages/db-mongodb/src/utilities/sanitizeRelationshipIDs.spec.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Field, SanitizedConfig } from 'payload'
1+
import { flattenAllFields, type Field, type SanitizedConfig } from 'payload'
22

33
import { Types } from 'mongoose'
44

@@ -74,7 +74,28 @@ const relsFields: Field[] = [
7474
},
7575
]
7676

77+
const referenceBlockFields: Field[] = [
78+
...relsFields,
79+
{
80+
name: 'group',
81+
type: 'group',
82+
fields: relsFields,
83+
},
84+
{
85+
name: 'array',
86+
type: 'array',
87+
fields: relsFields,
88+
},
89+
]
90+
7791
const config = {
92+
blocks: [
93+
{
94+
slug: 'reference-block',
95+
fields: referenceBlockFields,
96+
flattenedFields: flattenAllFields({ fields: referenceBlockFields }),
97+
},
98+
],
7899
collections: [
79100
{
80101
slug: 'docs',
@@ -137,6 +158,11 @@ const config = {
137158
},
138159
],
139160
},
161+
{
162+
name: 'blockReferences',
163+
type: 'blocks',
164+
blockReferences: ['reference-block'],
165+
},
140166
{
141167
name: 'group',
142168
type: 'group',
@@ -321,6 +347,14 @@ describe('sanitizeRelationshipIDs', () => {
321347
group: { ...relsData },
322348
},
323349
],
350+
blockReferences: [
351+
{
352+
blockType: 'reference-block',
353+
array: [{ ...relsData }],
354+
group: { ...relsData },
355+
...relsData,
356+
},
357+
],
324358
group: {
325359
...relsData,
326360
array: [{ ...relsData }],

0 commit comments

Comments
 (0)