generated from actions/hello-world-javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnotify.test.js
More file actions
45 lines (43 loc) · 1.27 KB
/
notify.test.js
File metadata and controls
45 lines (43 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { describe, test, expect, beforeEach, vi } from "vitest";
import { notify } from "./notify";
import core from "@actions/core";
vi.mock("@actions/core", () => ({
default: {
getInput: vi.fn(),
setFailed: vi.fn(),
setOutput: vi.fn(),
},
}));
describe("notify", () => {
beforeEach(() => {
vi.resetAllMocks();
global.fetch = vi.fn().mockResolvedValue({ json: vi.fn() });
});
test("makes a post request with the given input", async () => {
core.getInput
.mockImplementationOnce(() => "example@example.com")
.mockImplementationOnce(() => "the subject")
.mockImplementationOnce(() => "the body");
await notify();
expect(global.fetch).toHaveBeenCalledWith(
"https://www.cinotify.cc/api/notify",
expect.objectContaining({
body: expect.stringMatching(
/to(.*)example@example.com(.*)subject(.*)the subject(.*)body(.*)the body/
),
})
);
});
test("errors on status >= 300", async () => {
const response = JSON.stringify({
errors: [{ message: "Does not contain a valid address." }],
});
global.fetch.mockResolvedValueOnce(
new Response(response, {
status: 400,
})
);
await notify();
expect(core.setFailed).toHaveBeenCalledWith(response);
});
});