test: add unit tests for sms sending (#14737)

* add tests for workflow sms

* fix type error

* improvements

* add tests for team workflow

* rename test

* add emailsToReceive everywhere

* fix type errors

* code clean up

* fix fresh-booking.test.ts

* add destination email to emailsToReceive

* remove unused webhooks

---------

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Hariom <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-05-02 10:42:38 -04:00
1 parent c18407d75a
commit 0391bfe887
10 files changed
+674 -46

No files matched your search

@@ -19,7 +19,7 @@ import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
import { ProfileRepository } from "@calcom/lib/server/repository/profile";
import type { WorkflowActions, WorkflowTemplates, WorkflowTriggerEvents } from "@calcom/prisma/client";
import type { SchedulingType } from "@calcom/prisma/enums";
import type { SchedulingType, SMSLockState } from "@calcom/prisma/enums";
import type { BookingStatus } from "@calcom/prisma/enums";
import type { teamMetadataSchema } from "@calcom/prisma/zod-utils";
import type { userMetadataType } from "@calcom/prisma/zod-utils";
@@ -952,6 +952,7 @@ export function getOrganizer({
teams,
organizationId,
metadata,
smsLockState,
}: {
name: string;
email: string;
@@ -965,6 +966,7 @@ export function getOrganizer({
weekStart?: WeekDays;
teams?: InputUser["teams"];
metadata?: userMetadataType;
smsLockState?: SMSLockState;
}) {
return {
...TestData.users.example,
@@ -981,6 +983,7 @@ export function getOrganizer({
organizationId,
profiles: [],
metadata,
smsLockState,
};
}
+51 -17
View File
@@ -307,38 +307,72 @@ export function expectWebhookToHaveBeenCalledWith(
export function expectWorkflowToBeTriggered({
emails,
organizer,
destinationEmail,
emailsToReceive,
}: {
emails: Fixtures["emails"];
organizer: { email: string; name: string; timeZone: string };
destinationEmail?: string;
emailsToReceive: string[];
}) {
const subjectPattern = /^Reminder: /i;
expect(emails.get()).toEqual(
emailsToReceive.forEach((email) => {
expect(emails.get()).toEqual(
expect.arrayContaining([
expect.objectContaining({
subject: expect.stringMatching(subjectPattern),
to: email,
}),
])
);
});
}
export function expectWorkflowToBeNotTriggered({
emails,
emailsToReceive,
}: {
emails: Fixtures["emails"];
emailsToReceive: string[];
}) {
const subjectPattern = /^Reminder: /i;
emailsToReceive.forEach((email) => {
expect(emails.get()).not.toEqual(
expect.arrayContaining([
expect.objectContaining({
subject: expect.stringMatching(subjectPattern),
to: email,
}),
])
);
});
}
export function expectSMSWorkflowToBeTriggered({
sms,
toNumber,
}: {
sms: Fixtures["sms"];
toNumber: string;
}) {
expect(sms.get()).toEqual(
expect.arrayContaining([
expect.objectContaining({
subject: expect.stringMatching(subjectPattern),
to: destinationEmail ?? organizer.email,
to: toNumber,
}),
])
);
}
export function expectWorkflowToBeNotTriggered({
emails,
organizer,
export function expectSMSWorkflowToBeNotTriggered({
sms,
toNumber,
}: {
emails: Fixtures["emails"];
organizer: { email: string; name: string; timeZone: string };
sms: Fixtures["sms"];
toNumber: string;
}) {
const subjectPattern = /^Reminder: /i;
expect(emails.get()).not.toEqual(
expect(sms.get()).not.toEqual(
expect.arrayContaining([
expect.objectContaining({
subject: expect.stringMatching(subjectPattern),
to: organizer.email,
to: toNumber,
}),
])
);
@@ -30,6 +30,7 @@ export function getMockRequestDataForBooking({
email: string;
name: string;
location: { optionValue: ""; value: string };
smsReminderNumber?: string;
};
};
}) {
+4 -2
View File
@@ -15,7 +15,7 @@ const _testWithAndWithoutOrg = (
const t = mode === "only" ? test.only : mode === "skip" ? test.skip : test;
t(
`${description} - With org`,
async ({ emails, meta, task, onTestFailed, expect, skip }) => {
async ({ emails, sms, meta, task, onTestFailed, expect, skip }) => {
const org = await createOrganization({
name: "Test Org",
slug: "testorg",
@@ -27,6 +27,7 @@ const _testWithAndWithoutOrg = (
onTestFailed,
expect,
emails,
sms,
skip,
org: {
organization: org,
@@ -39,9 +40,10 @@ const _testWithAndWithoutOrg = (
t(
`${description}`,
async ({ emails, meta, task, onTestFailed, expect, skip }) => {
async ({ emails, sms, meta, task, onTestFailed, expect, skip }) => {
await fn({
emails,
sms,
meta,
task,
onTestFailed,