test: comprehensive test suites and quality gates pass across backend, storefront and admin
Deploy Canina / deploy (push) Successful in 4m1s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s

- 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:
devops committed 2026-10-13 16:01:00 +00:00
1 parent 1e73715169
commit ddbf1ca026
439 files changed
+32911 -6107

No files matched your search

+2 -2
View File
@@ -1,4 +1,4 @@
import { PartialType } from '@nestjs/swagger';
import { CreateWikiDto } from './create-wiki.dto';
import { PartialType } from "@nestjs/swagger";
import { CreateWikiDto } from "./create-wiki.dto";
export class UpdateWikiDto extends PartialType(CreateWikiDto) {}
+109
View File
@@ -0,0 +1,109 @@
import { Test, TestingModule } from "@nestjs/testing";
import { WikiController } from "./wiki.controller";
import { WikiService } from "./wiki.service";
import { PaginationDto, SortOrder } from "../common/dto/pagination.dto";
describe("WikiController", () => {
let controller: WikiController;
let service: WikiService;
const mockWikiService = {
findAll: jest.fn(),
findOneByKey: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [WikiController],
providers: [
{
provide: WikiService,
useValue: mockWikiService,
},
],
}).compile();
controller = module.get<WikiController>(WikiController);
service = module.get<WikiService>(WikiService);
});
afterEach(() => {
jest.clearAllMocks();
});
it("should be defined", () => {
expect(controller).toBeDefined();
});
describe("findAll", () => {
it("should return paginated scientific terms based on query", async () => {
const query: PaginationDto = {
page: 1,
limit: 10,
search: "calcium",
sortBy: "term",
sortOrder: SortOrder.ASC,
};
const expectedResult = {
data: [
{
id: "term-1",
key: "calcium-carbonate",
term: "Calcium Carbonate",
definition: "Rich mineral source for bone health",
wikiId: "wiki-1",
},
],
meta: {
total: 1,
page: 1,
lastPage: 1,
limit: 10,
},
};
mockWikiService.findAll.mockResolvedValue(expectedResult);
const result = await controller.findAll(query);
expect(service.findAll).toHaveBeenCalledWith(query);
expect(result).toEqual(expectedResult);
});
it("should handle empty query and default values", async () => {
const query: PaginationDto = {};
const expectedResult = {
data: [],
meta: { total: 0, page: 1, lastPage: 0, limit: 10 },
};
mockWikiService.findAll.mockResolvedValue(expectedResult);
const result = await controller.findAll(query);
expect(service.findAll).toHaveBeenCalledWith(query);
expect(result).toEqual(expectedResult);
});
});
describe("findOne", () => {
it("should return a scientific term by its key", async () => {
const key = "glucosamine";
const expectedTerm = {
id: "term-2",
key,
term: "Glucosamine",
definition: "Natural compound supporting cartilage and joint mobility",
wikiId: "wiki-2",
};
mockWikiService.findOneByKey.mockResolvedValue(expectedTerm);
const result = await controller.findOne(key);
expect(service.findOneByKey).toHaveBeenCalledWith(key);
expect(result).toEqual(expectedTerm);
});
});
});
+14 -14
View File
@@ -1,35 +1,35 @@
import { Controller, Get, Param, HttpStatus, Query } from '@nestjs/common';
import { WikiService } from './wiki.service';
import { Controller, Get, Param, HttpStatus, Query } from "@nestjs/common";
import { WikiService } from "./wiki.service";
import {
ApiTags,
ApiOperation,
ApiResponse,
ApiOkResponse,
ApiNotFoundResponse,
} from '@nestjs/swagger';
import { PaginationDto } from '../common/dto/pagination.dto';
} from "@nestjs/swagger";
import { PaginationDto } from "../common/dto/pagination.dto";
@ApiTags('Wiki - دانشنامه ترکیبات')
@Controller('wiki')
@ApiTags("Wiki - دانشنامه ترکیبات")
@Controller("wiki")
@ApiResponse({
status: HttpStatus.INTERNAL_SERVER_ERROR,
description: 'خطای داخلی سرور',
description: "خطای داخلی سرور",
})
export class WikiController {
constructor(private readonly wikiService: WikiService) {}
@Get()
@ApiOperation({ summary: 'دریافت تمام کلمات دانشنامه' })
@ApiOkResponse({ description: 'لیست کلمات به همراه توضیحات (صفحه‌بندی شده)' })
@ApiOperation({ summary: "دریافت تمام کلمات دانشنامه" })
@ApiOkResponse({ description: "لیست کلمات به همراه توضیحات (صفحه‌بندی شده)" })
findAll(@Query() query: PaginationDto) {
return this.wikiService.findAll(query);
}
@Get(':key')
@ApiOperation({ summary: 'دریافت ترکیب علمی با کلید' })
@ApiOkResponse({ description: 'اطلاعات کامل ترکیب علمی' })
@ApiNotFoundResponse({ description: 'ترکیب علمی یافت نشد' })
findOne(@Param('key') key: string) {
@Get(":key")
@ApiOperation({ summary: "دریافت ترکیب علمی با کلید" })
@ApiOkResponse({ description: "اطلاعات کامل ترکیب علمی" })
@ApiNotFoundResponse({ description: "ترکیب علمی یافت نشد" })
findOne(@Param("key") key: string) {
return this.wikiService.findOneByKey(key);
}
}
+3 -3
View File
@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { WikiService } from './wiki.service';
import { WikiController } from './wiki.controller';
import { Module } from "@nestjs/common";
import { WikiService } from "./wiki.service";
import { WikiController } from "./wiki.controller";
@Module({
controllers: [WikiController],
+96
View File
@@ -0,0 +1,96 @@
import { Test, TestingModule } from "@nestjs/testing";
import { WikiService } from "./wiki.service";
import { PrismaService } from "../prisma/prisma.service";
import { NotFoundException } from "@nestjs/common";
import { SortOrder } from "../common/dto/pagination.dto";
describe("WikiService", () => {
let service: WikiService;
const mockPrisma = {
scientificTerm: {
findMany: jest.fn(),
count: jest.fn(),
findUnique: jest.fn(),
},
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
WikiService,
{
provide: PrismaService,
useValue: mockPrisma,
},
],
}).compile();
service = module.get<WikiService>(WikiService);
jest.clearAllMocks();
});
it("should be defined", () => {
expect(service).toBeDefined();
});
describe("findAll", () => {
it("should paginate and filter terms with fallback to default sortBy", async () => {
const mockTerms = [
{
key: "glucosamine",
term: "گلوکزامین",
definition: "ترکیب محافظت از مفاصل",
wikiId: "W1",
},
];
mockPrisma.scientificTerm.findMany.mockResolvedValue(mockTerms);
mockPrisma.scientificTerm.count.mockResolvedValue(1);
const result = await service.findAll({
search: "مفصل",
page: 1,
limit: 10,
sortBy: "invalidField", // should fallback to 'term'
sortOrder: SortOrder.DESC,
});
expect(mockPrisma.scientificTerm.findMany).toHaveBeenCalledWith({
where: {
OR: [
{ term: { contains: "مفصل", mode: "insensitive" } },
{ definition: { contains: "مفصل", mode: "insensitive" } },
],
},
skip: 0,
take: 10,
orderBy: { term: "desc" },
});
expect(result.data).toEqual(mockTerms);
expect(result.meta.total).toBe(1);
expect(result.meta.lastPage).toBe(1);
});
});
describe("findOneByKey", () => {
it("should throw NotFoundException if scientific term key is not found", async () => {
mockPrisma.scientificTerm.findUnique.mockResolvedValue(null);
await expect(service.findOneByKey("unknown-term")).rejects.toThrow(
NotFoundException,
);
});
it("should return term when found by key", async () => {
const term = {
key: "calcium",
term: "کلسیم",
definition: "ماده معدنی ضروری برای استخوان‌ها",
wikiId: "W2",
};
mockPrisma.scientificTerm.findUnique.mockResolvedValue(term);
const result = await service.findOneByKey("calcium");
expect(result).toEqual(term);
});
});
});
+11 -11
View File
@@ -1,7 +1,7 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { PrismaService } from '../prisma/prisma.service';
import { PaginationDto } from '../common/dto/pagination.dto';
import { Injectable, NotFoundException } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { PrismaService } from "../prisma/prisma.service";
import { PaginationDto } from "../common/dto/pagination.dto";
@Injectable()
export class WikiService {
@@ -12,17 +12,17 @@ export class WikiService {
search,
page = 1,
limit = 10,
sortBy: rawSortBy = 'term',
sortOrder = 'asc',
sortBy: rawSortBy = "term",
sortOrder = "asc",
} = filters;
const allowedSortFields = ['key', 'term', 'wikiId'];
const sortBy = allowedSortFields.includes(rawSortBy) ? rawSortBy : 'term';
const allowedSortFields = ["key", "term", "wikiId"];
const sortBy = allowedSortFields.includes(rawSortBy) ? rawSortBy : "term";
const whereClause: Prisma.ScientificTermWhereInput = {};
if (search) {
whereClause.OR = [
{ term: { contains: search, mode: 'insensitive' } },
{ definition: { contains: search, mode: 'insensitive' } },
{ term: { contains: search, mode: "insensitive" } },
{ definition: { contains: search, mode: "insensitive" } },
];
}
@@ -53,7 +53,7 @@ export class WikiService {
const term = await this.prisma.scientificTerm.findUnique({
where: { key },
});
if (!term) throw new NotFoundException('Wiki term not found');
if (!term) throw new NotFoundException("Wiki term not found");
return term;
}
}