test: testing workflow triggers (#12823)
* add workflows to bookingScenario * activate sandbox mode for unit/integreation tests * add sendgrid specific code to SendgridProvider * Refactor WIP * remove duplicate sendgridProvider file * first implementation for testing workflows * revert unintended changes * comment out Workflow trigger tests * move sendgrid check after test mode * Update signup.tsx * fix esLint * test webhooks on all tests in fresh-booking.test.ts * fix subjectPattern as title can be different * add workflow tests to reschedule.test.ts * code clean up * code clean up * fix sendgrid credentials missing message * code clean up --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com>
This commit is contained in:
1 parent
a03a1ba34e
commit
076868d243
17 files changed
+453
-158
No files matched your search
@@ -16,6 +16,7 @@ import { weekdayToWeekIndex, type WeekDays } from "@calcom/lib/date-fns";
|
||||
import type { HttpError } from "@calcom/lib/http-error";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import type { WorkflowActions, WorkflowTemplates, WorkflowTriggerEvents } from "@calcom/prisma/client";
|
||||
import type { SchedulingType } from "@calcom/prisma/enums";
|
||||
import type { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { AppMeta } from "@calcom/types/App";
|
||||
@@ -36,6 +37,16 @@ type InputWebhook = {
|
||||
eventTriggers: WebhookTriggerEvents[];
|
||||
subscriberUrl: string;
|
||||
};
|
||||
|
||||
type InputWorkflow = {
|
||||
userId?: number | null;
|
||||
teamId?: number | null;
|
||||
name?: string;
|
||||
activeEventTypeId?: number;
|
||||
trigger: WorkflowTriggerEvents;
|
||||
action: WorkflowActions;
|
||||
template: WorkflowTemplates;
|
||||
};
|
||||
/**
|
||||
* Data to be mocked
|
||||
*/
|
||||
@@ -55,6 +66,7 @@ export type ScenarioData = {
|
||||
apps?: Partial<AppMeta>[];
|
||||
bookings?: InputBooking[];
|
||||
webhooks?: InputWebhook[];
|
||||
workflows?: InputWorkflow[];
|
||||
};
|
||||
|
||||
type InputCredential = typeof TestData.credentials.google & {
|
||||
@@ -371,6 +383,43 @@ async function addWebhooks(webhooks: InputWebhook[]) {
|
||||
await addWebhooksToDb(webhooks);
|
||||
}
|
||||
|
||||
async function addWorkflowsToDb(workflows: InputWorkflow[]) {
|
||||
await prismock.$transaction(
|
||||
workflows.map((workflow) => {
|
||||
return prismock.workflow.create({
|
||||
data: {
|
||||
userId: workflow.userId,
|
||||
teamId: workflow.teamId,
|
||||
trigger: workflow.trigger,
|
||||
name: workflow.name ? workflow.name : "Test Workflow",
|
||||
steps: {
|
||||
create: {
|
||||
stepNumber: 1,
|
||||
action: workflow.action,
|
||||
template: workflow.template,
|
||||
numberVerificationPending: false,
|
||||
includeCalendarEvent: false,
|
||||
},
|
||||
},
|
||||
activeOn: {
|
||||
create: workflow.activeEventTypeId ? { eventTypeId: workflow.activeEventTypeId } : undefined,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
activeOn: true,
|
||||
steps: true,
|
||||
},
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
async function addWorkflows(workflows: InputWorkflow[]) {
|
||||
log.silly("TestData: Creating Workflows", safeStringify(workflows));
|
||||
|
||||
await addWorkflowsToDb(workflows);
|
||||
}
|
||||
|
||||
async function addUsersToDb(users: (Prisma.UserCreateInput & { schedules: Prisma.ScheduleCreateInput[] })[]) {
|
||||
log.silly("TestData: Creating Users", JSON.stringify(users));
|
||||
await prismock.user.createMany({
|
||||
@@ -510,6 +559,8 @@ export async function createBookingScenario(data: ScenarioData) {
|
||||
// mockBusyCalendarTimes([]);
|
||||
await addWebhooks(data.webhooks || []);
|
||||
// addPaymentMock();
|
||||
await addWorkflows(data.workflows || []);
|
||||
|
||||
return {
|
||||
eventTypes,
|
||||
};
|
||||
@@ -872,6 +923,7 @@ export function getScenarioData(
|
||||
usersApartFromOrganizer = [],
|
||||
apps = [],
|
||||
webhooks,
|
||||
workflows,
|
||||
bookings,
|
||||
}: // hosts = [],
|
||||
{
|
||||
@@ -880,6 +932,7 @@ export function getScenarioData(
|
||||
apps?: ScenarioData["apps"];
|
||||
usersApartFromOrganizer?: ScenarioData["users"];
|
||||
webhooks?: ScenarioData["webhooks"];
|
||||
workflows?: ScenarioData["workflows"];
|
||||
bookings?: ScenarioData["bookings"];
|
||||
// hosts?: ScenarioData["hosts"];
|
||||
},
|
||||
@@ -928,6 +981,7 @@ export function getScenarioData(
|
||||
apps: [...apps],
|
||||
webhooks,
|
||||
bookings: bookings || [],
|
||||
workflows,
|
||||
} satisfies ScenarioData;
|
||||
}
|
||||
|
||||
|
||||
@@ -304,8 +304,41 @@ export function expectWebhookToHaveBeenCalledWith(
|
||||
}
|
||||
}
|
||||
|
||||
export function expectWorkflowToBeTriggered() {
|
||||
// TODO: Implement this.
|
||||
export function expectWorkflowToBeTriggered({
|
||||
emails,
|
||||
organizer,
|
||||
}: {
|
||||
emails: Fixtures["emails"];
|
||||
organizer: { email: string; name: string; timeZone: string };
|
||||
}) {
|
||||
const subjectPattern = /^Reminder: /i;
|
||||
expect(emails.get()).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
subject: expect.stringMatching(subjectPattern),
|
||||
to: organizer.email,
|
||||
}),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
export function expectWorkflowToBeNotTriggered({
|
||||
emails,
|
||||
organizer,
|
||||
}: {
|
||||
emails: Fixtures["emails"];
|
||||
organizer: { email: string; name: string; timeZone: string };
|
||||
}) {
|
||||
const subjectPattern = /^Reminder: /i;
|
||||
|
||||
expect(emails.get()).not.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
subject: expect.stringMatching(subjectPattern),
|
||||
to: organizer.email,
|
||||
}),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
export async function expectBookingToBeInDatabase(
|
||||
|
||||
Reference in new issue
Block a user