Files
canina/backend/src/admin/reports.service.spec.ts
T
devops ddbf1ca026
Deploy Canina / deploy (push) Successful in 4m1s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s
test: comprehensive test suites and quality gates pass across backend, storefront and admin
- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation.
- Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings.
- Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors.
- Fixed unmount lifecycle guards, promise error handling, and component edge cases.
2026-10-13 16:01:00 +00:00

86 lines
2.2 KiB
TypeScript

import { Test, TestingModule } from "@nestjs/testing";
import { ReportsService } from "./reports.service";
import { PrismaService } from "../prisma/prisma.service";
describe("ReportsService", () => {
let service: ReportsService;
const mockPrisma = {
order: {
findMany: jest.fn(),
},
orderItem: {
groupBy: jest.fn(),
},
category: {
findMany: jest.fn(),
},
coupon: {
findMany: jest.fn(),
},
user: {
count: jest.fn(),
},
product: {
findMany: jest.fn(),
},
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
ReportsService,
{ provide: PrismaService, useValue: mockPrisma },
],
}).compile();
service = module.get<ReportsService>(ReportsService);
jest.clearAllMocks();
});
it("should be defined", () => {
expect(service).toBeDefined();
});
describe("getDashboardReports", () => {
it("should aggregate revenue, charity, and COGS accurately", async () => {
mockPrisma.order.findMany.mockResolvedValue([
{
id: "ord-1",
totalAmount: 1000000,
charityDonation: 50000,
createdAt: new Date("2026-10-10T10:00:00Z"),
user: { role: "B2C" },
orderItems: [
{
quantity: 2,
product: {
id: "p-1",
buyPrice: 300000,
priceValue: 450000,
},
},
],
},
]);
mockPrisma.orderItem.groupBy.mockResolvedValue([]);
mockPrisma.category.findMany.mockResolvedValue([]);
mockPrisma.coupon.findMany.mockResolvedValue([]);
mockPrisma.user.count.mockResolvedValue(100);
mockPrisma.product.findMany.mockResolvedValue([]);
const report = await service.getDashboardReports({
startDate: "2026-10-01",
endDate: "2026-10-15",
});
expect(report.overview.totalRevenue).toBe(1000000);
expect(report.overview.totalCharity).toBe(50000);
expect(report.overview.totalCostOfGoods).toBe(600000); // 2 * 300000
expect(report.overview.b2cRevenue).toBe(1000000);
expect(report.overview.b2bRevenue).toBe(0);
});
});
});