import { DecimalInterceptor } from "./decimal.interceptor"; import { ExecutionContext, CallHandler } from "@nestjs/common"; import { Prisma } from "@prisma/client"; import { of } from "rxjs"; describe("DecimalInterceptor", () => { let interceptor: DecimalInterceptor; beforeEach(() => { interceptor = new DecimalInterceptor(); }); it("should be defined", () => { expect(interceptor).toBeDefined(); }); it("should transform Prisma.Decimal instances to exact string representations", (done) => { const mockData = { id: "order-1", totalAmount: new Prisma.Decimal("64.98"), items: [ { id: "item-1", unitPrice: new Prisma.Decimal("32.49"), }, ], }; const executionContext = {} as ExecutionContext; const callHandler: CallHandler = { handle: () => of(mockData), }; interceptor.intercept(executionContext, callHandler).subscribe((result) => { expect(result).toEqual({ id: "order-1", totalAmount: "64.98", items: [ { id: "item-1", unitPrice: "32.49", }, ], }); done(); }); }); it("should leave non-decimal values unchanged", (done) => { const mockData = { name: "Test", age: 5, isActive: true, createdAt: new Date("2026-01-01T00:00:00.000Z"), }; const executionContext = {} as ExecutionContext; const callHandler: CallHandler = { handle: () => of(mockData), }; interceptor.intercept(executionContext, callHandler).subscribe((result) => { expect(result).toEqual(mockData); done(); }); }); });