-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnotifySupportAboutFormSubmissionProblem.test.ts
More file actions
79 lines (71 loc) · 2.63 KB
/
Copy pathnotifySupportAboutFormSubmissionProblem.test.ts
File metadata and controls
79 lines (71 loc) · 2.63 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { EnvironmentMode } from "@config";
import { createFreshdeskTicket } from "@lib/integration/freshdeskConnector.js";
import { logMessage } from "@lib/logging/logger.js";
import { notifySupportAboutFormSubmissionProblem } from "@lib/support/notifySupportAboutFormSubmissionProblem.js";
import { beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("@lib/integration/freshdeskConnector");
const createFreshdeskTicketMock = vi.mocked(createFreshdeskTicket);
describe("notifySupportAboutFormSubmissionProblem should", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("successfully notify support about a form submission problem if Freshdesk create ticket operation did not throw any error", async () => {
createFreshdeskTicketMock.mockResolvedValueOnce();
await expect(
notifySupportAboutFormSubmissionProblem(
"clzamy5qv0000115huc4bh90m",
"01-08-a571",
"test@test.com",
"Here is my problem",
"en",
EnvironmentMode.production,
),
).resolves.not.toThrow();
expect(createFreshdeskTicketMock).toHaveBeenCalledWith({
description: `
User (test@test.com) reported problems with some of the submissions for form \`clzamy5qv0000115huc4bh90m\`.<br/>
<br/>
Submission names:<br/>
01-08-a571
<br/>
Description:<br/>
Here is my problem<br/>
****<br/>
L'utilisateur (test@test.com) a signalé avoir rencontré des problèmes avec certaines des soumissions du formulaire \`clzamy5qv0000115huc4bh90m\`.<br/>
<br/>
Nom des soumissions:<br/>
01-08-a571
<br/>
Description:<br/>
Here is my problem<br/>
`,
email: "test@test.com",
name: "test@test.com",
preferredLanguage: "en",
subject: "Problem with GC Forms / Problème avec Formulaires GC",
tags: ["Forms_Production", "Forms_API_Submission"],
type: "Problem",
});
});
it("throw an error if the createTicket function has an internal failure", async () => {
const customError = new Error("custom error");
createFreshdeskTicketMock.mockRejectedValueOnce(customError);
const logMessageSpy = vi.spyOn(logMessage, "info");
await expect(() =>
notifySupportAboutFormSubmissionProblem(
"clzamy5qv0000115huc4bh90m",
"01-08-a571",
"test@test.com",
"Here is my problem",
"en",
EnvironmentMode.production,
),
).rejects.toThrow(customError);
expect(logMessageSpy).toHaveBeenCalledWith(
customError,
expect.stringContaining(
"[support] Failed to notify support about form submission problem. FormId: clzamy5qv0000115huc4bh90m / SubmissionName: 01-08-a571 / Contact email: test@test.com",
),
);
});
});