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.
This commit is contained in:
1 parent
1e73715169
commit
ddbf1ca026
439 files changed
+32911
-6107
No files matched your search
@@ -0,0 +1,96 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { ReportsController } from "./reports.controller";
|
||||
import { ReportsService } from "./reports.service";
|
||||
|
||||
describe("ReportsController (Admin)", () => {
|
||||
let controller: ReportsController;
|
||||
let service: ReportsService;
|
||||
|
||||
const mockReportsService = {
|
||||
getDashboardReports: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [ReportsController],
|
||||
providers: [
|
||||
{
|
||||
provide: ReportsService,
|
||||
useValue: mockReportsService,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<ReportsController>(ReportsController);
|
||||
service = module.get<ReportsService>(ReportsService);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should be defined", () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
|
||||
describe("getReports", () => {
|
||||
it("should pass startDate, endDate, role query filters to service and return success wrapped data", async () => {
|
||||
const startDate = "2026-01-01";
|
||||
const endDate = "2026-03-31";
|
||||
const role = "USER";
|
||||
|
||||
const dashboardData = {
|
||||
totalRevenue: 450000000,
|
||||
ordersCount: 120,
|
||||
averageOrderValue: 3750000,
|
||||
revenueByRole: { USER: 450000000 },
|
||||
popularProducts: [
|
||||
{ productId: "p-1", name: "Canina Canihydrox GAG", totalSold: 85 },
|
||||
],
|
||||
salesByDay: [{ date: "2026-01-01", total: 15000000 }],
|
||||
};
|
||||
|
||||
mockReportsService.getDashboardReports.mockResolvedValue(dashboardData);
|
||||
|
||||
const result = await controller.getReports(startDate, endDate, role);
|
||||
|
||||
expect(service.getDashboardReports).toHaveBeenCalledWith({
|
||||
startDate,
|
||||
endDate,
|
||||
role,
|
||||
});
|
||||
expect(result).toEqual({
|
||||
success: true,
|
||||
data: dashboardData,
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle call when no query parameters are provided", async () => {
|
||||
const defaultDashboardData = {
|
||||
totalRevenue: 0,
|
||||
ordersCount: 0,
|
||||
averageOrderValue: 0,
|
||||
};
|
||||
|
||||
mockReportsService.getDashboardReports.mockResolvedValue(
|
||||
defaultDashboardData,
|
||||
);
|
||||
|
||||
const result = await controller.getReports(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
);
|
||||
|
||||
expect(service.getDashboardReports).toHaveBeenCalledWith({
|
||||
startDate: undefined,
|
||||
endDate: undefined,
|
||||
role: undefined,
|
||||
});
|
||||
expect(result).toEqual({
|
||||
success: true,
|
||||
data: defaultDashboardData,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user