Files
calendar/packages/features/ee/workflows/lib/service/WorkflowService.test.ts
T
Joe Au-YeungGitHubcal.comMorganhbjORbjDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>Alex van Andel
f33edb2b99 feat: Generate email workflow payload at time of sending (#25446)
* wip

* wip

* feature: Booking Tasker without DI yet

* feature: Booking Tasker with DI

* fix type check 1

* fix type check 2

* fix

* comment booking tasker for now

* fix: DI regularBookingService api v2

* fix: convert trigger.dev SDK imports to dynamic imports to fix unit tests

The unit tests were failing because BookingEmailAndSmsTriggerTasker.ts had static imports of trigger files that depend on @trigger.dev/sdk. This caused Vitest to try to resolve the SDK at module load time, even though it should be optional.

Changed all imports in BookingEmailAndSmsTriggerTasker.ts from static to dynamic (using await import()) so the trigger files are only loaded when the tasker methods are actually called, not at module load time during tests.

This fixes the 'Failed to load url @trigger.dev/sdk' errors that were causing 28+ test failures.

Co-Authored-By: morgan@cal.com <morgan@cal.com>

* fix unit tests

* keep inline smsAndEmailHandler.send calls

* chore: add team feature flag

* add satisfies ModuleLoader

* fix type check app flags

* move trigger in feature

* fix: add trigger.dev prisma  generator

* fix: email app statuses

* fix: CalEvtBuilder unit test

* chore: improvements, schema, config, retry

* fixup! chore: improvements, schema, config, retry

* chore: cleanup code

* chore: cleanup code

* chore: clean code and give full payload

* remove log

* add booking notifications queue

* add attendee phone number for sms

* bump trigger to 4.1.0

* add missing booking seat data in attendee

* update config

* fix logger regular booking service

* fix: prisma as external deps of trigger

* fix yarn.lock

* revert change to example app booking page

* fix: resolve circular dependencies and improve cold start performance in trigger tasks

- Convert BookingRepository import to type-only in CalendarEventBuilder.ts to eliminate circular dependency risk
- Convert EventNameObjectType, CalendarEvent, and JsonObject imports to type-only in BookingEmailAndSmsTaskService.ts
- Use dynamic imports in all trigger notification tasks (confirm, request, reschedule, rr-reschedule) to reduce cold start time
- Move heavy imports (BookingEmailSmsHandler, BookingRepository, prisma, TriggerDevLogger, BookingEmailAndSmsTaskService) inside run functions
- Eliminates module-level prisma import which violates repo guidelines and adds cold start overhead
- Reduces initial module dependency graph by deferring heavy imports (email templates, workflows, large repositories) until task execution

Co-Authored-By: morgan@cal.com <morgan@cal.com>

* fix: improve cold start performance in reminderScheduler with dynamic imports

- Remove module-level prisma import (violates 'No prisma outside repositories' guideline)
- Use dynamic imports for UserRepository (1,168 lines) - only loaded when needed in EMAIL_ATTENDEE action
- Use dynamic imports for twilio provider (386 lines) - only loaded in cancelScheduledMessagesAndScheduleEmails
- Use dynamic imports for all manager functions by action type:
  - scheduleSMSReminder (387 lines) - loaded only for SMS actions
  - scheduleEmailReminder (459 lines) - loaded only for Email actions
  - scheduleWhatsappReminder (266 lines) - loaded only for WhatsApp actions
  - scheduleAIPhoneCall (478 lines) - loaded only for AI phone call actions
- Use dynamic imports for sendOrScheduleWorkflowEmails in cancelScheduledMessagesAndScheduleEmails
- Significantly reduces cold start time by deferring heavy module loading until execution paths need them
- Eliminates module-level prisma import that violated repository pattern guidelines

Co-Authored-By: morgan@cal.com <morgan@cal.com>

* fix: improve cold start performance in BookingEmailSmsHandler with dynamic imports

- Remove module-level imports of all email-manager functions (653 LOC + 30+ email templates)
- Add dynamic imports in each method (_handleRescheduled, _handleRoundRobinRescheduled, _handleConfirmed, _handleRequested, handleAddGuests)
- Defer heavy email-manager loading until method execution
- Verified no circular dependencies between email-manager and bookings
- Significantly reduces cold start time for RegularBookingService and BookingEmailAndSmsTaskService

Co-Authored-By: morgan@cal.com <morgan@cal.com>

* fix: use dynamic imports

* update yarn lock

* code review

* trigger config project ref in env

* update yarn lock

* add .env.example trigger variables

* add .env.example trigger variables

* fix: cleanup error handling and loggin

* fix: trigger config from env

* fix: small typo fix

* fix: ai review comments

* fix: ai review comments

* ai review

* Add `create` on `WorkflowReminderRepository`

* `sendWorkflowEmails` tasker to accept lazy payload

* Add `scheduleLazyEmailWorkflow` to `WorkflowService

* Process scheduled date in `scheduleLazyEmailWorkflow`

* Type fixes

* Use `WorkflowService` to schedule

* Refactor `scheduleEmailReminderForEvt` to use
`WorkflowService.processWorkflowScheduledDate`

* Pass seat reference to lazy scheduled workflow reminder

* Refactor `WorkflowReminderRepository` to accept prisma as constructor

* Abstract `FormSubmissionData` type

* Abstract select statement and add get by uid to `BookingRepository`

* Add `FormSubmissionData` type

* Add `findByIdIncludeStepAndWorkflow` to `WorkflowReminderRepository`

* Tasker payload to accept `workflowReminderId`

* Create `BookingSeatRepository`

* Write `workflowReminderId` to tasker payload

* Add `generateCommonScheduleFunctionParams` to `WorkflowService`

* Init

* Use services in tasker

* Abstract types

* In reminderScheduler use workflowService to generate common params

* Type fix

* Return params from emailWorkflowService.generateParametersToBuildEmailWorkflowContent

* Use emailWorkflowService to generate params

* Abstract types

* Generate email content and send in EmailWorkflowService

* Move check to caller

* Use EmailWorkflowService to generate email payload in
emailReminderManager

* Fix initalizing repository

* Use evt.videoCallData first before the booking metadata

* Only get non-deleted references to build calendar event

* Remove check for videoCallData.id

* Dynamic import credit service

* BookingRepository.getByUid to only return what we need from attendee

* Type fixes

* test: Add comprehensive tests for lazy email workflow generation and fix broken tests

- Fix prisma mocks in sms-manager.test.ts and outOfOfficeCreateOrUpdate.handler.test.ts
  to export both 'default' and named 'prisma' exports
- Add EmailWorkflowService.test.ts with 4 tests for error handling paths
- Add sendWorkflowEmails.test.ts with 7 tests for schema validation and email sending
- Add tests to WorkflowService.test.ts for scheduleLazyEmailWorkflow,
  processWorkflowScheduledDate, and generateCommonScheduleFunctionParams methods

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>

* Write `seatReferenceUid`

* Return promise

* Fix log

* Change to `Promise.allSettled`

* Type fix

* Fix failing test

* fix: reorder workflow step checks to fix test failure

The test 'should throw error if workflow step not found on reminder' was failing because the code checked workflowStep.verifiedAt before checking if workflowStep exists. When workflowStep is null, this caused the error message to include 'undefined' instead of the expected workflow step id.

Fixed by reordering the checks:
1. First check if workflowStep exists
2. Then check if workflowStep.verifiedAt exists

Also updated the test expectation to match the correct error message.

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>

---------

Co-authored-by: cal.com <morgan@cal.com>
Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
Co-authored-by: hbjORbj <sldisek783@gmail.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
2025-12-02 02:25:07 +00:00

675 lines
18 KiB
TypeScript

import { describe, expect, vi, beforeEach } from "vitest";
import { scheduleWorkflowReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";
import { tasker } from "@calcom/features/tasker";
import { WorkflowTriggerEvents, WorkflowActions, WorkflowTemplates, TimeUnit } from "@calcom/prisma/enums";
import { test } from "@calcom/web/test/fixtures/fixtures";
import { WorkflowService } from "./WorkflowService";
vi.mock("@calcom/features/ee/workflows/lib/reminders/reminderScheduler");
vi.mock("@calcom/features/tasker");
const mockScheduleWorkflowReminders = vi.mocked(scheduleWorkflowReminders);
const mockTasker = vi.mocked(tasker);
vi.mock("@calcom/features/profile/lib/hideBranding", () => ({
getHideBranding: vi.fn().mockResolvedValue(false),
}));
const mockWorkflowReminderCreate = vi.fn();
vi.mock("@calcom/features/ee/workflows/repositories/WorkflowReminderRepository", () => ({
WorkflowReminderRepository: vi.fn().mockImplementation(() => ({
create: mockWorkflowReminderCreate,
})),
}));
vi.mock("@calcom/prisma", () => ({
prisma: {},
default: {},
}));
describe("WorkflowService.scheduleFormWorkflows", () => {
beforeEach(() => {
vi.clearAllMocks();
});
const mockForm = {
id: "form-123",
userId: 101,
teamId: null,
fields: [
{ type: "email", identifier: "email" },
{ type: "phone", identifier: "phone" },
],
user: {
email: "formowner@example.com",
timeFormat: 12,
locale: "en",
},
};
const mockResponses = {
email: {
value: "submitter@example.com",
response: "submitter@example.com",
},
phone: {
value: "+1234567890",
response: "+1234567890",
},
};
test("should call scheduleWorkflowReminders for FORM_SUBMITTED triggers with correct phone number", async () => {
const workflows = [
{
id: 1,
name: "Form Submitted",
userId: 101,
teamId: null,
trigger: WorkflowTriggerEvents.FORM_SUBMITTED,
time: null,
timeUnit: null,
steps: [
{
id: 1,
action: WorkflowActions.SMS_ATTENDEE,
sendTo: null,
reminderBody: "Thank you!",
emailSubject: "Form Received",
template: WorkflowTemplates.CUSTOM,
verifiedAt: new Date(),
includeCalendarEvent: false,
numberVerificationPending: false,
numberRequired: false,
},
],
},
];
const mockCreditCheckFn = vi.fn().mockResolvedValue(true);
await WorkflowService.scheduleFormWorkflows({
workflows,
responses: mockResponses,
form: mockForm,
responseId: 123,
routedEventTypeId: null,
creditCheckFn: mockCreditCheckFn,
});
expect(mockScheduleWorkflowReminders).toHaveBeenCalledWith({
smsReminderNumber: "+1234567890",
formData: {
responses: mockResponses,
user: { email: "formowner@example.com", timeFormat: 12, locale: "en" },
routedEventTypeId: null,
},
hideBranding: false,
workflows: [workflows[0]],
creditCheckFn: mockCreditCheckFn,
});
});
test("should create task for FORM_SUBMITTED_NO_EVENT triggers", async () => {
const workflows = [
{
id: 2,
name: "Form Follow-up",
userId: 101,
teamId: null,
trigger: WorkflowTriggerEvents.FORM_SUBMITTED_NO_EVENT,
time: 30,
timeUnit: TimeUnit.MINUTE,
steps: [
{
id: 2,
action: WorkflowActions.EMAIL_ATTENDEE,
sendTo: null,
reminderBody: "Follow up message",
emailSubject: "Follow Up",
template: WorkflowTemplates.CUSTOM,
verifiedAt: new Date(),
includeCalendarEvent: false,
numberVerificationPending: false,
numberRequired: false,
sender: null,
},
],
},
];
mockTasker.create.mockResolvedValue({ id: "task-123" });
const mockCreditCheckFn = vi.fn().mockResolvedValue(true);
await WorkflowService.scheduleFormWorkflows({
workflows,
responses: mockResponses,
responseId: 123,
form: mockForm,
routedEventTypeId: null,
creditCheckFn: mockCreditCheckFn,
});
expect(mockTasker.create).toHaveBeenCalledWith(
"triggerFormSubmittedNoEventWorkflow",
{
responseId: 123,
responses: mockResponses,
smsReminderNumber: "+1234567890",
hideBranding: false,
routedEventTypeId: null,
submittedAt: expect.any(Date),
form: {
id: "form-123",
userId: 101,
teamId: undefined,
user: {
email: "formowner@example.com",
timeFormat: 12,
locale: "en",
},
},
workflow: workflows[0],
},
{ scheduledAt: expect.any(Date) }
);
});
test("should handle forms without phone fields by passing null smsReminderNumber", async () => {
const formWithoutPhone = {
...mockForm,
fields: [
{ type: "email", identifier: "email" },
{ type: "text", identifier: "name" },
],
};
const workflows = [
{
id: 1,
name: "Form Submitted",
userId: 101,
teamId: null,
trigger: WorkflowTriggerEvents.FORM_SUBMITTED,
time: null,
timeUnit: null,
steps: [
{
id: 1,
action: WorkflowActions.EMAIL_ATTENDEE,
sendTo: null,
reminderBody: "Thank you!",
emailSubject: "Form Received",
template: WorkflowTemplates.CUSTOM,
verifiedAt: new Date(),
includeCalendarEvent: false,
numberVerificationPending: false,
numberRequired: false,
sender: null,
},
],
},
];
const mockCreditCheckFn = vi.fn().mockResolvedValue(true);
await WorkflowService.scheduleFormWorkflows({
workflows,
responses: mockResponses,
form: formWithoutPhone,
responseId: 123,
routedEventTypeId: null,
creditCheckFn: mockCreditCheckFn,
});
expect(mockScheduleWorkflowReminders).toHaveBeenCalledWith({
smsReminderNumber: null,
formData: {
responses: mockResponses,
user: { email: "formowner@example.com", timeFormat: 12, locale: "en" },
routedEventTypeId: null,
},
hideBranding: false,
workflows: [workflows[0]],
creditCheckFn: mockCreditCheckFn,
});
});
});
describe("WorkflowService.scheduleLazyEmailWorkflow", () => {
beforeEach(() => {
vi.clearAllMocks();
});
test("should schedule lazy email workflow for BEFORE_EVENT trigger", async () => {
const mockWorkflow = {
time: 24,
timeUnit: TimeUnit.HOUR,
};
const mockEvt = {
uid: "booking-123",
startTime: "2024-12-01T10:00:00Z",
endTime: "2024-12-01T11:00:00Z",
};
const mockWorkflowReminder = {
id: 1,
uuid: "reminder-uuid-123",
};
mockWorkflowReminderCreate.mockResolvedValue(mockWorkflowReminder);
mockTasker.create.mockResolvedValue({ id: "task-123" });
await WorkflowService.scheduleLazyEmailWorkflow({
workflowTriggerEvent: "BEFORE_EVENT",
workflowStepId: 1,
workflow: mockWorkflow,
evt: mockEvt,
});
expect(mockWorkflowReminderCreate).toHaveBeenCalledWith({
bookingUid: "booking-123",
workflowStepId: 1,
method: "EMAIL",
scheduledDate: expect.any(Date),
scheduled: true,
});
expect(mockTasker.create).toHaveBeenCalledWith(
"sendWorkflowEmails",
{
bookingUid: "booking-123",
workflowReminderId: 1,
},
{
scheduledAt: expect.any(Date),
referenceUid: "reminder-uuid-123",
}
);
});
test("should schedule lazy email workflow for AFTER_EVENT trigger", async () => {
const mockWorkflow = {
time: 1,
timeUnit: TimeUnit.HOUR,
};
const mockEvt = {
uid: "booking-456",
startTime: "2024-12-01T10:00:00Z",
endTime: "2024-12-01T11:00:00Z",
};
const mockWorkflowReminder = {
id: 2,
uuid: "reminder-uuid-456",
};
mockWorkflowReminderCreate.mockResolvedValue(mockWorkflowReminder);
mockTasker.create.mockResolvedValue({ id: "task-456" });
await WorkflowService.scheduleLazyEmailWorkflow({
workflowTriggerEvent: "AFTER_EVENT",
workflowStepId: 2,
workflow: mockWorkflow,
evt: mockEvt,
});
expect(mockTasker.create).toHaveBeenCalledWith(
"sendWorkflowEmails",
{
bookingUid: "booking-456",
workflowReminderId: 2,
},
{
scheduledAt: expect.any(Date),
referenceUid: "reminder-uuid-456",
}
);
});
test("should handle seated events with seatReferenceId", async () => {
const mockWorkflow = {
time: 24,
timeUnit: TimeUnit.HOUR,
};
const mockEvt = {
uid: "booking-789",
startTime: "2024-12-01T10:00:00Z",
endTime: "2024-12-01T11:00:00Z",
};
const mockWorkflowReminder = {
id: 3,
uuid: "reminder-uuid-789",
};
mockWorkflowReminderCreate.mockResolvedValue(mockWorkflowReminder);
mockTasker.create.mockResolvedValue({ id: "task-789" });
await WorkflowService.scheduleLazyEmailWorkflow({
workflowTriggerEvent: "BEFORE_EVENT",
workflowStepId: 3,
workflow: mockWorkflow,
evt: mockEvt,
seatReferenceId: "seat-123",
});
expect(mockTasker.create).toHaveBeenCalled();
});
test("should not schedule if bookingUid is missing", async () => {
const mockWorkflow = {
time: 24,
timeUnit: TimeUnit.HOUR,
};
const mockEvt = {
uid: "",
startTime: "2024-12-01T10:00:00Z",
endTime: "2024-12-01T11:00:00Z",
};
await WorkflowService.scheduleLazyEmailWorkflow({
workflowTriggerEvent: "BEFORE_EVENT",
workflowStepId: 1,
workflow: mockWorkflow,
evt: mockEvt,
});
expect(mockWorkflowReminderCreate).not.toHaveBeenCalled();
expect(mockTasker.create).not.toHaveBeenCalled();
});
test("should not schedule if time is null", async () => {
const mockWorkflow = {
time: null,
timeUnit: TimeUnit.HOUR,
};
const mockEvt = {
uid: "booking-123",
startTime: "2024-12-01T10:00:00Z",
endTime: "2024-12-01T11:00:00Z",
};
await WorkflowService.scheduleLazyEmailWorkflow({
workflowTriggerEvent: "BEFORE_EVENT",
workflowStepId: 1,
workflow: mockWorkflow,
evt: mockEvt,
});
expect(mockWorkflowReminderCreate).not.toHaveBeenCalled();
expect(mockTasker.create).not.toHaveBeenCalled();
});
});
describe("WorkflowService.processWorkflowScheduledDate", () => {
test("should calculate scheduled date for BEFORE_EVENT trigger", () => {
const evt = {
startTime: "2024-12-01T10:00:00Z",
endTime: "2024-12-01T11:00:00Z",
};
const result = WorkflowService.processWorkflowScheduledDate({
workflowTriggerEvent: WorkflowTriggerEvents.BEFORE_EVENT,
time: 24,
timeUnit: TimeUnit.HOUR,
evt,
});
expect(result).toBeDefined();
expect(result?.toISOString()).toBe("2024-11-30T10:00:00.000Z");
});
test("should calculate scheduled date for AFTER_EVENT trigger", () => {
const evt = {
startTime: "2024-12-01T10:00:00Z",
endTime: "2024-12-01T11:00:00Z",
};
const result = WorkflowService.processWorkflowScheduledDate({
workflowTriggerEvent: WorkflowTriggerEvents.AFTER_EVENT,
time: 1,
timeUnit: TimeUnit.HOUR,
evt,
});
expect(result).toBeDefined();
expect(result?.toISOString()).toBe("2024-12-01T12:00:00.000Z");
});
test("should return null if time is null", () => {
const evt = {
startTime: "2024-12-01T10:00:00Z",
endTime: "2024-12-01T11:00:00Z",
};
const result = WorkflowService.processWorkflowScheduledDate({
workflowTriggerEvent: WorkflowTriggerEvents.BEFORE_EVENT,
time: null,
timeUnit: TimeUnit.HOUR,
evt,
});
expect(result).toBeNull();
});
test("should return null if timeUnit is null", () => {
const evt = {
startTime: "2024-12-01T10:00:00Z",
endTime: "2024-12-01T11:00:00Z",
};
const result = WorkflowService.processWorkflowScheduledDate({
workflowTriggerEvent: WorkflowTriggerEvents.BEFORE_EVENT,
time: 24,
timeUnit: null,
evt,
});
expect(result).toBeNull();
});
test("should calculate scheduled date with MINUTE time unit", () => {
const evt = {
startTime: "2024-12-01T10:00:00Z",
endTime: "2024-12-01T11:00:00Z",
};
const result = WorkflowService.processWorkflowScheduledDate({
workflowTriggerEvent: WorkflowTriggerEvents.BEFORE_EVENT,
time: 30,
timeUnit: TimeUnit.MINUTE,
evt,
});
expect(result).toBeDefined();
expect(result?.toISOString()).toBe("2024-12-01T09:30:00.000Z");
});
});
describe("WorkflowService.generateCommonScheduleFunctionParams", () => {
test("should generate common parameters correctly", () => {
const verifiedAt = new Date("2024-01-01T00:00:00Z");
const mockWorkflow = {
id: 1,
name: "Test Workflow",
trigger: WorkflowTriggerEvents.BEFORE_EVENT,
time: 24,
timeUnit: TimeUnit.HOUR,
userId: 1,
teamId: null,
};
const mockWorkflowStep = {
id: 1,
action: WorkflowActions.EMAIL_ATTENDEE,
sendTo: null,
template: WorkflowTemplates.REMINDER,
reminderBody: null,
emailSubject: null,
sender: null,
includeCalendarEvent: false,
verifiedAt,
numberVerificationPending: false,
numberRequired: false,
};
const mockCreditCheckFn = vi.fn();
const result = WorkflowService.generateCommonScheduleFunctionParams({
workflow: mockWorkflow,
workflowStep: mockWorkflowStep,
seatReferenceUid: undefined,
creditCheckFn: mockCreditCheckFn,
});
expect(result).toEqual({
triggerEvent: WorkflowTriggerEvents.BEFORE_EVENT,
timeSpan: {
time: 24,
timeUnit: TimeUnit.HOUR,
},
workflowStepId: 1,
template: WorkflowTemplates.REMINDER,
userId: 1,
teamId: null,
seatReferenceUid: undefined,
verifiedAt,
creditCheckFn: mockCreditCheckFn,
});
});
test("should handle seated events with seatReferenceUid", () => {
const verifiedAt = new Date("2024-01-01T00:00:00Z");
const mockWorkflow = {
id: 1,
name: "Test Workflow",
trigger: WorkflowTriggerEvents.BEFORE_EVENT,
time: 24,
timeUnit: TimeUnit.HOUR,
userId: 1,
teamId: null,
};
const mockWorkflowStep = {
id: 1,
action: WorkflowActions.EMAIL_ATTENDEE,
sendTo: null,
template: WorkflowTemplates.REMINDER,
reminderBody: null,
emailSubject: null,
sender: null,
includeCalendarEvent: false,
verifiedAt,
numberVerificationPending: false,
numberRequired: false,
};
const mockCreditCheckFn = vi.fn();
const result = WorkflowService.generateCommonScheduleFunctionParams({
workflow: mockWorkflow,
workflowStep: mockWorkflowStep,
seatReferenceUid: "seat-123",
creditCheckFn: mockCreditCheckFn,
});
expect(result.seatReferenceUid).toBe("seat-123");
});
test("should handle null verifiedAt", () => {
const mockWorkflow = {
id: 1,
name: "Test Workflow",
trigger: WorkflowTriggerEvents.BEFORE_EVENT,
time: 24,
timeUnit: TimeUnit.HOUR,
userId: 1,
teamId: null,
};
const mockWorkflowStep = {
id: 1,
action: WorkflowActions.EMAIL_ATTENDEE,
sendTo: null,
template: WorkflowTemplates.REMINDER,
reminderBody: null,
emailSubject: null,
sender: null,
includeCalendarEvent: false,
verifiedAt: null,
numberVerificationPending: false,
numberRequired: false,
};
const mockCreditCheckFn = vi.fn();
const result = WorkflowService.generateCommonScheduleFunctionParams({
workflow: mockWorkflow,
workflowStep: mockWorkflowStep,
seatReferenceUid: undefined,
creditCheckFn: mockCreditCheckFn,
});
expect(result.verifiedAt).toBeNull();
});
test("should handle team workflows", () => {
const verifiedAt = new Date("2024-01-01T00:00:00Z");
const mockWorkflow = {
id: 1,
name: "Team Workflow",
trigger: WorkflowTriggerEvents.AFTER_EVENT,
time: 1,
timeUnit: TimeUnit.HOUR,
userId: null,
teamId: 123,
};
const mockWorkflowStep = {
id: 2,
action: WorkflowActions.EMAIL_HOST,
sendTo: null,
template: WorkflowTemplates.CUSTOM,
reminderBody: "Custom body",
emailSubject: "Custom subject",
sender: "Team",
includeCalendarEvent: true,
verifiedAt,
numberVerificationPending: false,
numberRequired: false,
};
const mockCreditCheckFn = vi.fn();
const result = WorkflowService.generateCommonScheduleFunctionParams({
workflow: mockWorkflow,
workflowStep: mockWorkflowStep,
seatReferenceUid: undefined,
creditCheckFn: mockCreditCheckFn,
});
expect(result).toEqual({
triggerEvent: WorkflowTriggerEvents.AFTER_EVENT,
timeSpan: {
time: 1,
timeUnit: TimeUnit.HOUR,
},
workflowStepId: 2,
template: WorkflowTemplates.CUSTOM,
userId: null,
teamId: 123,
seatReferenceUid: undefined,
verifiedAt,
creditCheckFn: mockCreditCheckFn,
});
});
});