Skip to content

Commit 2b6d01b

Browse files
committed
test(api): update sorting tests for lastModified property
1 parent a4edd29 commit 2b6d01b

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

apps/api/test/routes/v1_files/$wildcard.test.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -867,10 +867,11 @@ describe("v1_files", () => {
867867
});
868868

869869
it("should sort by lastModified ascending", async () => {
870+
const now = Date.now();
870871
const html = generateAutoIndexHtml([
871-
{ name: "Blocks.txt", path: "Blocks.txt", type: "file", lastModified: Date.now() },
872-
{ name: "UnicodeData.txt", path: "UnicodeData.txt", type: "file", lastModified: Date.now() },
873-
{ name: "ArabicShaping.txt", path: "ArabicShaping.txt", type: "file", lastModified: Date.now() },
872+
{ name: "Blocks.txt", path: "Blocks.txt", type: "file", lastModified: now - 2000 },
873+
{ name: "UnicodeData.txt", path: "UnicodeData.txt", type: "file", lastModified: now - 1000 },
874+
{ name: "ArabicShaping.txt", path: "ArabicShaping.txt", type: "file", lastModified: now - 3000 },
874875
], "F2");
875876

876877
mockFetch([
@@ -896,19 +897,18 @@ describe("v1_files", () => {
896897
expect(results).toHaveLength(3);
897898
expect(results.every((r) => typeof r.lastModified === "number")).toBe(true);
898899

899-
// Verify sorted by lastModified descending
900-
let prev: number | null = results.at(-1)!.lastModified;
900+
// Verify sorted by lastModified ascending (oldest first)
901901
for (let i = 1; i < results.length; i++) {
902-
expect(results[i]!.lastModified).toBeLessThanOrEqual(prev!);
903-
prev = results[i]!.lastModified;
902+
expect(results[i]!.lastModified!).toBeGreaterThanOrEqual(results[i - 1]!.lastModified!);
904903
}
905904
});
906905

907906
it("should sort by lastModified descending", async () => {
907+
const now = Date.now();
908908
const html = generateAutoIndexHtml([
909-
{ name: "Blocks.txt", path: "Blocks.txt", type: "file", lastModified: Date.now() },
910-
{ name: "UnicodeData.txt", path: "UnicodeData.txt", type: "file", lastModified: Date.now() },
911-
{ name: "ArabicShaping.txt", path: "ArabicShaping.txt", type: "file", lastModified: Date.now() },
909+
{ name: "Blocks.txt", path: "Blocks.txt", type: "file", lastModified: now - 2000 },
910+
{ name: "UnicodeData.txt", path: "UnicodeData.txt", type: "file", lastModified: now - 1000 },
911+
{ name: "ArabicShaping.txt", path: "ArabicShaping.txt", type: "file", lastModified: now - 3000 },
912912
], "F2");
913913

914914
mockFetch([
@@ -934,11 +934,9 @@ describe("v1_files", () => {
934934
expect(results).toHaveLength(3);
935935
expect(results.every((r) => typeof r.lastModified === "number")).toBe(true);
936936

937-
// Verify sorted by lastModified descending
938-
let prev: number | null = results.at(-1)!.lastModified;
937+
// Verify sorted by lastModified descending (newest first)
939938
for (let i = 1; i < results.length; i++) {
940-
expect(results[i]!.lastModified).toBeLessThanOrEqual(prev!);
941-
prev = results[i]!.lastModified;
939+
expect(results[i]!.lastModified!).toBeLessThanOrEqual(results[i - 1]!.lastModified!);
942940
}
943941
});
944942

0 commit comments

Comments
 (0)