-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api] migrate testing framework (Jest > Vitest) (#3555)
- Loading branch information
Showing
47 changed files
with
977 additions
and
3,082 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,32 +1,40 @@ | ||
import { createScheduledEvent, RequiredScheduledEventArgs } from "./index.js"; | ||
import Axios, { AxiosError } from "axios"; | ||
import axios from "axios"; | ||
import type { Mocked } from "vitest"; | ||
|
||
jest.mock("axios", () => ({ | ||
...jest.requireActual("axios"), | ||
post: jest.fn(), | ||
})); | ||
const mockAxios = Axios as jest.Mocked<typeof Axios>; | ||
describe("Creation of scheduled event", () => { | ||
vi.mock("axios", async (importOriginal) => { | ||
const actualAxios = await importOriginal<typeof import("axios")>(); | ||
return { | ||
default: { | ||
...actualAxios, | ||
post: vi.fn(), | ||
}, | ||
}; | ||
}); | ||
const mockAxios = axios as Mocked<typeof axios>; | ||
|
||
const mockScheduledEvent: RequiredScheduledEventArgs = { | ||
webhook: "test url", | ||
schedule_at: new Date(), | ||
comment: "test comment", | ||
payload: {}, | ||
}; | ||
const mockScheduledEvent: RequiredScheduledEventArgs = { | ||
webhook: "test url", | ||
schedule_at: new Date(), | ||
comment: "test comment", | ||
payload: {}, | ||
}; | ||
|
||
test("createScheduledEvent returns an error if request fails", async () => { | ||
mockAxios.post.mockRejectedValue(new Error()); | ||
await expect(createScheduledEvent(mockScheduledEvent)).rejects.toThrow(); | ||
}); | ||
test("returns an error if request fails", async () => { | ||
mockAxios.post.mockRejectedValue(new Error()); | ||
await expect(createScheduledEvent(mockScheduledEvent)).rejects.toThrow(); | ||
}); | ||
|
||
test("createScheduledEvent returns an error if Axios errors", async () => { | ||
mockAxios.post.mockRejectedValue(new AxiosError()); | ||
await expect(createScheduledEvent(mockScheduledEvent)).rejects.toThrow(); | ||
}); | ||
test("returns an error if axios errors", async () => { | ||
mockAxios.post.mockRejectedValue(new axios.AxiosError()); | ||
await expect(createScheduledEvent(mockScheduledEvent)).rejects.toThrow(); | ||
}); | ||
|
||
test("createScheduledEvent returns response data on success", async () => { | ||
mockAxios.post.mockResolvedValue({ data: "test data" }); | ||
await expect(createScheduledEvent(mockScheduledEvent)).resolves.toBe( | ||
"test data", | ||
); | ||
test("returns response data on success", async () => { | ||
mockAxios.post.mockResolvedValue({ data: "test data" }); | ||
await expect(createScheduledEvent(mockScheduledEvent)).resolves.toBe( | ||
"test data", | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,25 +1,33 @@ | ||
import { runSQL } from "./index.js"; | ||
import Axios, { AxiosError } from "axios"; | ||
import axios from "axios"; | ||
import type { Mocked } from "vitest"; | ||
|
||
jest.mock("axios", () => ({ | ||
...jest.requireActual("axios"), | ||
post: jest.fn(), | ||
})); | ||
const mockAxios = Axios as jest.Mocked<typeof Axios>; | ||
describe("runSQL", () => { | ||
vi.mock("axios", async (importOriginal) => { | ||
const actualAxios = await importOriginal<typeof import("axios")>(); | ||
return { | ||
default: { | ||
...actualAxios, | ||
post: vi.fn(), | ||
}, | ||
}; | ||
}); | ||
const mockAxios = axios as Mocked<typeof axios>; | ||
|
||
const sql = "SELECT * FROM TEST"; | ||
const sql = "SELECT * FROM TEST"; | ||
|
||
test("runSQL returns an error if request fails", async () => { | ||
mockAxios.post.mockRejectedValue(new Error()); | ||
await expect(runSQL(sql)).rejects.toThrow(); | ||
}); | ||
test("returns an error if request fails", async () => { | ||
mockAxios.post.mockRejectedValue(new Error()); | ||
await expect(runSQL(sql)).rejects.toThrow(); | ||
}); | ||
|
||
test("runSQL returns an error if Axios errors", async () => { | ||
mockAxios.post.mockRejectedValue(new AxiosError()); | ||
await expect(runSQL(sql)).rejects.toThrow(); | ||
}); | ||
test("returns an error if Axios errors", async () => { | ||
mockAxios.post.mockRejectedValue(new axios.AxiosError()); | ||
await expect(runSQL(sql)).rejects.toThrow(); | ||
}); | ||
|
||
test("runSQL returns response data on success", async () => { | ||
mockAxios.post.mockResolvedValue({ data: "test data" }); | ||
await expect(runSQL(sql)).resolves.toBe("test data"); | ||
test("returns response data on success", async () => { | ||
mockAxios.post.mockResolvedValue({ data: "test data" }); | ||
await expect(runSQL(sql)).resolves.toBe("test data"); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ import { sendEmail } from "./index.js"; | |
import { NotifyClient } from "notifications-node-client"; | ||
import { NotifyConfig } from "../../types.js"; | ||
|
||
jest.mock("notifications-node-client"); | ||
vi.mock("notifications-node-client"); | ||
|
||
const TEST_EMAIL = "[email protected]"; | ||
const mockConfig: NotifyConfig = { | ||
|
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
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
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
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
Oops, something went wrong.