Files
calendar/packages/features/bookings/repositories/WrongAssignmentReportRepository.test.ts
Benny JooGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ab21c7f805 refactor: Cal.diy (#28903)
* feat: Cal.diy — community-driven MIT-licensed fork of Cal.com

This squashed commit contains all Cal.diy changes applied on top of calcom/cal.com main:

- Rebrand Cal.com to Cal.diy across the entire codebase
- Remove Enterprise Edition (EE) features, license checks, and AGPL restrictions
- Switch license from AGPL-3.0 to MIT
- Remove docs/ directory (migrated to Nextra at cal.diy)
- Remove dead code: org tests, EE tips, platform nav, premium username, SAML/SSO, etc.
- Clean up .env.example for self-hosted Cal.diy
- Update Docker image references to calcom/cal.diy
- Update README, CONTRIBUTING.md, and issue templates for Cal.diy community fork
- Add PR welcome bot for Cal.diy contributors
- Fix API v2 breaking changes oasdiff ignore entries
- Replace Blacksmith CI runners with default GitHub Actions

3893 files changed, 20789 insertions(+), 411020 deletions(-)

Co-Authored-By: [email protected] <[email protected]>

* refactor: remove org-specific /organizations/:orgId endpoints from API v2 atoms controllers (#1701)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: revert Cal.diy Inc to Cal.com, Inc. in license files, copyright notices, and package metadata (#1702)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* rip out org related comments in api v2

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-04-15 09:52:36 -03:00

153 lines
4.9 KiB
TypeScript

import type { PrismaClient } from "@calcom/prisma";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { WrongAssignmentReportRepository } from "./WrongAssignmentReportRepository";
describe("WrongAssignmentReportRepository", () => {
let repository: WrongAssignmentReportRepository;
const mockPrisma = {
wrongAssignmentReport: {
findUnique: vi.fn(),
create: vi.fn(),
},
} as unknown as PrismaClient;
beforeEach(() => {
vi.clearAllMocks();
repository = new WrongAssignmentReportRepository(mockPrisma);
});
describe("existsByBookingUid", () => {
it("should return true when a report exists for the booking", async () => {
mockPrisma.wrongAssignmentReport.findUnique.mockResolvedValue({ id: "report-123" });
const result = await repository.existsByBookingUid("test-booking-uid");
expect(result).toBe(true);
expect(mockPrisma.wrongAssignmentReport.findUnique).toHaveBeenCalledWith({
where: { bookingUid: "test-booking-uid" },
select: { id: true },
});
});
it("should return false when no report exists for the booking", async () => {
mockPrisma.wrongAssignmentReport.findUnique.mockResolvedValue(null);
const result = await repository.existsByBookingUid("non-existent-booking-uid");
expect(result).toBe(false);
expect(mockPrisma.wrongAssignmentReport.findUnique).toHaveBeenCalledWith({
where: { bookingUid: "non-existent-booking-uid" },
select: { id: true },
});
});
it("should handle empty string bookingUid", async () => {
mockPrisma.wrongAssignmentReport.findUnique.mockResolvedValue(null);
const result = await repository.existsByBookingUid("");
expect(result).toBe(false);
expect(mockPrisma.wrongAssignmentReport.findUnique).toHaveBeenCalledWith({
where: { bookingUid: "" },
select: { id: true },
});
});
});
describe("createReport", () => {
it("should create a report with all fields", async () => {
const input = {
bookingUid: "test-booking-uid",
reportedById: 1,
correctAssignee: "[email protected]",
additionalNotes: "This booking was assigned incorrectly",
teamId: 5,
};
const mockCreatedReport = { id: "report-uuid-123" };
mockPrisma.wrongAssignmentReport.create.mockResolvedValue(mockCreatedReport);
const result = await repository.createReport(input);
expect(result).toEqual({ id: "report-uuid-123" });
expect(mockPrisma.wrongAssignmentReport.create).toHaveBeenCalledWith({
data: input,
select: { id: true },
});
});
it("should create a report with null optional fields", async () => {
const input = {
bookingUid: "test-booking-uid-2",
reportedById: 2,
correctAssignee: null,
additionalNotes: "Wrong person",
teamId: null,
};
const mockCreatedReport = { id: "report-uuid-456" };
mockPrisma.wrongAssignmentReport.create.mockResolvedValue(mockCreatedReport);
const result = await repository.createReport(input);
expect(result).toEqual({ id: "report-uuid-456" });
expect(mockPrisma.wrongAssignmentReport.create).toHaveBeenCalledWith({
data: input,
select: { id: true },
});
});
it("should create a report with empty additionalNotes", async () => {
const input = {
bookingUid: "test-booking-uid-3",
reportedById: 3,
correctAssignee: "[email protected]",
additionalNotes: "",
teamId: 10,
};
const mockCreatedReport = { id: "report-uuid-789" };
mockPrisma.wrongAssignmentReport.create.mockResolvedValue(mockCreatedReport);
const result = await repository.createReport(input);
expect(result).toEqual({ id: "report-uuid-789" });
expect(mockPrisma.wrongAssignmentReport.create).toHaveBeenCalledWith({
data: input,
select: { id: true },
});
});
it("should propagate database errors", async () => {
const input = {
bookingUid: "test-booking-uid",
reportedById: 1,
correctAssignee: null,
additionalNotes: "Notes",
teamId: null,
};
mockPrisma.wrongAssignmentReport.create.mockRejectedValue(new Error("Database connection failed"));
await expect(repository.createReport(input)).rejects.toThrow("Database connection failed");
});
it("should propagate foreign key constraint errors", async () => {
const input = {
bookingUid: "non-existent-booking",
reportedById: 999999,
correctAssignee: null,
additionalNotes: "Notes",
teamId: null,
};
mockPrisma.wrongAssignmentReport.create.mockRejectedValue(
new Error("Foreign key constraint failed on the field: `bookingUid`")
);
await expect(repository.createReport(input)).rejects.toThrow("Foreign key constraint failed");
});
});
});