* feature for team ooo crud and past records * added tests for ooo handler, combined list components for mine,team * nit: removed commented code * added current-previous tab , not to show TeamOOO tab for nonadmin * update for type checks * updated tests after merge * updated outofoffice handler after merge * for alignment with outofoffice header column * update after resolving merge conflicts * nit/chore: spacing * update after changes in router migration * ui improvements rounded corner * updated props * Update apps/web/public/static/locales/en/common.json Co-authored-by: Carina Wollendorfer <[email protected]> * Update apps/web/public/static/locales/en/common.json Co-authored-by: Carina Wollendorfer <[email protected]> * updated dialog subtitles, review comments * Update packages/features/settings/outOfOffice/CreateOrEditOutOfOfficeModal.tsx Co-authored-by: Amit Sharma <[email protected]> * Update packages/trpc/server/routers/loggedInViewer/outOfOffice.schema.ts Co-authored-by: Amit Sharma <[email protected]> * refactored to split ooo handlers, review comments * updated test.utils * chore * chore: unrelated changes may be merge * optimized query * update due to latest changes and merge conflicts * updates to changes in people filter * chore * as now taken care in DataTable * updates after merge * updates after merge due tp changes in datatable and others * update import due to file splitting and new name * update for typecheck * update for new add button when empty entries * nit * replace tests with e2e tests * chore * include only manage team ooo * fix type check * Update safe-parse.ts * use invalidate instead of props, leaving main server components as it is * nit * update forMember div ht in edit mode --------- Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: Amit Sharma <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]> Co-authored-by: Tushar Bhatt <[email protected]>
130 lines
3.2 KiB
TypeScript
130 lines
3.2 KiB
TypeScript
import { describe, expect, it, beforeEach, afterEach } from "vitest";
|
|
import { vi } from "vitest";
|
|
|
|
import { prisma } from "@calcom/prisma";
|
|
|
|
import { outOfOfficeCreateOrUpdate } from "../outOfOfficeCreateOrUpdate.handler";
|
|
|
|
const prismaMock = {
|
|
outOfOfficeEntry: {
|
|
findFirst: vi.fn().mockResolvedValue(undefined),
|
|
findUnique: vi.fn().mockResolvedValue(undefined),
|
|
upsert: vi.fn().mockResolvedValue(undefined),
|
|
},
|
|
};
|
|
vi.spyOn(prisma.outOfOfficeEntry, "findFirst").mockImplementation(prismaMock.outOfOfficeEntry.findFirst);
|
|
vi.spyOn(prisma.outOfOfficeEntry, "findUnique").mockImplementation(prismaMock.outOfOfficeEntry.findUnique);
|
|
vi.spyOn(prisma.outOfOfficeEntry, "upsert").mockImplementation(prismaMock.outOfOfficeEntry.upsert);
|
|
|
|
afterEach(() => {
|
|
prismaMock.outOfOfficeEntry.findFirst.mockClear();
|
|
prismaMock.outOfOfficeEntry.findUnique.mockClear();
|
|
prismaMock.outOfOfficeEntry.upsert.mockClear();
|
|
});
|
|
|
|
const mockUser = {
|
|
id: 4,
|
|
username: "pro",
|
|
email: "[email protected]",
|
|
password: {
|
|
hash: "",
|
|
userId: 0,
|
|
},
|
|
completedOnboarding: true,
|
|
identityProvider: "CAL",
|
|
profiles: [],
|
|
avatar: "",
|
|
organization: null,
|
|
organizationId: null,
|
|
locale: "en",
|
|
timeZone: "UTC",
|
|
defaultScheduleId: null,
|
|
email_verified: true,
|
|
name: null,
|
|
theme: null,
|
|
} as const;
|
|
|
|
describe("outOfOfficeCreateOrUpdate", () => {
|
|
beforeEach(() => {
|
|
vi.resetAllMocks();
|
|
vi.setSystemTime(new Date("2024-11-22T03:23:45Z"));
|
|
});
|
|
|
|
it("should throw error if start date is after end date", async () => {
|
|
const input = {
|
|
dateRange: {
|
|
startDate: new Date("2024-11-23T23:00:00.000Z"),
|
|
endDate: new Date("2024-11-22T23:00:00.000Z"),
|
|
},
|
|
offset: 60,
|
|
reasonId: 1,
|
|
notes: "",
|
|
toTeamUserId: null,
|
|
};
|
|
|
|
await expect(outOfOfficeCreateOrUpdate({ ctx: { user: mockUser }, input })).rejects.toThrow(
|
|
"start_date_must_be_before_end_date"
|
|
);
|
|
});
|
|
|
|
it("should handle timezone offset correctly", async () => {
|
|
const input = {
|
|
dateRange: {
|
|
startDate: new Date("2024-11-23T23:00:00.000Z"),
|
|
endDate: new Date("2024-11-23T23:00:00.000Z"),
|
|
},
|
|
offset: 60, // Paris timezone offset in minutes
|
|
reasonId: 1,
|
|
notes: "",
|
|
toTeamUserId: null,
|
|
};
|
|
const startTimeUtc = "2024-11-24T00:00:00.000Z";
|
|
const endTimeUtc = "2024-11-24T23:59:59.999Z";
|
|
|
|
await outOfOfficeCreateOrUpdate({
|
|
ctx: { user: mockUser },
|
|
input,
|
|
});
|
|
|
|
expect(prisma.outOfOfficeEntry.findFirst).toHaveBeenNthCalledWith(1, {
|
|
select: {
|
|
toUserId: true,
|
|
userId: true,
|
|
},
|
|
where: {
|
|
OR: [
|
|
{
|
|
AND: [
|
|
{
|
|
start: {
|
|
lte: endTimeUtc,
|
|
},
|
|
},
|
|
{
|
|
end: {
|
|
gte: startTimeUtc,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
AND: [
|
|
{
|
|
start: {
|
|
gte: startTimeUtc,
|
|
},
|
|
},
|
|
{
|
|
end: {
|
|
lte: endTimeUtc,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
toUserId: 4,
|
|
},
|
|
});
|
|
});
|
|
});
|