Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 69 additions & 19 deletions test/evals/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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';
Expand All @@ -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: {
Expand All @@ -179,20 +198,29 @@ 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;
batch?: number | null;
updatedAt: string;
createdAt: string;
}

/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-kv_select".
*/
export interface PayloadKvSelect<T extends boolean = true> {
key?: T;
data?: T;
}

/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users_select".
*/
export interface UsersSelect<T extends boolean = true> {
updatedAt?: T;
createdAt?: T;
Expand All @@ -211,36 +239,58 @@ export interface UsersSelect<T extends boolean = true> {
expiresAt?: T;
};
}

/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-locked-documents_select".
*/
export interface PayloadLockedDocumentsSelect<T extends boolean = true> {
document?: T;
globalSlug?: T;
user?: T;
updatedAt?: T;
createdAt?: T;
}

/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-preferences_select".
*/
export interface PayloadPreferencesSelect<T extends boolean = true> {
user?: T;
key?: T;
value?: T;
updatedAt?: T;
createdAt?: T;
}

/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-migrations_select".
*/
export interface PayloadMigrationsSelect<T extends boolean = true> {
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 {}
}
}
26 changes: 26 additions & 0 deletions test/joins/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading