import { ExpertInsurerService } from "./expert-insurer.service"; import { Types } from "mongoose"; describe("QA reporting regressions", () => { it("classifies a roster-owned claim by its linked blame even when that blame is outside the party-insurer list", async () => { const s: any = Object.create(ExpertInsurerService.prototype); const clientKey = String(new Types.ObjectId()), expertId = new Types.ObjectId(), blameId = new Types.ObjectId(); s.expertDbService = { findAll: jest.fn().mockResolvedValue([]) }; s.damageExpertDbService = { findAll: jest .fn() .mockResolvedValue([ { _id: expertId, firstName: "QA", lastName: "Expert" }, ]), }; s.fieldExpertDbService = { findAll: jest.fn().mockResolvedValue([]) }; s.getClientBlameFiles = jest.fn().mockResolvedValue([]); s.getClientClaimFiles = jest .fn() .mockResolvedValue([ { _id: new Types.ObjectId(), blameRequestId: blameId, createdAt: new Date(), }, ]); s.expertFileActivityDbService = { findByTenant: jest.fn().mockResolvedValue([]), }; s.claimDamageExpertActorId = jest.fn().mockReturnValue(String(expertId)); s.blameRequestDbService = { find: jest.fn().mockResolvedValue([{ _id: blameId, type: "CAR_BODY" }]), }; const result = await s.buildExpertReportRows({ clientKey }); expect(result.experts[0]).toMatchObject({ totalFiles: 1, carBodyFiles: 1, thirdPartyFiles: 0, }); expect(s.blameRequestDbService.find).toHaveBeenCalledWith( { _id: { $in: [blameId] } }, { lean: true, select: "type" }, ); }); it("preserves current root user ratings and falls back to legacy nested ratings", () => { const s: any = Object.create(ExpertInsurerService.prototype); const current = { overallEvaluation: 5 }, legacy = { overallEvaluation: 1 }; expect( s.normalizeClaimCase({ userRating: current, evaluation: { userRating: legacy }, }).userRating, ).toBe(current); expect( s.normalizeClaimCase({ evaluation: { userRating: legacy } }).userRating, ).toBe(legacy); }); });