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
@@ -1,4 +1,4 @@
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { CreateHomeDto } from './create-home.dto';
|
||||
import { PartialType } from "@nestjs/swagger";
|
||||
import { CreateHomeDto } from "./create-home.dto";
|
||||
|
||||
export class UpdateHomeDto extends PartialType(CreateHomeDto) {}
|
||||
@@ -0,0 +1,99 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { HomeController } from "./home.controller";
|
||||
import { HomeService } from "./home.service";
|
||||
|
||||
describe("HomeController", () => {
|
||||
let controller: HomeController;
|
||||
let service: HomeService;
|
||||
|
||||
const mockHomeData = {
|
||||
heroBanners: [
|
||||
{
|
||||
id: "banner-1",
|
||||
title: "برترین مکملهای مفاصل سگ و گربه",
|
||||
imageUrl: "/banners/hero-joint.jpg",
|
||||
link: "/products/joint-care",
|
||||
order: 1,
|
||||
isActive: true,
|
||||
},
|
||||
],
|
||||
featuredProducts: [
|
||||
{
|
||||
id: "prod-1",
|
||||
title: "قرص کلسیم و مفاصل کانین هیدروکس",
|
||||
slug: "canina-canhydrox-gag",
|
||||
price: 2500000,
|
||||
inventory: 15,
|
||||
rating: 4.9,
|
||||
},
|
||||
],
|
||||
vetTestimonials: [
|
||||
{
|
||||
id: "vet-1",
|
||||
vetName: "دکتر مریم شریفی",
|
||||
clinicName: "کلینیک تخصصی پرشین پت",
|
||||
quote:
|
||||
"مکملهای کانینا از بالاترین استانداردهای فارماکوپه آلمان پیروی میکنند.",
|
||||
},
|
||||
],
|
||||
latestArticles: [
|
||||
{
|
||||
id: "blog-1",
|
||||
title: "چگونه بهترین رژیم غذایی را برای سگ عقیمشده انتخاب کنیم؟",
|
||||
slug: "best-diet-for-neutered-dogs",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const mockHomeService = {
|
||||
getHomeData: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [HomeController],
|
||||
providers: [
|
||||
{
|
||||
provide: HomeService,
|
||||
useValue: mockHomeService,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<HomeController>(HomeController);
|
||||
service = module.get<HomeService>(HomeService);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should be defined", () => {
|
||||
expect(controller).toBeDefined();
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
describe("getHomeData", () => {
|
||||
it("should return home page aggregation payload successfully", async () => {
|
||||
mockHomeService.getHomeData.mockResolvedValue(mockHomeData);
|
||||
|
||||
const result = await controller.getHomeData();
|
||||
|
||||
expect(service.getHomeData).toHaveBeenCalledTimes(1);
|
||||
expect(result).toEqual(mockHomeData);
|
||||
expect(result.heroBanners).toHaveLength(1);
|
||||
expect(result.featuredProducts[0].slug).toBe("canina-canhydrox-gag");
|
||||
});
|
||||
|
||||
it("should propagate errors if homeService throws", async () => {
|
||||
mockHomeService.getHomeData.mockRejectedValue(
|
||||
new Error("Database connection timeout"),
|
||||
);
|
||||
|
||||
await expect(controller.getHomeData()).rejects.toThrow(
|
||||
"Database connection timeout",
|
||||
);
|
||||
expect(service.getHomeData).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,25 +1,25 @@
|
||||
import { Controller, Get, HttpStatus } from '@nestjs/common';
|
||||
import { HomeService } from './home.service';
|
||||
import { Controller, Get, HttpStatus } from "@nestjs/common";
|
||||
import { HomeService } from "./home.service";
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
ApiResponse,
|
||||
ApiOkResponse,
|
||||
} from '@nestjs/swagger';
|
||||
} from "@nestjs/swagger";
|
||||
|
||||
@ApiTags('Home - صفحه اصلی')
|
||||
@Controller('home')
|
||||
@ApiTags("Home - صفحه اصلی")
|
||||
@Controller("home")
|
||||
@ApiResponse({
|
||||
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
description: 'خطای داخلی سرور',
|
||||
description: "خطای داخلی سرور",
|
||||
})
|
||||
export class HomeController {
|
||||
constructor(private readonly homeService: HomeService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'دریافت اطلاعات صفحه اصلی' })
|
||||
@ApiOperation({ summary: "دریافت اطلاعات صفحه اصلی" })
|
||||
@ApiOkResponse({
|
||||
description: 'اطلاعات ویترین، بنرها، پرفروشترینها، وبلاگ و غیره',
|
||||
description: "اطلاعات ویترین، بنرها، پرفروشترینها، وبلاگ و غیره",
|
||||
})
|
||||
getHomeData() {
|
||||
return this.homeService.getHomeData();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { HomeService } from './home.service';
|
||||
import { HomeController } from './home.controller';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { HomeService } from "./home.service";
|
||||
import { HomeController } from "./home.controller";
|
||||
|
||||
@Module({
|
||||
controllers: [HomeController],
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { HomeService } from "./home.service";
|
||||
import { PrismaService } from "../prisma/prisma.service";
|
||||
|
||||
describe("HomeService", () => {
|
||||
let service: HomeService;
|
||||
let prisma: PrismaService;
|
||||
|
||||
const mockPrisma = {
|
||||
heroBanner: {
|
||||
findMany: jest.fn(),
|
||||
},
|
||||
vetTestimonial: {
|
||||
findMany: jest.fn(),
|
||||
},
|
||||
smartAdvisorRule: {
|
||||
findMany: jest.fn(),
|
||||
},
|
||||
product: {
|
||||
findMany: jest.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
HomeService,
|
||||
{ provide: PrismaService, useValue: mockPrisma },
|
||||
],
|
||||
}).compile();
|
||||
|
||||
service = module.get<HomeService>(HomeService);
|
||||
prisma = module.get<PrismaService>(PrismaService);
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should be defined", () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
describe("getHomeData", () => {
|
||||
it("should aggregate active hero banners, testimonials, smart advisor rules, and featured products", async () => {
|
||||
const mockBanners = [
|
||||
{ id: "b1", title: "Banner 1", isActive: true, order: 1 },
|
||||
];
|
||||
const mockTestimonials = [
|
||||
{ id: "t1", doctorName: "دکتر علوی", isActive: true, order: 1 },
|
||||
];
|
||||
const mockRules = [
|
||||
{
|
||||
id: "r1",
|
||||
petType: "DOG",
|
||||
product: { id: "p1", nameFa: "پتویتال", priceValue: 500000 },
|
||||
},
|
||||
];
|
||||
const mockProducts = [
|
||||
{ id: "p1", nameFa: "محصول ۱" },
|
||||
{ id: "p2", nameFa: "محصول ۲" },
|
||||
];
|
||||
|
||||
mockPrisma.heroBanner.findMany.mockResolvedValue(mockBanners);
|
||||
mockPrisma.vetTestimonial.findMany.mockResolvedValue(mockTestimonials);
|
||||
mockPrisma.smartAdvisorRule.findMany.mockResolvedValue(mockRules);
|
||||
mockPrisma.product.findMany.mockResolvedValue(mockProducts);
|
||||
|
||||
const result = await service.getHomeData();
|
||||
|
||||
expect(mockPrisma.heroBanner.findMany).toHaveBeenCalledWith({
|
||||
where: { isActive: true },
|
||||
orderBy: { order: "asc" },
|
||||
});
|
||||
expect(mockPrisma.vetTestimonial.findMany).toHaveBeenCalledWith({
|
||||
where: { isActive: true },
|
||||
orderBy: { order: "asc" },
|
||||
});
|
||||
expect(mockPrisma.smartAdvisorRule.findMany).toHaveBeenCalledWith({
|
||||
include: {
|
||||
product: {
|
||||
select: {
|
||||
id: true,
|
||||
nameFa: true,
|
||||
nameEn: true,
|
||||
slug: true,
|
||||
imageUrl: true,
|
||||
priceValue: true,
|
||||
priceDisplay: true,
|
||||
categorySlug: true,
|
||||
categoryId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(mockPrisma.product.findMany).toHaveBeenCalledWith({
|
||||
take: 4,
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
heroBanners: mockBanners,
|
||||
vetTestimonials: mockTestimonials,
|
||||
smartAdvisorRules: mockRules,
|
||||
featuredProducts: mockProducts,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { PrismaService } from "../prisma/prisma.service";
|
||||
|
||||
@Injectable()
|
||||
export class HomeService {
|
||||
@@ -9,13 +9,13 @@ export class HomeService {
|
||||
// Fetch Banners
|
||||
const heroBanners = await this.prisma.heroBanner.findMany({
|
||||
where: { isActive: true },
|
||||
orderBy: { order: 'asc' },
|
||||
orderBy: { order: "asc" },
|
||||
});
|
||||
|
||||
// Fetch Vet Testimonials
|
||||
const vetTestimonials = await this.prisma.vetTestimonial.findMany({
|
||||
where: { isActive: true },
|
||||
orderBy: { order: 'asc' },
|
||||
orderBy: { order: "asc" },
|
||||
});
|
||||
|
||||
// Fetch Smart Advisor Rules
|
||||
@@ -40,7 +40,7 @@ export class HomeService {
|
||||
// We can also fetch featured products here if needed, or rely on a separate endpoint
|
||||
const featuredProducts = await this.prisma.product.findMany({
|
||||
take: 4,
|
||||
orderBy: { createdAt: 'desc' }, // Or any other criteria
|
||||
orderBy: { createdAt: "desc" }, // Or any other criteria
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user