Files
calendar/packages/features/host/repositories/HostRepository.test.ts
T
98b6d63164 refactor: apply biome formatting to packages/features (#27844)
* refactor: apply biome formatting to packages/features (batch 1 - small subdirs)

Format small subdirectories in packages/features: di, flags, holidays, oauth,
settings, users, assignment-reason, selectedCalendar, hashedLink, host, form,
form-builder, availability, data-table, pbac, schedules, troubleshooter,
eventtypes, calendar-subscription, and root-level files.

Also includes straggler apps/web BookEventForm.tsx.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 2 - medium subdirs)

Format medium subdirectories in packages/features: auth, credentials,
calendars, routing-forms, routing-trace, attributes, watchlist, calAIPhone,
tasker, and webhooks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 3 - bookings + insights)

Format bookings and insights subdirectories in packages/features.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 4 - ee)

Format packages/features/ee subdirectory covering billing, workflows,
organizations, teams, managed-event-types, round-robin, dsync,
integration-attribute-sync, and payments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 5 - booking-audit part 1)

Format booking-audit di, actions, common, dto, repository, and types
subdirectories in packages/features/booking-audit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 6 - booking-audit part 2)

Format booking-audit service subdirectory in packages/features/booking-audit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 15:47:14 +01:00

79 lines
2.1 KiB
TypeScript

import { describe, expect, it, vi, beforeEach } from "vitest";
import { PrismaClient } from "@calcom/prisma";
import { HostRepository } from "./HostRepository";
vi.mock("@calcom/prisma", () => {
const mockPrisma = {
host: {
updateMany: vi.fn(),
findMany: vi.fn(),
},
};
return {
__esModule: true,
default: mockPrisma,
PrismaClient: vi.fn().mockImplementation(function () {
return mockPrisma;
}),
};
});
describe("HostRepository", () => {
let prisma: PrismaClient;
let hostRepo: HostRepository;
beforeEach(() => {
prisma = new PrismaClient();
hostRepo = new HostRepository(prisma);
vi.clearAllMocks();
});
describe("updateHostsWithNewDefaultSchedule", () => {
it("should update hosts with new scheduleId", async () => {
const userId = 1;
const oldScheduleId = 123;
const newScheduleId = 456;
const updateResult = { count: 2 }; // 2 hosts updated
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(prisma.host.updateMany as any).mockResolvedValue(updateResult);
const result = await hostRepo.updateHostsSchedule(userId, oldScheduleId, newScheduleId);
expect(prisma.host.updateMany).toHaveBeenCalledWith({
where: {
userId,
scheduleId: oldScheduleId,
},
data: {
scheduleId: newScheduleId,
},
});
expect(result).toEqual(updateResult);
});
it("should handle case with no hosts to update", async () => {
const userId = 1;
const oldScheduleId = 123;
const newScheduleId = 456;
const updateResult = { count: 0 }; // No hosts updated
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(prisma.host.updateMany as any).mockResolvedValue(updateResult);
const result = await hostRepo.updateHostsSchedule(userId, oldScheduleId, newScheduleId);
expect(prisma.host.updateMany).toHaveBeenCalledWith({
where: {
userId,
scheduleId: oldScheduleId,
},
data: {
scheduleId: newScheduleId,
},
});
expect(result).toEqual(updateResult);
});
});
});