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,6 +1,6 @@
|
||||
import { Controller, Get, Query } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { Controller, Get, Query } from "@nestjs/common";
|
||||
import { ApiTags, ApiOperation } from "@nestjs/swagger";
|
||||
import { PrismaService } from "../prisma/prisma.service";
|
||||
|
||||
function buildTorobProductTitle(product: {
|
||||
nameFa?: string | null;
|
||||
@@ -9,28 +9,28 @@ function buildTorobProductTitle(product: {
|
||||
unit?: string | null;
|
||||
suitableFor?: string | null;
|
||||
}): string {
|
||||
const nameFa = (product.nameFa || '').trim();
|
||||
let nameEn = (product.nameEn || '').trim();
|
||||
const nameFa = (product.nameFa || "").trim();
|
||||
let nameEn = (product.nameEn || "").trim();
|
||||
|
||||
// Clean brand duplicate if nameEn already starts with Canina
|
||||
if (/^Canina\b/i.test(nameEn)) {
|
||||
nameEn = nameEn.replace(/^Canina\s*[-–:]*\s*/i, '').trim();
|
||||
nameEn = nameEn.replace(/^Canina\s*[-–:]*\s*/i, "").trim();
|
||||
}
|
||||
|
||||
// Package size & unit
|
||||
let sizePart = '';
|
||||
let sizePart = "";
|
||||
const numSize = Number(product.packageSize);
|
||||
const unit = (product.unit || '').trim();
|
||||
const unit = (product.unit || "").trim();
|
||||
if (numSize && numSize > 0) {
|
||||
sizePart = unit ? `${numSize} ${unit}` : `${numSize}`;
|
||||
}
|
||||
|
||||
// Suitable for pet
|
||||
let petPart = '';
|
||||
let petPart = "";
|
||||
if (product.suitableFor) {
|
||||
const pet = product.suitableFor.trim();
|
||||
if (pet === 'هر دو' || pet === 'سگ و گربه' || pet === 'سگ، گربه') {
|
||||
petPart = 'مناسب سگ و گربه';
|
||||
if (pet === "هر دو" || pet === "سگ و گربه" || pet === "سگ، گربه") {
|
||||
petPart = "مناسب سگ و گربه";
|
||||
} else if (pet) {
|
||||
petPart = `مناسب ${pet}`;
|
||||
}
|
||||
@@ -40,10 +40,10 @@ function buildTorobProductTitle(product: {
|
||||
if (nameFa) parts.push(nameFa);
|
||||
|
||||
// Brand part
|
||||
if (!nameFa.includes('کنینا') && !nameFa.includes('Canina')) {
|
||||
parts.push('برند کنینا Canina');
|
||||
} else if (!nameFa.includes('Canina')) {
|
||||
parts.push('Canina');
|
||||
if (!nameFa.includes("کنینا") && !nameFa.includes("Canina")) {
|
||||
parts.push("برند کنینا Canina");
|
||||
} else if (!nameFa.includes("Canina")) {
|
||||
parts.push("Canina");
|
||||
}
|
||||
|
||||
if (nameEn && nameEn.toLowerCase() !== nameFa.toLowerCase()) {
|
||||
@@ -58,7 +58,7 @@ function buildTorobProductTitle(product: {
|
||||
parts.push(petPart);
|
||||
}
|
||||
|
||||
return parts.join(' ').replace(/\s+/g, ' ').trim();
|
||||
return parts.join(" ").replace(/\s+/g, " ").trim();
|
||||
}
|
||||
|
||||
function buildTorobProductSpec(product: {
|
||||
@@ -69,59 +69,59 @@ function buildTorobProductSpec(product: {
|
||||
category?: { name?: string } | null;
|
||||
}): Record<string, string> {
|
||||
const spec: Record<string, string> = {
|
||||
برند: 'کنینا (Canina Pharma Germany)',
|
||||
'کشور سازنده': 'آلمان',
|
||||
ضمانت: 'اصالت ۱۰۰٪ کالای آلمانی و سلامت فیزیکی',
|
||||
برند: "کنینا (Canina Pharma Germany)",
|
||||
"کشور سازنده": "آلمان",
|
||||
ضمانت: "اصالت ۱۰۰٪ کالای آلمانی و سلامت فیزیکی",
|
||||
};
|
||||
|
||||
if (product.suitableFor) {
|
||||
spec['گونه هدف'] =
|
||||
product.suitableFor === 'هر دو' ? 'سگ و گربه' : product.suitableFor;
|
||||
spec["گونه هدف"] =
|
||||
product.suitableFor === "هر دو" ? "سگ و گربه" : product.suitableFor;
|
||||
}
|
||||
|
||||
const numSize = Number(product.packageSize);
|
||||
const unit = (product.unit || '').trim();
|
||||
const unit = (product.unit || "").trim();
|
||||
if (numSize && numSize > 0) {
|
||||
spec['حجم / وزن / تعداد'] = unit ? `${numSize} ${unit}` : `${numSize}`;
|
||||
spec["حجم / وزن / تعداد"] = unit ? `${numSize} ${unit}` : `${numSize}`;
|
||||
}
|
||||
|
||||
if (product.artNo) {
|
||||
spec['کد محصول (Art.No)'] = product.artNo;
|
||||
spec["کد محصول (Art.No)"] = product.artNo;
|
||||
}
|
||||
|
||||
if (product.category?.name) {
|
||||
spec['دسته دارویی و درمانی'] = product.category.name;
|
||||
spec["دسته دارویی و درمانی"] = product.category.name;
|
||||
}
|
||||
|
||||
return spec;
|
||||
}
|
||||
|
||||
@ApiTags('Torob Integration - وبسرویس اتصال به ترب')
|
||||
@Controller('torob')
|
||||
@ApiTags("Torob Integration - وبسرویس اتصال به ترب")
|
||||
@Controller("torob")
|
||||
export class TorobController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
@Get('products')
|
||||
@Get("products")
|
||||
@ApiOperation({
|
||||
summary: 'دریافت محصولات جهت وبسرویس خودکار ترب (Torob API)',
|
||||
summary: "دریافت محصولات جهت وبسرویس خودکار ترب (Torob API)",
|
||||
})
|
||||
async getTorobProducts(
|
||||
@Query('page') pageQuery?: string,
|
||||
@Query('page_size') pageSizeQuery?: string,
|
||||
@Query("page") pageQuery?: string,
|
||||
@Query("page_size") pageSizeQuery?: string,
|
||||
) {
|
||||
const page = Math.max(1, parseInt(pageQuery || '1', 10));
|
||||
const page = Math.max(1, parseInt(pageQuery || "1", 10));
|
||||
const pageSize = Math.min(
|
||||
100,
|
||||
Math.max(10, parseInt(pageSizeQuery || '100', 10)),
|
||||
Math.max(10, parseInt(pageSizeQuery || "100", 10)),
|
||||
);
|
||||
const baseUrl = (process.env.FRONTEND_URL || 'https://canina.ir').replace(
|
||||
const baseUrl = (process.env.FRONTEND_URL || "https://canina.ir").replace(
|
||||
/\/$/,
|
||||
'',
|
||||
"",
|
||||
);
|
||||
|
||||
const whereCondition = {
|
||||
noIndex: false,
|
||||
stockStatus: { not: 'DISCONTINUED' as const },
|
||||
stockStatus: { not: "DISCONTINUED" as const },
|
||||
};
|
||||
|
||||
const [totalCount, products] = await Promise.all([
|
||||
@@ -133,7 +133,7 @@ export class TorobController {
|
||||
include: {
|
||||
category: { select: { name: true } },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
orderBy: { createdAt: "desc" },
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -148,49 +148,49 @@ export class TorobController {
|
||||
const spec = buildTorobProductSpec(product);
|
||||
|
||||
// Construct pure English subtitle
|
||||
const rawEn = (product.nameEn || '').trim();
|
||||
const rawEn = (product.nameEn || "").trim();
|
||||
const numSize = Number(product.packageSize);
|
||||
const unit = (product.unit || '').trim();
|
||||
const unit = (product.unit || "").trim();
|
||||
const sizeStr =
|
||||
numSize && numSize > 0
|
||||
? unit
|
||||
? `${numSize} ${unit}`
|
||||
: `${numSize}`
|
||||
: '';
|
||||
let subtitle = rawEn.startsWith('Canina')
|
||||
: "";
|
||||
let subtitle = rawEn.startsWith("Canina")
|
||||
? rawEn
|
||||
: `Canina ${rawEn}`.trim();
|
||||
if (sizeStr && !subtitle.includes(sizeStr)) {
|
||||
subtitle = `${subtitle} - ${sizeStr}`;
|
||||
}
|
||||
|
||||
const rawImage = product.ogImage || product.imageUrl || '';
|
||||
let imageLink = '';
|
||||
const rawImage = product.ogImage || product.imageUrl || "";
|
||||
let imageLink = "";
|
||||
if (rawImage) {
|
||||
const cleanImage = rawImage
|
||||
.trim()
|
||||
.replace(/^https?:\/\/api\.canina\.ir/i, '')
|
||||
.replace(/^https?:\/\/localhost:\d+/i, '')
|
||||
.replace(/^https?:\/\/127\.0\.0\.1:\d+/i, '');
|
||||
.replace(/^https?:\/\/api\.canina\.ir/i, "")
|
||||
.replace(/^https?:\/\/localhost:\d+/i, "")
|
||||
.replace(/^https?:\/\/127\.0\.0\.1:\d+/i, "");
|
||||
|
||||
if (
|
||||
cleanImage.startsWith('http://') ||
|
||||
cleanImage.startsWith('https://')
|
||||
cleanImage.startsWith("http://") ||
|
||||
cleanImage.startsWith("https://")
|
||||
) {
|
||||
imageLink = cleanImage;
|
||||
} else {
|
||||
const cleanPath = cleanImage.replace(/^\/?(api\/)?(uploads\/)?/, '');
|
||||
const cleanPath = cleanImage.replace(/^\/?(api\/)?(uploads\/)?/, "");
|
||||
imageLink = `${baseUrl}/api/uploads/${cleanPath}`;
|
||||
}
|
||||
}
|
||||
|
||||
const isInStock =
|
||||
product.stockStatus !== 'DISCONTINUED' &&
|
||||
product.stockStatus !== 'OUT_OF_STOCK' &&
|
||||
product.stockStatus !== "DISCONTINUED" &&
|
||||
product.stockStatus !== "OUT_OF_STOCK" &&
|
||||
(product.stock === undefined || product.stock > 0) &&
|
||||
String(product.stockStatus || '')
|
||||
String(product.stockStatus || "")
|
||||
.toLowerCase()
|
||||
.includes('in');
|
||||
.includes("in");
|
||||
const price = Number(product.priceValue || 0);
|
||||
const oldPrice = Number(product.priceValue || 0);
|
||||
|
||||
@@ -202,13 +202,13 @@ export class TorobController {
|
||||
page_url: pageUrl,
|
||||
price,
|
||||
old_price: oldPrice,
|
||||
availability: isInStock ? 'instock' : 'outofstock',
|
||||
availability: isInStock ? "instock" : "outofstock",
|
||||
image_link: imageLink,
|
||||
guarantee: 'ضمانت اصالت ۱۰۰٪ کمپانی Canina آلمان و اصالت کالا',
|
||||
guarantee: "ضمانت اصالت ۱۰۰٪ کمپانی Canina آلمان و اصالت کالا",
|
||||
category_name:
|
||||
product.category?.name ||
|
||||
product.categorySlug ||
|
||||
'مکمل حیوانات خانگی',
|
||||
"مکمل حیوانات خانگی",
|
||||
spec,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user