-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetPageModule.test.ts
71 lines (57 loc) · 1.54 KB
/
getPageModule.test.ts
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { contentfulDeliveryClient } from "./contentful";
import getPageModule from "./getPageModule";
jest.mock("./contentful", () => ({
contentfulDeliveryClient: {
getEntries: jest.fn(),
},
}));
const mockedEntryFields = {
content: "test content",
};
afterEach(() => {
jest.clearAllMocks();
});
it("Returns page module entry with all properties", async () => {
(contentfulDeliveryClient.getEntries as jest.Mock).mockImplementation(() => ({
items: [
{
fields: {
...mockedEntryFields,
data: "test data",
},
},
],
}));
const result = await getPageModule("mocked-id");
expect(contentfulDeliveryClient.getEntries).toHaveBeenCalledTimes(1);
expect(contentfulDeliveryClient.getEntries).toHaveBeenNthCalledWith(1, {
content_type: "pageModule",
"fields.id": "mocked-id",
limit: 1,
});
expect(result).toStrictEqual({
content: "test content",
data: "test data",
});
});
it("Returns page module entry with missing properties", async () => {
(contentfulDeliveryClient.getEntries as jest.Mock).mockImplementation(() => ({
items: [
{
fields: mockedEntryFields,
},
],
}));
const result = await getPageModule("mocked-id");
expect(result).toStrictEqual({
content: "test content",
data: null,
});
});
it("Returns null for no entries", async () => {
(contentfulDeliveryClient.getEntries as jest.Mock).mockImplementation(() => ({
items: [],
}));
const result = await getPageModule("mocked-id");
expect(result).toBe(null);
});