71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
meetingTypes: vi.fn(),
|
|
pages: vi.fn(),
|
|
bookings: vi.fn(),
|
|
calendars: vi.fn(),
|
|
audit: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@hivegrid/db/admin-sales-core.server", () => ({
|
|
writeAdminSalesAudit: mocks.audit,
|
|
}));
|
|
vi.mock("~/utils/db.server", () => ({
|
|
db: {
|
|
adminMeetingType: { findMany: mocks.meetingTypes },
|
|
adminBookingPage: { findMany: mocks.pages },
|
|
adminBooking: { findMany: mocks.bookings },
|
|
adminCalendarConnection: { count: mocks.calendars },
|
|
},
|
|
}));
|
|
|
|
import { readAdminBookingWorkspace } from "./admin-booking-workspace.server";
|
|
|
|
describe("admin booking team scope", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
mocks.meetingTypes.mockResolvedValue([]);
|
|
mocks.pages.mockResolvedValue([]);
|
|
mocks.bookings.mockResolvedValue([
|
|
{ id: "booking-b", adminUserId: "sales-b" },
|
|
]);
|
|
mocks.calendars.mockResolvedValue(0);
|
|
});
|
|
|
|
it("loads team bookings and records a summarized foreign-access audit", async () => {
|
|
await readAdminBookingWorkspace({
|
|
adminUserId: "manager",
|
|
canReadAllCommunication: true,
|
|
actor: (reason) => ({
|
|
adminUserId: "manager",
|
|
email: "manager@example.test",
|
|
reason,
|
|
requestId: null,
|
|
ip: null,
|
|
userAgent: null,
|
|
}),
|
|
});
|
|
|
|
expect(mocks.bookings).toHaveBeenCalledWith(
|
|
expect.objectContaining({ where: {} })
|
|
);
|
|
expect(mocks.audit).toHaveBeenCalledWith(
|
|
expect.anything(),
|
|
expect.objectContaining({
|
|
action: "admin.sales.booking.foreignBookings.read",
|
|
targetId: "booking-b",
|
|
after: {
|
|
foreignTargets: [
|
|
{
|
|
targetId: "booking-b",
|
|
dataOwnerAdminUserId: "sales-b",
|
|
},
|
|
],
|
|
accessKind: "read",
|
|
},
|
|
})
|
|
);
|
|
});
|
|
});
|