-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnotion.test.tsx
More file actions
56 lines (48 loc) · 1.44 KB
/
notion.test.tsx
File metadata and controls
56 lines (48 loc) · 1.44 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
46
47
48
49
50
51
52
53
54
55
56
const mockNotion = jest.fn();
jest.mock("@notionhq/client", () => {
const actual = jest.requireActual("@notionhq/client");
return {
...actual,
Client: jest.fn().mockImplementation(() => ({
pages: {
create: mockNotion,
},
})),
isFullPage: jest.fn(() => true),
};
});
jest.mock("../../helpers/slack", () => {
return {
notifyContactCreated: jest.fn(),
};
});
import { notifyContactCreated } from "../../helpers/slack";
import { processContact } from "../../helpers/notion";
const mockSlack = notifyContactCreated as jest.Mock;
const mockData = {
id: "123456789",
email: "test@test.com",
name: "Test Test",
message: "This is a test message",
databaseID: "mocked-notion-database-id",
source: "Unknown",
};
describe("Notion helper", () => {
beforeEach(() => {
mockNotion.mockResolvedValue({
id: "fake-page-id",
url: "https://www.notion.so/Message-from-Test-Test-123456789-fakepageid",
});
mockSlack.mockResolvedValue({ message: "success" });
const { isFullPage } = require("@notionhq/client");
isFullPage.mockImplementation(() => true);
});
describe("processContact", () => {
it("should call createContact and notifyContactCreated", async () => {
const response = await processContact(mockData);
expect(response).toBe("fake-page-id");
expect(mockNotion).toHaveBeenCalledTimes(1);
expect(mockSlack).toHaveBeenCalledTimes(1);
});
});
});