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:
10 files changed
+674
-46
No files matched your search
Vendored
+11
@@ -2,15 +2,20 @@
|
||||
import { test as base } from "vitest";
|
||||
|
||||
import { getTestEmails } from "@calcom/lib/testEmails";
|
||||
import { getTestSMS } from "@calcom/lib/testSMS";
|
||||
|
||||
export interface Fixtures {
|
||||
emails: ReturnType<typeof getEmailsFixture>;
|
||||
sms: ReturnType<typeof getSMSFixture>;
|
||||
}
|
||||
|
||||
export const test = base.extend<Fixtures>({
|
||||
emails: async ({}, use) => {
|
||||
await use(getEmailsFixture());
|
||||
},
|
||||
sms: async ({}, use) => {
|
||||
await use(getSMSFixture());
|
||||
},
|
||||
});
|
||||
|
||||
function getEmailsFixture() {
|
||||
@@ -18,3 +23,9 @@ function getEmailsFixture() {
|
||||
get: getTestEmails,
|
||||
};
|
||||
}
|
||||
|
||||
function getSMSFixture() {
|
||||
return {
|
||||
get: getTestSMS,
|
||||
};
|
||||
}
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
};
|
||||
}) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user