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

97 lines
2.9 KiB
TypeScript

import { Test, TestingModule } from "@nestjs/testing";
import { TestimonialsService } from "./testimonials.service";
import { PrismaService } from "../prisma/prisma.service";
import { NotFoundException } from "@nestjs/common";
describe("TestimonialsService", () => {
let service: TestimonialsService;
const mockPrisma = {
testimonial: {
findMany: jest.fn(),
findUnique: jest.fn(),
create: jest.fn(),
update: jest.fn(),
delete: jest.fn(),
},
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
TestimonialsService,
{
provide: PrismaService,
useValue: mockPrisma,
},
],
}).compile();
service = module.get<TestimonialsService>(TestimonialsService);
jest.clearAllMocks();
});
it("should be defined", () => {
expect(service).toBeDefined();
});
describe("findHomepage", () => {
it("should query only active testimonials flagged for showOnHome ordered by order", async () => {
const activeItems = [
{
id: "t1",
authorName: "دکتر علوی",
order: 1,
isActive: true,
showOnHome: true,
},
];
mockPrisma.testimonial.findMany.mockResolvedValue(activeItems);
const result = await service.findHomepage();
expect(mockPrisma.testimonial.findMany).toHaveBeenCalledWith({
where: { isActive: true, showOnHome: true },
orderBy: { order: "asc" },
});
expect(result).toEqual(activeItems);
});
});
describe("update", () => {
it("should throw NotFoundException if testimonial does not exist", async () => {
mockPrisma.testimonial.findUnique.mockResolvedValue(null);
await expect(
service.update("invalid-id", { authorName: "تغییر نام" }),
).rejects.toThrow(NotFoundException);
});
it("should update and return testimonial when exists", async () => {
mockPrisma.testimonial.findUnique.mockResolvedValue({ id: "t1" });
mockPrisma.testimonial.update.mockResolvedValue({
id: "t1",
authorName: "تغییر نام",
});
const result = await service.update("t1", { authorName: "تغییر نام" });
expect(result.authorName).toBe("تغییر نام");
});
});
describe("remove", () => {
it("should throw NotFoundException if testimonial does not exist on remove", async () => {
mockPrisma.testimonial.findUnique.mockResolvedValue(null);
await expect(service.remove("missing-id")).rejects.toThrow(
NotFoundException,
);
});
it("should delete and return testimonial when found", async () => {
mockPrisma.testimonial.findUnique.mockResolvedValue({ id: "t1" });
mockPrisma.testimonial.delete.mockResolvedValue({ id: "t1" });
const result = await service.remove("t1");
expect(result.id).toBe("t1");
});
});
});