Skip to content

Commit fba3d9a

Browse files
committed
🧪 All repo test cases
1 parent 242e576 commit fba3d9a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

__tests__/repository/paginate.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
setupTestTables,
88
} from "../../test-setup";
99
import { Repository } from "../../src/repository/repository";
10+
import { asc, desc } from "../../src";
1011

1112
describe("Repository Pagination", () => {
1213
let postRepository: Repository<DomainPost>;
@@ -48,4 +49,34 @@ describe("Repository Pagination", () => {
4849
expect(post.author).toBeUndefined();
4950
});
5051
});
52+
53+
it("should sort users by age in ascending order", async () => {
54+
const page = await userRepository.paginate({
55+
page: 1,
56+
limit: 5,
57+
orderBy: [asc("age")],
58+
});
59+
60+
expect(page.nodes).toHaveLength(5);
61+
for (let i = 1; i < page.nodes.length; i++) {
62+
expect(page.nodes[i].age).toBeGreaterThanOrEqual(
63+
page?.nodes?.[i - 1].age ?? 0
64+
);
65+
}
66+
});
67+
68+
it("should sort users by age in descending order", async () => {
69+
const page = await userRepository.paginate({
70+
page: 1,
71+
limit: 5,
72+
orderBy: [desc("age")],
73+
});
74+
75+
expect(page.nodes).toHaveLength(5);
76+
for (let i = 1; i < page.nodes.length; i++) {
77+
expect(page.nodes[i].age ?? 0).toBeLessThanOrEqual(
78+
page.nodes[i - 1].age ?? 0
79+
);
80+
}
81+
});
5182
});

0 commit comments

Comments
 (0)