Files
canina/backend/src/admin/pets.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

110 lines
2.8 KiB
TypeScript

import { Test, TestingModule } from "@nestjs/testing";
import { PetsController } from "./pets.controller";
import { PetsService } from "./pets.service";
import { PaginationDto } from "../common/dto/pagination.dto";
describe("PetsController (Admin)", () => {
let controller: PetsController;
let service: PetsService;
const mockPetsService = {
getPets: jest.fn(),
deletePet: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [PetsController],
providers: [
{
provide: PetsService,
useValue: mockPetsService,
},
],
}).compile();
controller = module.get<PetsController>(PetsController);
service = module.get<PetsService>(PetsService);
});
afterEach(() => {
jest.clearAllMocks();
});
it("should be defined", () => {
expect(controller).toBeDefined();
});
describe("getPets", () => {
it("should return paginated pets with related user and health details", async () => {
const query: PaginationDto = {
page: 1,
limit: 10,
search: "Rex",
};
const expectedResponse = {
data: [
{
id: "pet-1",
name: "Rex",
species: "DOG",
breed: "German Shepherd",
age: 3,
user: {
firstName: "Ali",
lastName: "Tehrani",
email: "ali@example.com",
mobile: "09121111111",
},
medicalConditions: [],
reminders: [],
healthLogs: [],
prescriptions: [],
},
],
meta: {
total: 1,
page: 1,
limit: 10,
lastPage: 1,
},
};
mockPetsService.getPets.mockResolvedValue(expectedResponse);
const result = await controller.getPets(query);
expect(service.getPets).toHaveBeenCalledWith(query);
expect(result).toEqual(expectedResponse);
});
it("should handle default query parameters", async () => {
const query: PaginationDto = {};
const expectedResponse = {
data: [],
meta: { total: 0, page: 1, limit: 10, lastPage: 0 },
};
mockPetsService.getPets.mockResolvedValue(expectedResponse);
const result = await controller.getPets(query);
expect(service.getPets).toHaveBeenCalledWith(query);
expect(result).toEqual(expectedResponse);
});
});
describe("deletePet", () => {
it("should delete pet by id and return success: true", async () => {
const petId = "pet-101";
mockPetsService.deletePet.mockResolvedValue({ id: petId });
const result = await controller.deletePet(petId);
expect(service.deletePet).toHaveBeenCalledWith(petId);
expect(result).toEqual({ success: true });
});
});
});