✨ Sort files chronologically + infinite scroll (#535)
This commit is contained in:
+51
@@ -8,6 +8,20 @@ import {
|
||||
comparisonType
|
||||
} from "../../../../../../../../../src/core/platform/services/database/services/orm/repository/repository";
|
||||
|
||||
type SortDirection = "asc" | "desc";
|
||||
|
||||
type SortOption = {
|
||||
[field: string]: SortDirection;
|
||||
};
|
||||
|
||||
interface FindOptions {
|
||||
sort?: SortOption;
|
||||
pagination?: {
|
||||
limitStr: string;
|
||||
page_token: string;
|
||||
};
|
||||
}
|
||||
|
||||
describe('The PostgresQueryBuilder', () => {
|
||||
|
||||
const subj: PostgresQueryBuilder = new PostgresQueryBuilder("");
|
||||
@@ -103,6 +117,43 @@ describe('The PostgresQueryBuilder', () => {
|
||||
expect(query[1]).toEqual([entity.company_id, entity.id]);
|
||||
});
|
||||
|
||||
test('buildSelect query with sort option', async () => {
|
||||
//given
|
||||
const options = { sort: { added: "asc" as SortDirection, id: "desc" as SortDirection } };
|
||||
|
||||
//when
|
||||
const query = subj.buildSelect(TestDbEntity, null, options);
|
||||
|
||||
//then
|
||||
expect(normalizeWhitespace(query[0] as string)).toBe(`SELECT * FROM "test_table" ORDER BY added ASC, id DESC LIMIT 100 OFFSET 0`);
|
||||
expect(query[1]).toEqual([]);
|
||||
});
|
||||
|
||||
test('buildSelect query with pagination', async () => {
|
||||
//given
|
||||
const options = { pagination: { limitStr: "50", page_token: "2" } };
|
||||
|
||||
//when
|
||||
const query = subj.buildSelect(TestDbEntity, null, options);
|
||||
|
||||
//then
|
||||
expect(normalizeWhitespace(query[0] as string)).toBe(`SELECT * FROM "test_table" ORDER BY id DESC LIMIT 50 OFFSET 100`);
|
||||
expect(query[1]).toEqual([]);
|
||||
});
|
||||
|
||||
test('buildSelect query with filter, sort, and pagination', async () => {
|
||||
//given
|
||||
const filter = { id: randomUUID(), company_id: randomUUID() };
|
||||
const options = { sort: { added: "asc" as SortDirection, id: "desc" as SortDirection }, pagination: { limitStr: "10", page_token: "3" } };
|
||||
|
||||
//when
|
||||
const query = subj.buildSelect(TestDbEntity, filter as { [key: string]: any }, options);
|
||||
|
||||
//then
|
||||
expect(normalizeWhitespace(query[0] as string)).toBe(`SELECT * FROM "test_table" WHERE id = $1 AND company_id = $2 ORDER BY added ASC, id DESC LIMIT 10 OFFSET 30`);
|
||||
expect(query[1]).toEqual([filter.id, filter.company_id]);
|
||||
});
|
||||
|
||||
test('buildInsert', async () => {
|
||||
//given
|
||||
const entity = newTestDbEntity();
|
||||
|
||||
Reference in New Issue
Block a user