WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 470866a

Browse files
committed
chore: adds test case for relation field maxDepth
1 parent 95c1650 commit 470866a

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

demo/collections/AllFields.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,6 @@ const AllFields: PayloadCollectionConfig = {
240240
name: 'relationshipMultipleCollections',
241241
relationTo: ['localized-posts', 'conditions'],
242242
},
243-
{
244-
type: 'relationship',
245-
label: 'Relationship with maxDepth',
246-
name: 'relationshipMaxDepth',
247-
relationTo: 'relationship-a',
248-
maxDepth: 1,
249-
},
250243
{
251244
type: 'textarea',
252245
label: 'Textarea',

demo/collections/RelationshipA.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ const RelationshipA: PayloadCollectionConfig = {
4141
localized: true,
4242
hasMany: false,
4343
},
44+
{
45+
name: 'postMaxDepth',
46+
maxDepth: 0,
47+
label: 'Post With MaxDepth',
48+
type: 'relationship',
49+
relationTo: 'relationship-b',
50+
hasMany: false,
51+
},
4452
],
4553
timestamps: true,
4654
};

src/collections/tests/relationships.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe('Collections - REST', () => {
5858
const updateA = await fetch(`${url}/api/relationship-a/${createAData.doc.id}`, {
5959
body: JSON.stringify({
6060
post: documentB.id,
61+
postMaxDepth: documentB.id,
6162
}),
6263
headers,
6364
method: 'put',
@@ -90,5 +91,17 @@ describe('Collections - REST', () => {
9091
expect(nested).not.toHaveProperty('post');
9192
expect(nested).toBe(documentA.id);
9293
});
94+
95+
it('should respect max depth at the field level', async () => {
96+
const response = await fetch(`${url}/api/relationship-a?depth=1`, {
97+
headers,
98+
method: 'get',
99+
});
100+
const data = await response.json();
101+
const [doc] = data.docs;
102+
// asserts postMaxDepth is not populated
103+
expect(doc.postMaxDepth).toBe(documentB.id);
104+
expect(doc.postMaxDepth).not.toHaveProperty('post');
105+
});
93106
});
94107
});

0 commit comments

Comments
 (0)