Files
calendar/packages/features/ee/workflows/lib/test/compareReminderBodyToTemplate.test.ts
T
98b6d63164 refactor: apply biome formatting to packages/features (#27844)
* refactor: apply biome formatting to packages/features (batch 1 - small subdirs)

Format small subdirectories in packages/features: di, flags, holidays, oauth,
settings, users, assignment-reason, selectedCalendar, hashedLink, host, form,
form-builder, availability, data-table, pbac, schedules, troubleshooter,
eventtypes, calendar-subscription, and root-level files.

Also includes straggler apps/web BookEventForm.tsx.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 2 - medium subdirs)

Format medium subdirectories in packages/features: auth, credentials,
calendars, routing-forms, routing-trace, attributes, watchlist, calAIPhone,
tasker, and webhooks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 3 - bookings + insights)

Format bookings and insights subdirectories in packages/features.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 4 - ee)

Format packages/features/ee subdirectory covering billing, workflows,
organizations, teams, managed-event-types, round-robin, dsync,
integration-attribute-sync, and payments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 5 - booking-audit part 1)

Format booking-audit di, actions, common, dto, repository, and types
subdirectories in packages/features/booking-audit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 6 - booking-audit part 2)

Format booking-audit service subdirectory in packages/features/booking-audit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 15:47:14 +01:00

168 lines
5.8 KiB
TypeScript

import { vi, expect, test, describe } from "vitest";
import { getTranslation } from "@calcom/lib/server/i18n";
import { TimeFormat } from "@calcom/lib/timeFormat";
import { WorkflowActions, WorkflowTemplates } from "@calcom/prisma/enums";
import { getTemplateBodyForAction } from "../actionHelperFunctions";
import compareReminderBodyToTemplate from "../compareReminderBodyToTemplate";
import plainTextReminderTemplates from "../reminders/templates/plainTextTemplates";
const tMock = (key: string) => {
const mocks: Record<string, string> = {
hi: "Hi",
reminder: "Reminder",
email_reminder_upcoming_event_notice: "This is a reminder about your upcoming event.",
event_upper_case: "Event",
date_and_time: "Date & Time",
attendees: "Attendees",
you_and_conjunction: "You &",
location: "Location",
scheduling_by: "Scheduling by",
experience_review_prompt: "How was your experience with",
improve_customer_experience_message: "We're always looking to improve our customer's experience.",
meeting_satisfaction_question: "How satisfied were you with your recent meeting?",
meeting_not_joined_question: "didn't join the meeting?",
reschedule_cta_short: "Reschedule here.",
};
return mocks[key] || key;
};
vi.mock("@calcom/lib/server/i18n", () => {
return {
getTranslation: async (locale: string, namespace: string) => {
const t = tMock as any;
t.locale = locale;
t.namespace = namespace;
return t;
},
};
});
const translation = async () => tMock as any;
describe("compareReminderBodyToTemplate", () => {
test("should return true if reminderBody and template are the same", () => {
const reminderBody = "<p>Test</p>";
const template = "<p>Test</p>";
expect(compareReminderBodyToTemplate({ reminderBody, template })).toBe(true);
});
test("should return false if reminderBody and template are different", () => {
const reminderBody = "<p>Test</p>";
const template = "<p>Test2</p>";
expect(compareReminderBodyToTemplate({ reminderBody, template })).toBe(false);
});
describe("email templates", () => {
test("reminder", async () => {
const template = getTemplateBodyForAction({
action: WorkflowActions.EMAIL_HOST,
template: WorkflowTemplates.REMINDER,
timeFormat: TimeFormat.TWELVE_HOUR,
locale: "en",
t: await translation(),
});
if (!template) throw new Error("template not found");
const reminderBody = plainTextReminderTemplates.email.reminder;
expect(compareReminderBodyToTemplate({ reminderBody, template })).toBe(true);
});
test("rating", async () => {
const template = getTemplateBodyForAction({
action: WorkflowActions.EMAIL_HOST,
template: WorkflowTemplates.RATING,
timeFormat: TimeFormat.TWELVE_HOUR,
locale: "en",
t: await translation(),
});
if (!template) throw new Error("template not found");
const reminderBody = plainTextReminderTemplates.email?.rating ?? "";
expect(compareReminderBodyToTemplate({ reminderBody, template })).toBe(true);
});
});
describe("sms templates", () => {
test("reminder", async () => {
const template = getTemplateBodyForAction({
action: WorkflowActions.SMS_ATTENDEE,
template: WorkflowTemplates.REMINDER,
timeFormat: TimeFormat.TWELVE_HOUR,
locale: "en",
t: await getTranslation("en", "common"),
});
if (!template) throw new Error("template not found");
const reminderBody = plainTextReminderTemplates.sms.reminder;
expect(compareReminderBodyToTemplate({ reminderBody, template })).toBe(true);
});
});
describe("whatsapp templates", () => {
test("reminder", async () => {
const template = getTemplateBodyForAction({
action: WorkflowActions.WHATSAPP_ATTENDEE,
template: WorkflowTemplates.REMINDER,
timeFormat: TimeFormat.TWELVE_HOUR,
locale: "en",
t: await getTranslation("en", "common"),
});
if (!template) throw new Error("template not found");
const reminderBody = plainTextReminderTemplates.whatsapp.reminder;
expect(compareReminderBodyToTemplate({ reminderBody, template })).toBe(true);
});
test("rescheduled", async () => {
const template = getTemplateBodyForAction({
action: WorkflowActions.WHATSAPP_ATTENDEE,
template: WorkflowTemplates.RESCHEDULED,
timeFormat: TimeFormat.TWELVE_HOUR,
locale: "en",
t: await getTranslation("en", "common"),
});
if (!template) throw new Error("template not found");
const reminderBody = plainTextReminderTemplates.whatsapp.rescheduled;
expect(compareReminderBodyToTemplate({ reminderBody, template })).toBe(true);
});
test("completed", async () => {
const template = getTemplateBodyForAction({
action: WorkflowActions.WHATSAPP_ATTENDEE,
template: WorkflowTemplates.COMPLETED,
timeFormat: TimeFormat.TWELVE_HOUR,
locale: "en",
t: await getTranslation("en", "common"),
});
if (!template) throw new Error("template not found");
const reminderBody = plainTextReminderTemplates.whatsapp.completed;
expect(compareReminderBodyToTemplate({ reminderBody, template })).toBe(true);
});
test("canceled", async () => {
const template = getTemplateBodyForAction({
action: WorkflowActions.WHATSAPP_ATTENDEE,
template: WorkflowTemplates.CANCELLED,
timeFormat: TimeFormat.TWELVE_HOUR,
locale: "en",
t: await getTranslation("en", "common"),
});
if (!template) throw new Error("template not found");
const reminderBody = plainTextReminderTemplates.whatsapp?.canceled ?? "";
expect(compareReminderBodyToTemplate({ reminderBody, template })).toBe(true);
});
});
});