|
| 1 | +jest.mock("./entities/team.entity", () => ({ |
| 2 | + TeamEntity: class TeamEntity {}, |
| 3 | +})); |
| 4 | +jest.mock("../event/entities/event.entity", () => ({ |
| 5 | + EventEntity: class EventEntity {}, |
| 6 | +})); |
| 7 | +jest.mock("../event/event.service", () => ({ |
| 8 | + EventService: class EventService {}, |
| 9 | +})); |
| 10 | +jest.mock("../github-api/github-api.service", () => ({ |
| 11 | + GithubApiService: class GithubApiService {}, |
| 12 | +})); |
| 13 | +jest.mock("../match/match.service", () => ({ |
| 14 | + MatchService: class MatchService {}, |
| 15 | +})); |
| 16 | +jest.mock("../user/user.service", () => ({ |
| 17 | + UserService: class UserService {}, |
| 18 | +})); |
| 19 | + |
| 20 | +import type { TeamEntity } from "./entities/team.entity"; |
| 21 | +import { TeamService } from "./team.service"; |
| 22 | + |
| 23 | +describe("TeamService.getSearchedTeamsForEvent", () => { |
| 24 | + it("returns the persisted Buchholz score for the admin reveal view", async () => { |
| 25 | + const team = { |
| 26 | + id: "team-1", |
| 27 | + name: "Team One", |
| 28 | + locked: false, |
| 29 | + score: 4, |
| 30 | + buchholzPoints: 12, |
| 31 | + hadBye: false, |
| 32 | + credits: 0, |
| 33 | + createdAt: new Date("2026-01-01T00:00:00.000Z"), |
| 34 | + updatedAt: new Date("2026-01-01T00:00:00.000Z"), |
| 35 | + } as TeamEntity; |
| 36 | + |
| 37 | + const queryBuilder = { |
| 38 | + innerJoin: jest.fn().mockReturnThis(), |
| 39 | + leftJoin: jest.fn().mockReturnThis(), |
| 40 | + where: jest.fn().mockReturnThis(), |
| 41 | + andWhere: jest.fn().mockReturnThis(), |
| 42 | + select: jest.fn().mockReturnThis(), |
| 43 | + addSelect: jest.fn().mockReturnThis(), |
| 44 | + groupBy: jest.fn().mockReturnThis(), |
| 45 | + getRawAndEntities: jest.fn().mockResolvedValue({ |
| 46 | + entities: [team], |
| 47 | + raw: [{ user_count: "2" }], |
| 48 | + }), |
| 49 | + }; |
| 50 | + const calculateBuchholzPointsForTeams = jest |
| 51 | + .fn() |
| 52 | + .mockResolvedValue(new Map([["team-1", 8]])); |
| 53 | + const service = Object.create(TeamService.prototype) as TeamService; |
| 54 | + |
| 55 | + Reflect.set(service, "teamRepository", { |
| 56 | + createQueryBuilder: jest.fn().mockReturnValue(queryBuilder), |
| 57 | + }); |
| 58 | + Reflect.set(service, "eventService", { |
| 59 | + isEventAdmin: jest.fn().mockResolvedValue(true), |
| 60 | + }); |
| 61 | + Reflect.set(service, "matchService", { |
| 62 | + calculateBuchholzPointsForTeams, |
| 63 | + }); |
| 64 | + jest |
| 65 | + .spyOn(service, "getLocationTagsForTeams") |
| 66 | + .mockResolvedValue(new Map([["team-1", []]])); |
| 67 | + |
| 68 | + const result = await service.getSearchedTeamsForEvent( |
| 69 | + "event-1", |
| 70 | + undefined, |
| 71 | + undefined, |
| 72 | + undefined, |
| 73 | + "admin-1", |
| 74 | + true, |
| 75 | + ); |
| 76 | + |
| 77 | + expect(result[0].buchholzPoints).toBe(12); |
| 78 | + expect(calculateBuchholzPointsForTeams).not.toHaveBeenCalled(); |
| 79 | + }); |
| 80 | +}); |
0 commit comments