-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { describe, it, vi } from "vitest"; | ||
|
||
const { mockDelete, mockSchedule, mockWhere } = vi.hoisted(() => ({ | ||
mockDelete: vi.fn(), | ||
mockSchedule: vi.fn(), | ||
mockWhere: vi.fn(() => ({ | ||
delete: mockDelete, | ||
select: () => [{ id: 1234 }], | ||
})), | ||
})); | ||
|
||
vi.mock("knex", () => ({ default: () => () => ({ where: mockWhere }) })); | ||
vi.mock("node-cron", () => ({ schedule: mockSchedule })); | ||
|
||
describe("purge cronjob", async () => { | ||
await import("../../../src/back-end/cronjobs/purge"); | ||
|
||
it("deletes expired stories and associated votes", async ({ expect }) => { | ||
await mockSchedule.mock.lastCall![1](new Date()); | ||
|
||
expect(mockWhere).toHaveBeenCalledWith("storyId", 1234); | ||
expect(mockWhere).toHaveBeenCalledWith("id", 1234); | ||
expect(mockDelete).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { readFile, writeFile } from "fs"; | ||
import { describe, it, vi } from "vitest"; | ||
import transform from "../../src/tasks/transform"; | ||
|
||
const { mockPromisify, mockWriteFile } = vi.hoisted(() => ({ | ||
mockPromisify: (arg: unknown) => { | ||
switch (arg) { | ||
case readFile: | ||
return () => '<link href="/test" />'; | ||
case writeFile: | ||
return mockWriteFile; | ||
} | ||
}, | ||
mockWriteFile: vi.fn(), | ||
})); | ||
|
||
vi.mock("util", () => ({ default: { promisify: mockPromisify } })); | ||
|
||
describe("transform task", () => { | ||
it("keeps links intact when rootURI is /", async ({ expect }) => { | ||
vi.stubEnv("ROOT_URI", "/"); | ||
|
||
await transform(); | ||
|
||
expect(mockWriteFile).toHaveBeenCalledWith( | ||
expect.anything(), | ||
'<link href="/test" />', | ||
); | ||
}); | ||
|
||
it("reformats links when rootURI is custom", async ({ expect }) => { | ||
vi.stubEnv("ROOT_URI", "/prefix/"); | ||
|
||
await transform(); | ||
|
||
expect(mockWriteFile).toHaveBeenCalledWith( | ||
expect.anything(), | ||
'<link href="/prefix/test" />', | ||
); | ||
}); | ||
}); |