Files
canina/backend/src/products/products.controller.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

59 lines
1.8 KiB
TypeScript

import { Test, TestingModule } from "@nestjs/testing";
import { ProductsController } from "./products.controller";
import { ProductsService } from "./products.service";
import { NotFoundException } from "@nestjs/common";
describe("ProductsController", () => {
let controller: ProductsController;
let service: ProductsService;
const mockProductsService = {
findAll: jest
.fn()
.mockResolvedValue([{ id: "prod-id", name: "Product 1" }]),
findOne: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ProductsController],
providers: [{ provide: ProductsService, useValue: mockProductsService }],
}).compile();
controller = module.get<ProductsController>(ProductsController);
service = module.get<ProductsService>(ProductsService);
});
afterEach(() => {
jest.clearAllMocks();
});
it("should be defined", () => {
expect(controller).toBeDefined();
});
it("should list products", async () => {
const query = { category: "joints" };
const result = await controller.findAll(query);
expect(service.findAll).toHaveBeenCalledWith(query);
expect(result).toHaveLength(1);
});
describe("findOne", () => {
it("should throw NotFoundException if product not found", async () => {
mockProductsService.findOne.mockResolvedValue(null);
await expect(controller.findOne("invalid-id")).rejects.toThrow(
NotFoundException,
);
});
it("should return product details if found", async () => {
const prod = { id: "prod-id", name: "Product 1" };
mockProductsService.findOne.mockResolvedValue(prod);
const result = await controller.findOne("prod-id");
expect(service.findOne).toHaveBeenCalledWith("prod-id");
expect(result).toEqual(prod);
});
});
});