* Add akismet package to tasker * Create scanWorkflowBody task * Schedule workflow body scan * Add AKISMET_API_KEY .env * Auto lock user if spam is detected * Uncommit key * Add safe param to workflow step * Migration for safe field * Do not process workflow steps is `safe` is false * Update migration to set previous records to true * Address comments * Refactor `scheduleWorkflowNotifications` to accept an object * If new steps or editing old ones send to tasker * Call `scheduleWorkflowNotifications` in task * Fix `IS_SELF_HOSTED` * Remove unused function * Make `safe` optional in schema * Type fix * Revert "Make `safe` optional in schema" This reverts commit d0964702affa87c35562300301473d25635c565b. * Revert "Type fix" This reverts commit d9a031303269a2994ae46f576ab2a3d31e4d977b. * Type fixes * Type fixes * Address comments * Fix tests * Add tests * Update tests * Typo fix * Update `safe` to `verifiedAt` * feat: Compare workflow reminder bodies to default template (#19060) * Add `getTemplateForAction` function * Use `getTemplateForAction` when creating a new step * Use `getTemplateForAction` when action changes * Have `emailReminderTemplate` accept an object as a param * Rename `getTemplateForAction` to `getTemplateBodyForAction` * Simplify changing body when changing templates * Create `compareReminderBodyToTemplate` * In task, compare if reminderBody is a template * Linting * Add tests * refactor: `emailReminderTemplate` to accept object as param (#19288) * Add `getTemplateForAction` function * Use `getTemplateForAction` when creating a new step * Use `getTemplateForAction` when action changes * Have `emailReminderTemplate` accept an object as a param * Rename `getTemplateForAction` to `getTemplateBodyForAction` * Simplify changing body when changing templates * Create `compareReminderBodyToTemplate` * In task, compare if reminderBody is a template * Linting * Add tests * Refactor `scheduleEmailReminders` * Refactor `create.handler` for new workflows * Refactor `emailReminderManager` * Refactor `getEmailTemplateText` * Fix typo * Type fix - whatsapp plain text template imports * Type fix - no template found * Type fix - add `isBrandingDisabled` to `emailReminderTemplate` * Add workflow and user to prisma mock * Fix imports for akismet dependencies * Record user lock reason * Undo linting changes * Fix tests * New workflow, at verify created step * Handle if `SCANNING_WORKFLOW_STEPS` is toggled * Move `verifiedAt` checks to specific schedule functions - `scheduleWhatsappReminder` - `scheduleEmailReminder` - `scheduleSMSReminder` * Update logic * Do not fallback verifiedAt * Add comment to next.config.js
146 lines
4.5 KiB
TypeScript
146 lines
4.5 KiB
TypeScript
import type { Locator } from "@playwright/test";
|
|
import { expect, type Page } from "@playwright/test";
|
|
|
|
import prisma from "@calcom/prisma";
|
|
import { WorkflowTriggerEvents } from "@calcom/prisma/enums";
|
|
|
|
import { localize } from "../lib/localize";
|
|
|
|
type CreateWorkflowProps = {
|
|
name?: string;
|
|
isTeam?: true;
|
|
trigger?: WorkflowTriggerEvents;
|
|
};
|
|
|
|
export function createWorkflowPageFixture(page: Page) {
|
|
const createWorkflow = async (props: CreateWorkflowProps) => {
|
|
const { name, isTeam, trigger } = props;
|
|
if (isTeam) {
|
|
await page.getByTestId("create-button-dropdown").click();
|
|
await page.getByTestId("option-team-1").click();
|
|
} else {
|
|
await page.getByTestId("create-button").click();
|
|
}
|
|
if (name) {
|
|
await fillNameInput(name);
|
|
}
|
|
if (trigger) {
|
|
page.locator("div").filter({ hasText: WorkflowTriggerEvents.BEFORE_EVENT }).nth(1);
|
|
page.getByText(trigger);
|
|
await selectEventType("30 min");
|
|
}
|
|
const workflow = await saveWorkflow();
|
|
|
|
for (const step of workflow.steps) {
|
|
await prisma.workflowStep.update({
|
|
where: { id: step.id },
|
|
data: { verifiedAt: new Date() },
|
|
});
|
|
}
|
|
|
|
await page.getByTestId("go-back-button").click();
|
|
};
|
|
|
|
const saveWorkflow = async () => {
|
|
const submitPromise = page.waitForResponse("/api/trpc/workflows/update?batch=1");
|
|
await page.getByTestId("save-workflow").click();
|
|
const response = await submitPromise;
|
|
expect(response.status()).toBe(200);
|
|
const responseData = await response.json();
|
|
return responseData[0].result.data.json.workflow;
|
|
};
|
|
|
|
const assertListCount = async (count: number) => {
|
|
const workflowListCount = await page.locator('[data-testid="workflow-list"] > li');
|
|
await expect(workflowListCount).toHaveCount(count);
|
|
};
|
|
|
|
const fillNameInput = async (name: string) => {
|
|
await page.getByTestId("workflow-name").fill(name);
|
|
};
|
|
|
|
const editSelectedWorkflow = async (name: string) => {
|
|
const selectedWorkflow = page.getByTestId("workflow-list").getByTestId(nameToTestId(name));
|
|
const editButton = selectedWorkflow.getByRole("button").nth(0);
|
|
|
|
await editButton.click();
|
|
};
|
|
|
|
const hasWorkflowInList = async (name: string, negate?: true) => {
|
|
const selectedWorkflow = page.getByTestId("workflow-list").getByTestId(nameToTestId(name));
|
|
|
|
if (negate) {
|
|
await expect(selectedWorkflow).toBeHidden();
|
|
} else {
|
|
await expect(selectedWorkflow).toBeVisible();
|
|
}
|
|
};
|
|
|
|
const deleteAndConfirm = async (workflow: Locator) => {
|
|
const deleteButton = workflow.getByTestId("delete-button");
|
|
const confirmDeleteText = (await localize("en"))("confirm_delete_workflow");
|
|
|
|
await deleteButton.click();
|
|
await page.getByRole("button", { name: confirmDeleteText }).click();
|
|
};
|
|
|
|
const selectEventType = async (name: string) => {
|
|
await page.getByTestId("multi-select-check-boxes").click();
|
|
await page.getByText(name, { exact: true }).click();
|
|
};
|
|
|
|
const hasReadonlyBadge = async () => {
|
|
const readOnlyBadge = page.getByText((await localize("en"))("readonly"));
|
|
await expect(readOnlyBadge).toBeVisible();
|
|
};
|
|
|
|
const selectedWorkflowPage = async (name: string) => {
|
|
await page.getByTestId("workflow-list").getByTestId(nameToTestId(name)).click();
|
|
};
|
|
|
|
const workflowOptionsAreDisabled = async (workflow: string, negate?: boolean) => {
|
|
const getWorkflowButton = async (buttonTestId: string) =>
|
|
page.getByTestId(nameToTestId(workflow)).getByTestId(buttonTestId);
|
|
const [editButton, deleteButton] = await Promise.all([
|
|
getWorkflowButton("edit-button"),
|
|
getWorkflowButton("delete-button"),
|
|
]);
|
|
|
|
expect(editButton.isDisabled()).toBeTruthy();
|
|
expect(deleteButton.isDisabled()).toBeTruthy();
|
|
};
|
|
|
|
const assertWorkflowReminders = async (eventTypeId: number, count: number) => {
|
|
const booking = await prisma.booking.findFirst({
|
|
where: {
|
|
eventTypeId,
|
|
},
|
|
});
|
|
const workflowReminders = await prisma.workflowReminder.findMany({
|
|
where: {
|
|
bookingUid: booking?.uid ?? "",
|
|
},
|
|
});
|
|
expect(workflowReminders).toHaveLength(count);
|
|
};
|
|
|
|
function nameToTestId(name: string) {
|
|
return `workflow-${name.split(" ").join("-").toLowerCase()}`;
|
|
}
|
|
|
|
return {
|
|
createWorkflow,
|
|
saveWorkflow,
|
|
assertListCount,
|
|
fillNameInput,
|
|
editSelectedWorkflow,
|
|
hasWorkflowInList,
|
|
deleteAndConfirm,
|
|
selectEventType,
|
|
hasReadonlyBadge,
|
|
selectedWorkflowPage,
|
|
workflowOptionsAreDisabled,
|
|
assertWorkflowReminders,
|
|
};
|
|
}
|