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,152 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { TestimonialsController } from "./testimonials.controller";
|
||||
import { TestimonialsService } from "./testimonials.service";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
describe("TestimonialsController", () => {
|
||||
let controller: TestimonialsController;
|
||||
let service: TestimonialsService;
|
||||
|
||||
const mockTestimonialsService = {
|
||||
findAll: jest.fn(),
|
||||
findHomepage: jest.fn(),
|
||||
create: jest.fn(),
|
||||
update: jest.fn(),
|
||||
remove: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [TestimonialsController],
|
||||
providers: [
|
||||
{
|
||||
provide: TestimonialsService,
|
||||
useValue: mockTestimonialsService,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<TestimonialsController>(TestimonialsController);
|
||||
service = module.get<TestimonialsService>(TestimonialsService);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should be defined", () => {
|
||||
expect(controller).toBeDefined();
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
describe("findAll", () => {
|
||||
it("should return all testimonials", async () => {
|
||||
const mockList = [
|
||||
{
|
||||
id: "testi-1",
|
||||
authorName: "فرهاد پیروز",
|
||||
roleTitle: "سرپرست سگ ژرمن شپرد",
|
||||
content: "مکمل مفاصل کانین هیدروکس واقعا معجزه کرد برای پای سگم.",
|
||||
rating: 5,
|
||||
isActive: true,
|
||||
showOnHome: true,
|
||||
order: 1,
|
||||
},
|
||||
];
|
||||
|
||||
mockTestimonialsService.findAll.mockResolvedValue(mockList);
|
||||
|
||||
const result = await controller.findAll();
|
||||
|
||||
expect(service.findAll).toHaveBeenCalledTimes(1);
|
||||
expect(result).toEqual(mockList);
|
||||
});
|
||||
});
|
||||
|
||||
describe("findHomepage", () => {
|
||||
it("should return only active homepage testimonials", async () => {
|
||||
const mockHomeList = [
|
||||
{
|
||||
id: "testi-1",
|
||||
authorName: "فرهاد پیروز",
|
||||
showOnHome: true,
|
||||
isActive: true,
|
||||
},
|
||||
];
|
||||
|
||||
mockTestimonialsService.findHomepage.mockResolvedValue(mockHomeList);
|
||||
|
||||
const result = await controller.findHomepage();
|
||||
|
||||
expect(service.findHomepage).toHaveBeenCalledTimes(1);
|
||||
expect(result).toEqual(mockHomeList);
|
||||
});
|
||||
});
|
||||
|
||||
describe("create", () => {
|
||||
it("should create a new testimonial via service.create", async () => {
|
||||
const createInput: Prisma.TestimonialCreateInput = {
|
||||
authorName: "مونا اسدی",
|
||||
roleTitle: "سرپرست گربه پرشین",
|
||||
content: "پودر بیوتین باعث براق شدن و قطع ریزش موی گربهام شد.",
|
||||
rating: 5,
|
||||
isActive: true,
|
||||
showOnHome: true,
|
||||
order: 2,
|
||||
};
|
||||
|
||||
const created = {
|
||||
id: "testi-2",
|
||||
...createInput,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
mockTestimonialsService.create.mockResolvedValue(created);
|
||||
|
||||
const result = await controller.create(createInput);
|
||||
|
||||
expect(service.create).toHaveBeenCalledWith(createInput);
|
||||
expect(result).toEqual(created);
|
||||
});
|
||||
});
|
||||
|
||||
describe("update", () => {
|
||||
it("should update a testimonial by id via service.update", async () => {
|
||||
const testId = "testi-1";
|
||||
const updateInput: Prisma.TestimonialUpdateInput = {
|
||||
content: "متن ویرایش شده رضایتنامه مشتری",
|
||||
rating: 5,
|
||||
};
|
||||
|
||||
const updated = {
|
||||
id: testId,
|
||||
authorName: "فرهاد پیروز",
|
||||
content: "متن ویرایش شده رضایتنامه مشتری",
|
||||
rating: 5,
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
mockTestimonialsService.update.mockResolvedValue(updated);
|
||||
|
||||
const result = await controller.update(testId, updateInput);
|
||||
|
||||
expect(service.update).toHaveBeenCalledWith(testId, updateInput);
|
||||
expect(result).toEqual(updated);
|
||||
});
|
||||
});
|
||||
|
||||
describe("remove", () => {
|
||||
it("should delete a testimonial by id via service.remove", async () => {
|
||||
const testId = "testi-del-1";
|
||||
const deleted = { id: testId, authorName: "حذف شده" };
|
||||
|
||||
mockTestimonialsService.remove.mockResolvedValue(deleted);
|
||||
|
||||
const result = await controller.remove(testId);
|
||||
|
||||
expect(service.remove).toHaveBeenCalledWith(testId);
|
||||
expect(result).toEqual(deleted);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user