2026-01-28 13:03:28 +08:00
|
|
|
import { Test, TestingModule } from "@nestjs/testing";
|
|
|
|
|
import { getRepositoryToken } from "@nestjs/typeorm";
|
2026-01-28 10:42:06 +08:00
|
|
|
import {
|
|
|
|
|
NotFoundException,
|
|
|
|
|
ForbiddenException,
|
|
|
|
|
BadRequestException,
|
2026-01-28 13:03:28 +08:00
|
|
|
} from "@nestjs/common";
|
|
|
|
|
import { SchedulesService } from "./schedules.service";
|
|
|
|
|
import { Schedule } from "../../entities/schedule.entity";
|
|
|
|
|
import { Group } from "../../entities/group.entity";
|
|
|
|
|
import { GroupMember } from "../../entities/group-member.entity";
|
|
|
|
|
import { TimeSlotDto } from "./dto/schedule.dto";
|
|
|
|
|
|
|
|
|
|
describe("SchedulesService", () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
let service: SchedulesService;
|
|
|
|
|
let mockScheduleRepository: any;
|
|
|
|
|
let mockGroupRepository: any;
|
|
|
|
|
let mockGroupMemberRepository: any;
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
const mockUser = { id: "user-1", username: "testuser" };
|
|
|
|
|
const mockGroup = { id: "group-1", name: "测试小组", isActive: true };
|
2026-01-28 10:42:06 +08:00
|
|
|
const mockMembership = {
|
2026-01-28 13:03:28 +08:00
|
|
|
id: "member-1",
|
|
|
|
|
userId: "user-1",
|
|
|
|
|
groupId: "group-1",
|
|
|
|
|
role: "member",
|
2026-01-28 10:42:06 +08:00
|
|
|
isActive: true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mockTimeSlots: TimeSlotDto[] = [
|
|
|
|
|
{
|
2026-01-28 13:03:28 +08:00
|
|
|
startTime: new Date("2024-01-20T19:00:00Z"),
|
|
|
|
|
endTime: new Date("2024-01-20T21:00:00Z"),
|
|
|
|
|
note: "晚上空闲",
|
2026-01-28 10:42:06 +08:00
|
|
|
},
|
|
|
|
|
{
|
2026-01-28 13:03:28 +08:00
|
|
|
startTime: new Date("2024-01-21T14:00:00Z"),
|
|
|
|
|
endTime: new Date("2024-01-21T17:00:00Z"),
|
|
|
|
|
note: "下午空闲",
|
2026-01-28 10:42:06 +08:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const mockSchedule = {
|
2026-01-28 13:03:28 +08:00
|
|
|
id: "schedule-1",
|
|
|
|
|
userId: "user-1",
|
|
|
|
|
groupId: "group-1",
|
2026-01-28 10:42:06 +08:00
|
|
|
availableSlots: mockTimeSlots,
|
|
|
|
|
createdAt: new Date(),
|
|
|
|
|
updatedAt: new Date(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
mockScheduleRepository = {
|
|
|
|
|
create: jest.fn(),
|
|
|
|
|
save: jest.fn(),
|
|
|
|
|
find: jest.fn(),
|
|
|
|
|
findOne: jest.fn(),
|
|
|
|
|
remove: jest.fn(),
|
|
|
|
|
createQueryBuilder: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mockGroupRepository = {
|
|
|
|
|
findOne: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mockGroupMemberRepository = {
|
|
|
|
|
find: jest.fn(),
|
|
|
|
|
findOne: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
|
|
|
providers: [
|
|
|
|
|
SchedulesService,
|
|
|
|
|
{
|
|
|
|
|
provide: getRepositoryToken(Schedule),
|
|
|
|
|
useValue: mockScheduleRepository,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
provide: getRepositoryToken(Group),
|
|
|
|
|
useValue: mockGroupRepository,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
provide: getRepositoryToken(GroupMember),
|
|
|
|
|
useValue: mockGroupMemberRepository,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}).compile();
|
|
|
|
|
|
|
|
|
|
service = module.get<SchedulesService>(SchedulesService);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
describe("create", () => {
|
|
|
|
|
it("应该成功创建排班", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockGroupRepository.findOne.mockResolvedValue(mockGroup);
|
|
|
|
|
mockGroupMemberRepository.findOne.mockResolvedValue(mockMembership);
|
|
|
|
|
mockScheduleRepository.create.mockReturnValue(mockSchedule);
|
|
|
|
|
mockScheduleRepository.save.mockResolvedValue(mockSchedule);
|
|
|
|
|
mockScheduleRepository.findOne.mockResolvedValue({
|
|
|
|
|
...mockSchedule,
|
|
|
|
|
user: mockUser,
|
|
|
|
|
group: mockGroup,
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
const result = await service.create("user-1", {
|
|
|
|
|
groupId: "group-1",
|
|
|
|
|
title: "测试排班",
|
2026-01-28 10:42:06 +08:00
|
|
|
availableSlots: mockTimeSlots,
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
expect(result).toHaveProperty("id");
|
2026-01-28 10:42:06 +08:00
|
|
|
expect(mockScheduleRepository.save).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在小组不存在时抛出异常", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockGroupRepository.findOne.mockResolvedValue(null);
|
|
|
|
|
|
|
|
|
|
await expect(
|
2026-01-28 13:03:28 +08:00
|
|
|
service.create("user-1", {
|
|
|
|
|
groupId: "group-1",
|
|
|
|
|
title: "测试排班",
|
2026-01-28 10:42:06 +08:00
|
|
|
availableSlots: mockTimeSlots,
|
|
|
|
|
}),
|
|
|
|
|
).rejects.toThrow(NotFoundException);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在用户不在小组中时抛出异常", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockGroupRepository.findOne.mockResolvedValue(mockGroup);
|
|
|
|
|
mockGroupMemberRepository.findOne.mockResolvedValue(null);
|
|
|
|
|
|
|
|
|
|
await expect(
|
2026-01-28 13:03:28 +08:00
|
|
|
service.create("user-1", {
|
|
|
|
|
groupId: "group-1",
|
|
|
|
|
title: "测试排班",
|
2026-01-28 10:42:06 +08:00
|
|
|
availableSlots: mockTimeSlots,
|
|
|
|
|
}),
|
|
|
|
|
).rejects.toThrow(ForbiddenException);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在时间段为空时抛出异常", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockGroupRepository.findOne.mockResolvedValue(mockGroup);
|
|
|
|
|
mockGroupMemberRepository.findOne.mockResolvedValue(mockMembership);
|
|
|
|
|
|
|
|
|
|
await expect(
|
2026-01-28 13:03:28 +08:00
|
|
|
service.create("user-1", {
|
|
|
|
|
groupId: "group-1",
|
|
|
|
|
title: "测试排班",
|
2026-01-28 10:42:06 +08:00
|
|
|
availableSlots: [],
|
|
|
|
|
}),
|
|
|
|
|
).rejects.toThrow(BadRequestException);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在时间段无效时抛出异常", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockGroupRepository.findOne.mockResolvedValue(mockGroup);
|
|
|
|
|
mockGroupMemberRepository.findOne.mockResolvedValue(mockMembership);
|
|
|
|
|
|
|
|
|
|
await expect(
|
2026-01-28 13:03:28 +08:00
|
|
|
service.create("user-1", {
|
|
|
|
|
groupId: "group-1",
|
|
|
|
|
title: "测试排班",
|
2026-01-28 10:42:06 +08:00
|
|
|
availableSlots: [
|
|
|
|
|
{
|
2026-01-28 13:03:28 +08:00
|
|
|
startTime: new Date("2024-01-20T21:00:00Z"),
|
|
|
|
|
endTime: new Date("2024-01-20T19:00:00Z"), // 结束时间早于开始时间
|
2026-01-28 10:42:06 +08:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}),
|
|
|
|
|
).rejects.toThrow(BadRequestException);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
describe("findAll", () => {
|
|
|
|
|
it("应该成功获取排班列表", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
const mockQueryBuilder = {
|
|
|
|
|
leftJoinAndSelect: jest.fn().mockReturnThis(),
|
|
|
|
|
andWhere: jest.fn().mockReturnThis(),
|
|
|
|
|
orderBy: jest.fn().mockReturnThis(),
|
|
|
|
|
skip: jest.fn().mockReturnThis(),
|
|
|
|
|
take: jest.fn().mockReturnThis(),
|
2026-01-28 13:03:28 +08:00
|
|
|
getManyAndCount: jest.fn().mockResolvedValue([[mockSchedule], 1]),
|
2026-01-28 10:42:06 +08:00
|
|
|
};
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
mockScheduleRepository.createQueryBuilder.mockReturnValue(
|
|
|
|
|
mockQueryBuilder,
|
|
|
|
|
);
|
2026-01-28 10:42:06 +08:00
|
|
|
mockGroupMemberRepository.findOne.mockResolvedValue(mockMembership);
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
const result = await service.findAll("user-1", {
|
|
|
|
|
groupId: "group-1",
|
2026-01-28 10:42:06 +08:00
|
|
|
page: 1,
|
|
|
|
|
limit: 10,
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
expect(result).toHaveProperty("items");
|
|
|
|
|
expect(result).toHaveProperty("total");
|
2026-01-28 10:42:06 +08:00
|
|
|
expect(result.items).toHaveLength(1);
|
|
|
|
|
expect(result.total).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在指定小组且用户不在小组时抛出异常", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
const mockQueryBuilder = {
|
|
|
|
|
leftJoinAndSelect: jest.fn().mockReturnThis(),
|
|
|
|
|
andWhere: jest.fn().mockReturnThis(),
|
|
|
|
|
orderBy: jest.fn().mockReturnThis(),
|
|
|
|
|
skip: jest.fn().mockReturnThis(),
|
|
|
|
|
take: jest.fn().mockReturnThis(),
|
2026-01-28 13:03:28 +08:00
|
|
|
getManyAndCount: jest.fn().mockResolvedValue([[mockSchedule], 1]),
|
2026-01-28 10:42:06 +08:00
|
|
|
};
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
mockScheduleRepository.createQueryBuilder.mockReturnValue(
|
|
|
|
|
mockQueryBuilder,
|
|
|
|
|
);
|
2026-01-28 10:42:06 +08:00
|
|
|
mockGroupMemberRepository.findOne.mockResolvedValue(null);
|
|
|
|
|
|
|
|
|
|
await expect(
|
2026-01-28 13:03:28 +08:00
|
|
|
service.findAll("user-1", {
|
|
|
|
|
groupId: "group-1",
|
2026-01-28 10:42:06 +08:00
|
|
|
}),
|
|
|
|
|
).rejects.toThrow(ForbiddenException);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在无小组ID时返回用户所在所有小组的排班", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
const mockQueryBuilder = {
|
|
|
|
|
leftJoinAndSelect: jest.fn().mockReturnThis(),
|
|
|
|
|
andWhere: jest.fn().mockReturnThis(),
|
|
|
|
|
orderBy: jest.fn().mockReturnThis(),
|
|
|
|
|
skip: jest.fn().mockReturnThis(),
|
|
|
|
|
take: jest.fn().mockReturnThis(),
|
2026-01-28 13:03:28 +08:00
|
|
|
getManyAndCount: jest.fn().mockResolvedValue([[mockSchedule], 1]),
|
2026-01-28 10:42:06 +08:00
|
|
|
};
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
mockScheduleRepository.createQueryBuilder.mockReturnValue(
|
|
|
|
|
mockQueryBuilder,
|
|
|
|
|
);
|
2026-01-28 10:42:06 +08:00
|
|
|
mockGroupMemberRepository.find.mockResolvedValue([
|
2026-01-28 13:03:28 +08:00
|
|
|
{ groupId: "group-1" },
|
|
|
|
|
{ groupId: "group-2" },
|
2026-01-28 10:42:06 +08:00
|
|
|
]);
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
const result = await service.findAll("user-1", {});
|
2026-01-28 10:42:06 +08:00
|
|
|
|
|
|
|
|
expect(result.items).toHaveLength(1);
|
|
|
|
|
expect(mockGroupMemberRepository.find).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
describe("findOne", () => {
|
|
|
|
|
it("应该成功获取排班详情", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockScheduleRepository.findOne.mockResolvedValue({
|
|
|
|
|
...mockSchedule,
|
|
|
|
|
user: mockUser,
|
|
|
|
|
group: mockGroup,
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
const result = await service.findOne("schedule-1");
|
2026-01-28 10:42:06 +08:00
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
expect(result).toHaveProperty("id");
|
|
|
|
|
expect(result.id).toBe("schedule-1");
|
2026-01-28 10:42:06 +08:00
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在排班不存在时抛出异常", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockScheduleRepository.findOne.mockResolvedValue(null);
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
await expect(service.findOne("schedule-1")).rejects.toThrow(
|
2026-01-28 10:42:06 +08:00
|
|
|
NotFoundException,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
describe("update", () => {
|
|
|
|
|
it("应该成功更新排班", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockScheduleRepository.findOne
|
|
|
|
|
.mockResolvedValueOnce(mockSchedule)
|
|
|
|
|
.mockResolvedValueOnce({
|
|
|
|
|
...mockSchedule,
|
|
|
|
|
user: mockUser,
|
|
|
|
|
group: mockGroup,
|
|
|
|
|
});
|
|
|
|
|
mockScheduleRepository.save.mockResolvedValue(mockSchedule);
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
const result = await service.update("user-1", "schedule-1", {
|
2026-01-28 10:42:06 +08:00
|
|
|
availableSlots: mockTimeSlots,
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
expect(result).toHaveProperty("id");
|
2026-01-28 10:42:06 +08:00
|
|
|
expect(mockScheduleRepository.save).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在排班不存在时抛出异常", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockScheduleRepository.findOne.mockResolvedValue(null);
|
|
|
|
|
|
|
|
|
|
await expect(
|
2026-01-28 13:03:28 +08:00
|
|
|
service.update("user-1", "schedule-1", {
|
|
|
|
|
availableSlots: mockTimeSlots,
|
|
|
|
|
}),
|
2026-01-28 10:42:06 +08:00
|
|
|
).rejects.toThrow(NotFoundException);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在非创建者更新时抛出异常", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockScheduleRepository.findOne.mockResolvedValue(mockSchedule);
|
|
|
|
|
|
|
|
|
|
await expect(
|
2026-01-28 13:03:28 +08:00
|
|
|
service.update("user-2", "schedule-1", {
|
|
|
|
|
availableSlots: mockTimeSlots,
|
|
|
|
|
}),
|
2026-01-28 10:42:06 +08:00
|
|
|
).rejects.toThrow(ForbiddenException);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
describe("remove", () => {
|
|
|
|
|
it("应该成功删除排班", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockScheduleRepository.findOne.mockResolvedValue(mockSchedule);
|
|
|
|
|
mockScheduleRepository.remove.mockResolvedValue(mockSchedule);
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
const result = await service.remove("user-1", "schedule-1");
|
2026-01-28 10:42:06 +08:00
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
expect(result).toHaveProperty("message");
|
2026-01-28 10:42:06 +08:00
|
|
|
expect(mockScheduleRepository.remove).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在排班不存在时抛出异常", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockScheduleRepository.findOne.mockResolvedValue(null);
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
await expect(service.remove("user-1", "schedule-1")).rejects.toThrow(
|
2026-01-28 10:42:06 +08:00
|
|
|
NotFoundException,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在非创建者删除时抛出异常", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockScheduleRepository.findOne.mockResolvedValue(mockSchedule);
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
await expect(service.remove("user-2", "schedule-1")).rejects.toThrow(
|
2026-01-28 10:42:06 +08:00
|
|
|
ForbiddenException,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
describe("findCommonSlots", () => {
|
|
|
|
|
it("应该成功查找共同空闲时间", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockGroupMemberRepository.findOne.mockResolvedValue(mockMembership);
|
|
|
|
|
mockScheduleRepository.find.mockResolvedValue([
|
|
|
|
|
{
|
|
|
|
|
...mockSchedule,
|
2026-01-28 13:03:28 +08:00
|
|
|
userId: "user-1",
|
|
|
|
|
user: { id: "user-1" },
|
2026-01-28 10:42:06 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
...mockSchedule,
|
2026-01-28 13:03:28 +08:00
|
|
|
id: "schedule-2",
|
|
|
|
|
userId: "user-2",
|
|
|
|
|
user: { id: "user-2" },
|
2026-01-28 10:42:06 +08:00
|
|
|
availableSlots: [
|
|
|
|
|
{
|
2026-01-28 13:03:28 +08:00
|
|
|
startTime: new Date("2024-01-20T19:30:00Z"),
|
|
|
|
|
endTime: new Date("2024-01-20T22:00:00Z"),
|
2026-01-28 10:42:06 +08:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
const result = await service.findCommonSlots("user-1", {
|
|
|
|
|
groupId: "group-1",
|
|
|
|
|
startTime: new Date("2024-01-20T00:00:00Z"),
|
|
|
|
|
endTime: new Date("2024-01-22T00:00:00Z"),
|
2026-01-28 10:42:06 +08:00
|
|
|
minParticipants: 2,
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
expect(result).toHaveProperty("commonSlots");
|
|
|
|
|
expect(result).toHaveProperty("totalParticipants");
|
2026-01-28 10:42:06 +08:00
|
|
|
expect(result.totalParticipants).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在用户不在小组时抛出异常", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockGroupMemberRepository.findOne.mockResolvedValue(null);
|
|
|
|
|
|
|
|
|
|
await expect(
|
2026-01-28 13:03:28 +08:00
|
|
|
service.findCommonSlots("user-1", {
|
|
|
|
|
groupId: "group-1",
|
|
|
|
|
startTime: new Date("2024-01-20T00:00:00Z"),
|
|
|
|
|
endTime: new Date("2024-01-22T00:00:00Z"),
|
2026-01-28 10:42:06 +08:00
|
|
|
}),
|
|
|
|
|
).rejects.toThrow(ForbiddenException);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
it("应该在没有排班数据时返回空结果", async () => {
|
2026-01-28 10:42:06 +08:00
|
|
|
mockGroupMemberRepository.findOne.mockResolvedValue(mockMembership);
|
|
|
|
|
mockScheduleRepository.find.mockResolvedValue([]);
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
const result = await service.findCommonSlots("user-1", {
|
|
|
|
|
groupId: "group-1",
|
|
|
|
|
startTime: new Date("2024-01-20T00:00:00Z"),
|
|
|
|
|
endTime: new Date("2024-01-22T00:00:00Z"),
|
2026-01-28 10:42:06 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(result.commonSlots).toEqual([]);
|
2026-01-28 13:03:28 +08:00
|
|
|
expect(result.message).toBe("暂无排班数据");
|
2026-01-28 10:42:06 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|