* wip * wip * wip * Add tests * Update getSchedule.test.ts * Update types.ts * Self review fixes * Update text * PR feedback from Carina * Use utcoffset for range as well * Remove logging from the function that runs on every timeslot * Add one more test * Show x days instead of x+1 days for both ROLLING and ROLLING_WINDOW * refactor tests * Move bookingScenario imports to the top as they import prismock mock that has to be imported very early * More reordering of imports * Fix accidental min update at wrong place * Handle legacy value of zero for periodDays * Range fix * Fix isDateOutOfBound not being checked properly during booking. Also added a test for the case * Fix duplicate element, how the hell it reached there * Use today plus x days for ROLLING periodType * Add disabled for Checkbox as well * Revert logger.ts * Formatting Signed-off-by: zomars <zomars@me.com> * Fix ordering of imports that is causing tests failure --------- Signed-off-by: zomars <zomars@me.com> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Omar López <zomars@me.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import prismock from "../../../../../tests/libs/__mocks__/prisma";
|
|
|
|
import { expectWebhookToHaveBeenCalledWith } from "@calcom/web/test/utils/bookingScenario/expects";
|
|
|
|
import { describe, expect, beforeEach } from "vitest";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
import { test } from "@calcom/web/test/fixtures/fixtures";
|
|
|
|
import { handleWebhookScheduledTriggers } from "../handleWebhookScheduledTriggers";
|
|
|
|
describe("Cron job handler", () => {
|
|
beforeEach(async () => {
|
|
await prismock.webhookScheduledTriggers.deleteMany();
|
|
});
|
|
test(`should delete old webhook scheduled triggers`, async () => {
|
|
const now = dayjs();
|
|
await prismock.webhookScheduledTriggers.createMany({
|
|
data: [
|
|
{
|
|
id: 1,
|
|
subscriberUrl: "https://example.com",
|
|
startAfter: now.subtract(2, "day").toDate(),
|
|
payload: "",
|
|
},
|
|
{
|
|
id: 1,
|
|
subscriberUrl: "https://example.com",
|
|
startAfter: now.subtract(1, "day").subtract(1, "hour").toDate(),
|
|
payload: "",
|
|
},
|
|
{
|
|
id: 2,
|
|
subscriberUrl: "https://example.com",
|
|
startAfter: now.add(1, "day").toDate(),
|
|
payload: "",
|
|
},
|
|
],
|
|
});
|
|
|
|
await handleWebhookScheduledTriggers(prismock);
|
|
|
|
const scheduledTriggers = await prismock.webhookScheduledTriggers.findMany();
|
|
expect(scheduledTriggers.length).toBe(1);
|
|
expect(scheduledTriggers[0].startAfter).toStrictEqual(now.add(1, "day").toDate());
|
|
});
|
|
test(`should trigger if current date is after startAfter`, async () => {
|
|
const now = dayjs();
|
|
const payload = `{"triggerEvent":"MEETING_ENDED"}`;
|
|
await prismock.webhookScheduledTriggers.createMany({
|
|
data: [
|
|
{
|
|
id: 1,
|
|
subscriberUrl: "https://example.com",
|
|
startAfter: now.add(5, "minute").toDate(),
|
|
payload,
|
|
},
|
|
{
|
|
id: 2,
|
|
subscriberUrl: "https://example.com/test",
|
|
startAfter: now.subtract(5, "minute").toDate(),
|
|
payload,
|
|
},
|
|
],
|
|
});
|
|
await handleWebhookScheduledTriggers(prismock);
|
|
|
|
expectWebhookToHaveBeenCalledWith("https://example.com/test", { triggerEvent: "MEETING_ENDED", payload });
|
|
expect(() =>
|
|
expectWebhookToHaveBeenCalledWith("https://example.com", { triggerEvent: "MEETING_ENDED", payload })
|
|
).toThrow("Webhook not sent to https://example.com for MEETING_ENDED. All webhooks: []");
|
|
});
|
|
});
|