diff --git a/test/evals/payload-types.ts b/test/evals/payload-types.ts index 25669be4fc5..6ee60de2210 100644 --- a/test/evals/payload-types.ts +++ b/test/evals/payload-types.ts @@ -6,6 +6,12 @@ * and re-run `payload generate:types` to regenerate this file. */ +/** + * Supported timezones in IANA format. + * + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "supportedTimezones". + */ export type SupportedTimezones = | 'Pacific/Midway' | 'Pacific/Niue' @@ -82,13 +88,15 @@ export interface Config { globals: {}; globalsSelect: {}; locale: null; + widgets: { + collections: CollectionsWidget; + }; user: User; jobs: { tasks: unknown; workflows: unknown; }; } - export interface UserAuthOperations { forgotPassword: { email: string; @@ -107,7 +115,10 @@ export interface UserAuthOperations { password: string; }; } - +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "payload-kv". + */ export interface PayloadKv { id: string; key: string; @@ -121,7 +132,10 @@ export interface PayloadKv { | boolean | null; } - +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "users". + */ export interface User { id: string; updatedAt: string; @@ -143,14 +157,16 @@ export interface User { password?: string | null; collection: 'users'; } - +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "payload-locked-documents". + */ export interface PayloadLockedDocument { id: string; - document?: - | ({ - relationTo: 'users'; - value: string | User; - } | null); + document?: { + relationTo: 'users'; + value: string | User; + } | null; globalSlug?: string | null; user: { relationTo: 'users'; @@ -159,7 +175,10 @@ export interface PayloadLockedDocument { updatedAt: string; createdAt: string; } - +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "payload-preferences". + */ export interface PayloadPreference { id: string; user: { @@ -179,7 +198,10 @@ export interface PayloadPreference { updatedAt: string; createdAt: string; } - +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "payload-migrations". + */ export interface PayloadMigration { id: string; name?: string | null; @@ -187,12 +209,18 @@ export interface PayloadMigration { updatedAt: string; createdAt: string; } - +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "payload-kv_select". + */ export interface PayloadKvSelect { key?: T; data?: T; } - +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "users_select". + */ export interface UsersSelect { updatedAt?: T; createdAt?: T; @@ -211,7 +239,10 @@ export interface UsersSelect { expiresAt?: T; }; } - +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "payload-locked-documents_select". + */ export interface PayloadLockedDocumentsSelect { document?: T; globalSlug?: T; @@ -219,7 +250,10 @@ export interface PayloadLockedDocumentsSelect { updatedAt?: T; createdAt?: T; } - +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "payload-preferences_select". + */ export interface PayloadPreferencesSelect { user?: T; key?: T; @@ -227,20 +261,36 @@ export interface PayloadPreferencesSelect { updatedAt?: T; createdAt?: T; } - +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "payload-migrations_select". + */ export interface PayloadMigrationsSelect { name?: T; batch?: T; updatedAt?: T; createdAt?: T; } - +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "collections_widget". + */ +export interface CollectionsWidget { + data?: { + [k: string]: unknown; + }; + width: 'full'; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "auth". + */ export interface Auth { [k: string]: unknown; } declare module 'payload' { - // @ts-ignore + // @ts-ignore export interface GeneratedTypes extends Config {} -} +} \ No newline at end of file diff --git a/test/joins/int.spec.ts b/test/joins/int.spec.ts index 0df9b491934..a58a92af0a7 100644 --- a/test/joins/int.spec.ts +++ b/test/joins/int.spec.ts @@ -499,6 +499,32 @@ describe('Joins Field', () => { expect(categoryWithPosts.relatedPosts.hasNextPage).toStrictEqual(false) }) + it('should apply defaultSort when no sort is specified in join query', async () => { + const categoryWithPosts = await payload.findByID({ + id: category.id, + collection: categoriesSlug, + }) + + // relatedPosts join has defaultSort: '-title', defaultLimit: 5 + expect(categoryWithPosts.relatedPosts!.docs).toHaveLength(5) + expect((categoryWithPosts.relatedPosts!.docs![0] as Post).title).toStrictEqual('test 9') + }) + + it('should override defaultSort when sort is specified in join query', async () => { + const categoryWithPosts = await payload.findByID({ + id: category.id, + collection: categoriesSlug, + joins: { + relatedPosts: { + sort: 'title', + }, + }, + }) + + // ascending sort overrides defaultSort: '-title' + expect((categoryWithPosts.relatedPosts!.docs![0] as Post).title).toStrictEqual('test 0') + }) + it('should populate joins using find', async () => { const result = await payload.find({ collection: categoriesSlug,