Skip to content

Commit b2a8917

Browse files
authored
test: add defaultSort join field property integration tests (#16057)
Previously this property was tested only in e2e tests - having it in integration tests as well makes it easier to verify whether a db adapter works properly
1 parent e0b3e81 commit b2a8917

File tree

2 files changed

+95
-19
lines changed

2 files changed

+95
-19
lines changed

test/evals/payload-types.ts

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
* and re-run `payload generate:types` to regenerate this file.
77
*/
88

9+
/**
10+
* Supported timezones in IANA format.
11+
*
12+
* This interface was referenced by `Config`'s JSON-Schema
13+
* via the `definition` "supportedTimezones".
14+
*/
915
export type SupportedTimezones =
1016
| 'Pacific/Midway'
1117
| 'Pacific/Niue'
@@ -82,13 +88,15 @@ export interface Config {
8288
globals: {};
8389
globalsSelect: {};
8490
locale: null;
91+
widgets: {
92+
collections: CollectionsWidget;
93+
};
8594
user: User;
8695
jobs: {
8796
tasks: unknown;
8897
workflows: unknown;
8998
};
9099
}
91-
92100
export interface UserAuthOperations {
93101
forgotPassword: {
94102
email: string;
@@ -107,7 +115,10 @@ export interface UserAuthOperations {
107115
password: string;
108116
};
109117
}
110-
118+
/**
119+
* This interface was referenced by `Config`'s JSON-Schema
120+
* via the `definition` "payload-kv".
121+
*/
111122
export interface PayloadKv {
112123
id: string;
113124
key: string;
@@ -121,7 +132,10 @@ export interface PayloadKv {
121132
| boolean
122133
| null;
123134
}
124-
135+
/**
136+
* This interface was referenced by `Config`'s JSON-Schema
137+
* via the `definition` "users".
138+
*/
125139
export interface User {
126140
id: string;
127141
updatedAt: string;
@@ -143,14 +157,16 @@ export interface User {
143157
password?: string | null;
144158
collection: 'users';
145159
}
146-
160+
/**
161+
* This interface was referenced by `Config`'s JSON-Schema
162+
* via the `definition` "payload-locked-documents".
163+
*/
147164
export interface PayloadLockedDocument {
148165
id: string;
149-
document?:
150-
| ({
151-
relationTo: 'users';
152-
value: string | User;
153-
} | null);
166+
document?: {
167+
relationTo: 'users';
168+
value: string | User;
169+
} | null;
154170
globalSlug?: string | null;
155171
user: {
156172
relationTo: 'users';
@@ -159,7 +175,10 @@ export interface PayloadLockedDocument {
159175
updatedAt: string;
160176
createdAt: string;
161177
}
162-
178+
/**
179+
* This interface was referenced by `Config`'s JSON-Schema
180+
* via the `definition` "payload-preferences".
181+
*/
163182
export interface PayloadPreference {
164183
id: string;
165184
user: {
@@ -179,20 +198,29 @@ export interface PayloadPreference {
179198
updatedAt: string;
180199
createdAt: string;
181200
}
182-
201+
/**
202+
* This interface was referenced by `Config`'s JSON-Schema
203+
* via the `definition` "payload-migrations".
204+
*/
183205
export interface PayloadMigration {
184206
id: string;
185207
name?: string | null;
186208
batch?: number | null;
187209
updatedAt: string;
188210
createdAt: string;
189211
}
190-
212+
/**
213+
* This interface was referenced by `Config`'s JSON-Schema
214+
* via the `definition` "payload-kv_select".
215+
*/
191216
export interface PayloadKvSelect<T extends boolean = true> {
192217
key?: T;
193218
data?: T;
194219
}
195-
220+
/**
221+
* This interface was referenced by `Config`'s JSON-Schema
222+
* via the `definition` "users_select".
223+
*/
196224
export interface UsersSelect<T extends boolean = true> {
197225
updatedAt?: T;
198226
createdAt?: T;
@@ -211,36 +239,58 @@ export interface UsersSelect<T extends boolean = true> {
211239
expiresAt?: T;
212240
};
213241
}
214-
242+
/**
243+
* This interface was referenced by `Config`'s JSON-Schema
244+
* via the `definition` "payload-locked-documents_select".
245+
*/
215246
export interface PayloadLockedDocumentsSelect<T extends boolean = true> {
216247
document?: T;
217248
globalSlug?: T;
218249
user?: T;
219250
updatedAt?: T;
220251
createdAt?: T;
221252
}
222-
253+
/**
254+
* This interface was referenced by `Config`'s JSON-Schema
255+
* via the `definition` "payload-preferences_select".
256+
*/
223257
export interface PayloadPreferencesSelect<T extends boolean = true> {
224258
user?: T;
225259
key?: T;
226260
value?: T;
227261
updatedAt?: T;
228262
createdAt?: T;
229263
}
230-
264+
/**
265+
* This interface was referenced by `Config`'s JSON-Schema
266+
* via the `definition` "payload-migrations_select".
267+
*/
231268
export interface PayloadMigrationsSelect<T extends boolean = true> {
232269
name?: T;
233270
batch?: T;
234271
updatedAt?: T;
235272
createdAt?: T;
236273
}
237-
274+
/**
275+
* This interface was referenced by `Config`'s JSON-Schema
276+
* via the `definition` "collections_widget".
277+
*/
278+
export interface CollectionsWidget {
279+
data?: {
280+
[k: string]: unknown;
281+
};
282+
width: 'full';
283+
}
284+
/**
285+
* This interface was referenced by `Config`'s JSON-Schema
286+
* via the `definition` "auth".
287+
*/
238288
export interface Auth {
239289
[k: string]: unknown;
240290
}
241291

242292

243293
declare module 'payload' {
244-
// @ts-ignore
294+
// @ts-ignore
245295
export interface GeneratedTypes extends Config {}
246-
}
296+
}

test/joins/int.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,32 @@ describe('Joins Field', () => {
499499
expect(categoryWithPosts.relatedPosts.hasNextPage).toStrictEqual(false)
500500
})
501501

502+
it('should apply defaultSort when no sort is specified in join query', async () => {
503+
const categoryWithPosts = await payload.findByID({
504+
id: category.id,
505+
collection: categoriesSlug,
506+
})
507+
508+
// relatedPosts join has defaultSort: '-title', defaultLimit: 5
509+
expect(categoryWithPosts.relatedPosts!.docs).toHaveLength(5)
510+
expect((categoryWithPosts.relatedPosts!.docs![0] as Post).title).toStrictEqual('test 9')
511+
})
512+
513+
it('should override defaultSort when sort is specified in join query', async () => {
514+
const categoryWithPosts = await payload.findByID({
515+
id: category.id,
516+
collection: categoriesSlug,
517+
joins: {
518+
relatedPosts: {
519+
sort: 'title',
520+
},
521+
},
522+
})
523+
524+
// ascending sort overrides defaultSort: '-title'
525+
expect((categoryWithPosts.relatedPosts!.docs![0] as Post).title).toStrictEqual('test 0')
526+
})
527+
502528
it('should populate joins using find', async () => {
503529
const result = await payload.find({
504530
collection: categoriesSlug,

0 commit comments

Comments
 (0)