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,273 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { CmsController } from "./cms.controller";
|
||||
import { CmsService } from "./cms.service";
|
||||
import {
|
||||
CreateHeroBannerDto,
|
||||
CreateVetTestimonialDto,
|
||||
CreateSmartAdvisorRuleDto,
|
||||
} from "./dto/cms.dto";
|
||||
|
||||
describe("CmsController", () => {
|
||||
let controller: CmsController;
|
||||
let service: CmsService;
|
||||
|
||||
const mockCmsService = {
|
||||
getHeroBanners: jest.fn(),
|
||||
createHeroBanner: jest.fn(),
|
||||
updateHeroBanner: jest.fn(),
|
||||
deleteHeroBanner: jest.fn(),
|
||||
getVetTestimonials: jest.fn(),
|
||||
createVetTestimonial: jest.fn(),
|
||||
updateVetTestimonial: jest.fn(),
|
||||
deleteVetTestimonial: jest.fn(),
|
||||
getSmartAdvisorRules: jest.fn(),
|
||||
createSmartAdvisorRule: jest.fn(),
|
||||
updateSmartAdvisorRule: jest.fn(),
|
||||
deleteSmartAdvisorRule: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [CmsController],
|
||||
providers: [
|
||||
{
|
||||
provide: CmsService,
|
||||
useValue: mockCmsService,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<CmsController>(CmsController);
|
||||
service = module.get<CmsService>(CmsService);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should be defined", () => {
|
||||
expect(controller).toBeDefined();
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
// ==========================================
|
||||
// Hero Banners
|
||||
// ==========================================
|
||||
describe("Hero Banners", () => {
|
||||
const mockBanner = {
|
||||
id: "hero-1",
|
||||
title: "جشنواره مکملهای تقویتی کانینا",
|
||||
subtitle: "تخفیف ویژه محصولات استخوان و مفاصل",
|
||||
imageUrl: "https://canina.ir/banners/hero1.jpg",
|
||||
buttonText: "مشاهده محصولات",
|
||||
buttonLink: "/category/supplements",
|
||||
order: 1,
|
||||
isActive: true,
|
||||
};
|
||||
|
||||
it("should get all hero banners", async () => {
|
||||
mockCmsService.getHeroBanners.mockResolvedValue([mockBanner]);
|
||||
|
||||
const result = await controller.getHeroBanners();
|
||||
|
||||
expect(service.getHeroBanners).toHaveBeenCalledTimes(1);
|
||||
expect(result).toEqual([mockBanner]);
|
||||
});
|
||||
|
||||
it("should create a new hero banner", async () => {
|
||||
const dto: CreateHeroBannerDto = {
|
||||
title: "جشنواره مکملهای تقویتی کانینا",
|
||||
subtitle: "تخفیف ویژه",
|
||||
imageUrl: "https://canina.ir/banners/hero1.jpg",
|
||||
buttonText: "مشاهده",
|
||||
buttonLink: "/category/supplements",
|
||||
order: 1,
|
||||
isActive: true,
|
||||
};
|
||||
|
||||
mockCmsService.createHeroBanner.mockResolvedValue(mockBanner);
|
||||
|
||||
const result = await controller.createHeroBanner(dto);
|
||||
|
||||
expect(service.createHeroBanner).toHaveBeenCalledWith(dto);
|
||||
expect(result).toEqual(mockBanner);
|
||||
});
|
||||
|
||||
it("should update an existing hero banner", async () => {
|
||||
const updateDto: Partial<CreateHeroBannerDto> = {
|
||||
title: "عنوان ویرایش شده",
|
||||
isActive: false,
|
||||
};
|
||||
const updatedBanner = { ...mockBanner, ...updateDto };
|
||||
|
||||
mockCmsService.updateHeroBanner.mockResolvedValue(updatedBanner);
|
||||
|
||||
const result = await controller.updateHeroBanner("hero-1", updateDto);
|
||||
|
||||
expect(service.updateHeroBanner).toHaveBeenCalledWith(
|
||||
"hero-1",
|
||||
updateDto,
|
||||
);
|
||||
expect(result).toEqual(updatedBanner);
|
||||
});
|
||||
|
||||
it("should delete a hero banner", async () => {
|
||||
mockCmsService.deleteHeroBanner.mockResolvedValue({
|
||||
success: true,
|
||||
id: "hero-1",
|
||||
});
|
||||
|
||||
const result = await controller.deleteHeroBanner("hero-1");
|
||||
|
||||
expect(service.deleteHeroBanner).toHaveBeenCalledWith("hero-1");
|
||||
expect(result).toEqual({ success: true, id: "hero-1" });
|
||||
});
|
||||
});
|
||||
|
||||
// ==========================================
|
||||
// Vet Testimonials
|
||||
// ==========================================
|
||||
describe("Vet Testimonials", () => {
|
||||
const mockTestimonial = {
|
||||
id: "vet-1",
|
||||
vetName: "دکتر رامین کیانی",
|
||||
clinicName: "کلینیک مرکزی دامپزشکی آریا",
|
||||
imageUrl: "https://canina.ir/vets/kiani.jpg",
|
||||
quote: "اثربخشی فرمولاسیون گگ در بازسازی غضروفها بینظیر است.",
|
||||
rating: 5,
|
||||
order: 1,
|
||||
isActive: true,
|
||||
};
|
||||
|
||||
it("should get all vet testimonials", async () => {
|
||||
mockCmsService.getVetTestimonials.mockResolvedValue([mockTestimonial]);
|
||||
|
||||
const result = await controller.getVetTestimonials();
|
||||
|
||||
expect(service.getVetTestimonials).toHaveBeenCalledTimes(1);
|
||||
expect(result).toEqual([mockTestimonial]);
|
||||
});
|
||||
|
||||
it("should create a vet testimonial", async () => {
|
||||
const dto: CreateVetTestimonialDto = {
|
||||
vetName: "دکتر رامین کیانی",
|
||||
clinicName: "کلینیک مرکزی دامپزشکی آریا",
|
||||
imageUrl: "https://canina.ir/vets/kiani.jpg",
|
||||
quote: "اثربخشی فرمولاسیون گگ در بازسازی غضروفها بینظیر است.",
|
||||
rating: 5,
|
||||
order: 1,
|
||||
isActive: true,
|
||||
};
|
||||
|
||||
mockCmsService.createVetTestimonial.mockResolvedValue(mockTestimonial);
|
||||
|
||||
const result = await controller.createVetTestimonial(dto);
|
||||
|
||||
expect(service.createVetTestimonial).toHaveBeenCalledWith(dto);
|
||||
expect(result).toEqual(mockTestimonial);
|
||||
});
|
||||
|
||||
it("should update a vet testimonial", async () => {
|
||||
const updateDto: Partial<CreateVetTestimonialDto> = {
|
||||
quote: "ویرایش متن تجربه بالینی",
|
||||
rating: 4,
|
||||
};
|
||||
const updatedTestimonial = { ...mockTestimonial, ...updateDto };
|
||||
|
||||
mockCmsService.updateVetTestimonial.mockResolvedValue(updatedTestimonial);
|
||||
|
||||
const result = await controller.updateVetTestimonial("vet-1", updateDto);
|
||||
|
||||
expect(service.updateVetTestimonial).toHaveBeenCalledWith(
|
||||
"vet-1",
|
||||
updateDto,
|
||||
);
|
||||
expect(result).toEqual(updatedTestimonial);
|
||||
});
|
||||
|
||||
it("should delete a vet testimonial", async () => {
|
||||
mockCmsService.deleteVetTestimonial.mockResolvedValue({
|
||||
success: true,
|
||||
id: "vet-1",
|
||||
});
|
||||
|
||||
const result = await controller.deleteVetTestimonial("vet-1");
|
||||
|
||||
expect(service.deleteVetTestimonial).toHaveBeenCalledWith("vet-1");
|
||||
expect(result).toEqual({ success: true, id: "vet-1" });
|
||||
});
|
||||
});
|
||||
|
||||
// ==========================================
|
||||
// Smart Advisor Rules
|
||||
// ==========================================
|
||||
describe("Smart Advisor Rules", () => {
|
||||
const mockRule = {
|
||||
id: "rule-1",
|
||||
condition: "لنگش و سفتی مفاصل پا پس از خواب یا استراحت",
|
||||
targetPetType: "DOG",
|
||||
recommendedProduct: "123e4567-e89b-12d3-a456-426614174000",
|
||||
reason:
|
||||
"حاوی گلیکوزآمینوگلیکان و هیدروکسی آپاتیت برای تقویت غضروف و تاندون",
|
||||
};
|
||||
|
||||
it("should get all smart advisor rules", async () => {
|
||||
mockCmsService.getSmartAdvisorRules.mockResolvedValue([mockRule]);
|
||||
|
||||
const result = await controller.getSmartAdvisorRules();
|
||||
|
||||
expect(service.getSmartAdvisorRules).toHaveBeenCalledTimes(1);
|
||||
expect(result).toEqual([mockRule]);
|
||||
});
|
||||
|
||||
it("should create a smart advisor rule", async () => {
|
||||
const dto: CreateSmartAdvisorRuleDto = {
|
||||
condition: "لنگش و سفتی مفاصل پا پس از خواب یا استراحت",
|
||||
targetPetType: "DOG",
|
||||
recommendedProduct: "123e4567-e89b-12d3-a456-426614174000",
|
||||
reason:
|
||||
"حاوی گلیکوزآمینوگلیکان و هیدروکسی آپاتیت برای تقویت غضروف و تاندون",
|
||||
};
|
||||
|
||||
mockCmsService.createSmartAdvisorRule.mockResolvedValue(mockRule);
|
||||
|
||||
const result = await controller.createSmartAdvisorRule(dto);
|
||||
|
||||
expect(service.createSmartAdvisorRule).toHaveBeenCalledWith(dto);
|
||||
expect(result).toEqual(mockRule);
|
||||
});
|
||||
|
||||
it("should update a smart advisor rule", async () => {
|
||||
const updateDto: Partial<CreateSmartAdvisorRuleDto> = {
|
||||
targetPetType: "BOTH",
|
||||
reason: "بهبود دوز مصرفی",
|
||||
};
|
||||
const updatedRule = { ...mockRule, ...updateDto };
|
||||
|
||||
mockCmsService.updateSmartAdvisorRule.mockResolvedValue(updatedRule);
|
||||
|
||||
const result = await controller.updateSmartAdvisorRule(
|
||||
"rule-1",
|
||||
updateDto,
|
||||
);
|
||||
|
||||
expect(service.updateSmartAdvisorRule).toHaveBeenCalledWith(
|
||||
"rule-1",
|
||||
updateDto,
|
||||
);
|
||||
expect(result).toEqual(updatedRule);
|
||||
});
|
||||
|
||||
it("should delete a smart advisor rule", async () => {
|
||||
mockCmsService.deleteSmartAdvisorRule.mockResolvedValue({
|
||||
success: true,
|
||||
id: "rule-1",
|
||||
});
|
||||
|
||||
const result = await controller.deleteSmartAdvisorRule("rule-1");
|
||||
|
||||
expect(service.deleteSmartAdvisorRule).toHaveBeenCalledWith("rule-1");
|
||||
expect(result).toEqual({ success: true, id: "rule-1" });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -7,107 +7,107 @@ import {
|
||||
Body,
|
||||
Param,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { CmsService } from './cms.service';
|
||||
} from "@nestjs/common";
|
||||
import { CmsService } from "./cms.service";
|
||||
import {
|
||||
CreateHeroBannerDto,
|
||||
CreateVetTestimonialDto,
|
||||
CreateSmartAdvisorRuleDto,
|
||||
} from './dto/cms.dto';
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { RolesGuard } from '../auth/roles.guard';
|
||||
import { Roles } from '../auth/roles.decorator';
|
||||
} from "./dto/cms.dto";
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth } from "@nestjs/swagger";
|
||||
import { JwtAuthGuard } from "../auth/jwt-auth.guard";
|
||||
import { RolesGuard } from "../auth/roles.guard";
|
||||
import { Roles } from "../auth/roles.decorator";
|
||||
|
||||
@ApiTags('CMS - مدیریت بنرها، نظرات دامپزشکان و قوانین مشاوره')
|
||||
@Controller('admin/cms')
|
||||
@ApiTags("CMS - مدیریت بنرها، نظرات دامپزشکان و قوانین مشاوره")
|
||||
@Controller("admin/cms")
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('ADMIN')
|
||||
@Roles("ADMIN")
|
||||
@ApiBearerAuth()
|
||||
export class CmsController {
|
||||
constructor(private readonly cmsService: CmsService) {}
|
||||
|
||||
// Hero Banners Admin
|
||||
@Get('hero-banners')
|
||||
@ApiOperation({ summary: 'لیست تمام بنرهای هیرو' })
|
||||
@Get("hero-banners")
|
||||
@ApiOperation({ summary: "لیست تمام بنرهای هیرو" })
|
||||
getHeroBanners() {
|
||||
return this.cmsService.getHeroBanners();
|
||||
}
|
||||
|
||||
@Post('hero-banners')
|
||||
@ApiOperation({ summary: 'ایجاد بنر جدید هیرو' })
|
||||
@Post("hero-banners")
|
||||
@ApiOperation({ summary: "ایجاد بنر جدید هیرو" })
|
||||
createHeroBanner(@Body() dto: CreateHeroBannerDto) {
|
||||
return this.cmsService.createHeroBanner(dto);
|
||||
}
|
||||
|
||||
@Put('hero-banners/:id')
|
||||
@ApiOperation({ summary: 'ویرایش بنر هیرو' })
|
||||
@Put("hero-banners/:id")
|
||||
@ApiOperation({ summary: "ویرایش بنر هیرو" })
|
||||
updateHeroBanner(
|
||||
@Param('id') id: string,
|
||||
@Param("id") id: string,
|
||||
@Body() dto: Partial<CreateHeroBannerDto>,
|
||||
) {
|
||||
return this.cmsService.updateHeroBanner(id, dto);
|
||||
}
|
||||
|
||||
@Delete('hero-banners/:id')
|
||||
@ApiOperation({ summary: 'حذف بنر هیرو' })
|
||||
deleteHeroBanner(@Param('id') id: string) {
|
||||
@Delete("hero-banners/:id")
|
||||
@ApiOperation({ summary: "حذف بنر هیرو" })
|
||||
deleteHeroBanner(@Param("id") id: string) {
|
||||
return this.cmsService.deleteHeroBanner(id);
|
||||
}
|
||||
|
||||
// Vet Testimonials Admin
|
||||
@Get('vet-testimonials')
|
||||
@ApiOperation({ summary: 'لیست تمام نظرات دامپزشکان' })
|
||||
@Get("vet-testimonials")
|
||||
@ApiOperation({ summary: "لیست تمام نظرات دامپزشکان" })
|
||||
getVetTestimonials() {
|
||||
return this.cmsService.getVetTestimonials();
|
||||
}
|
||||
|
||||
@Post('vet-testimonials')
|
||||
@ApiOperation({ summary: 'ایجاد نظر دامپزشک جدید' })
|
||||
@Post("vet-testimonials")
|
||||
@ApiOperation({ summary: "ایجاد نظر دامپزشک جدید" })
|
||||
createVetTestimonial(@Body() dto: CreateVetTestimonialDto) {
|
||||
return this.cmsService.createVetTestimonial(dto);
|
||||
}
|
||||
|
||||
@Put('vet-testimonials/:id')
|
||||
@ApiOperation({ summary: 'ویرایش نظر دامپزشک' })
|
||||
@Put("vet-testimonials/:id")
|
||||
@ApiOperation({ summary: "ویرایش نظر دامپزشک" })
|
||||
updateVetTestimonial(
|
||||
@Param('id') id: string,
|
||||
@Param("id") id: string,
|
||||
@Body() dto: Partial<CreateVetTestimonialDto>,
|
||||
) {
|
||||
return this.cmsService.updateVetTestimonial(id, dto);
|
||||
}
|
||||
|
||||
@Delete('vet-testimonials/:id')
|
||||
@ApiOperation({ summary: 'حذف نظر دامپزشک' })
|
||||
deleteVetTestimonial(@Param('id') id: string) {
|
||||
@Delete("vet-testimonials/:id")
|
||||
@ApiOperation({ summary: "حذف نظر دامپزشک" })
|
||||
deleteVetTestimonial(@Param("id") id: string) {
|
||||
return this.cmsService.deleteVetTestimonial(id);
|
||||
}
|
||||
|
||||
// Smart Advisor Rules Admin
|
||||
@Get('smart-advisor-rules')
|
||||
@ApiOperation({ summary: 'لیست قوانین دستیار هوشمند سلامت' })
|
||||
@Get("smart-advisor-rules")
|
||||
@ApiOperation({ summary: "لیست قوانین دستیار هوشمند سلامت" })
|
||||
getSmartAdvisorRules() {
|
||||
return this.cmsService.getSmartAdvisorRules();
|
||||
}
|
||||
|
||||
@Post('smart-advisor-rules')
|
||||
@ApiOperation({ summary: 'ایجاد قانون مشاوره هوشمند جدید' })
|
||||
@Post("smart-advisor-rules")
|
||||
@ApiOperation({ summary: "ایجاد قانون مشاوره هوشمند جدید" })
|
||||
createSmartAdvisorRule(@Body() dto: CreateSmartAdvisorRuleDto) {
|
||||
return this.cmsService.createSmartAdvisorRule(dto);
|
||||
}
|
||||
|
||||
@Put('smart-advisor-rules/:id')
|
||||
@ApiOperation({ summary: 'ویرایش قانون مشاوره هوشمند' })
|
||||
@Put("smart-advisor-rules/:id")
|
||||
@ApiOperation({ summary: "ویرایش قانون مشاوره هوشمند" })
|
||||
updateSmartAdvisorRule(
|
||||
@Param('id') id: string,
|
||||
@Param("id") id: string,
|
||||
@Body() dto: Partial<CreateSmartAdvisorRuleDto>,
|
||||
) {
|
||||
return this.cmsService.updateSmartAdvisorRule(id, dto);
|
||||
}
|
||||
|
||||
@Delete('smart-advisor-rules/:id')
|
||||
@ApiOperation({ summary: 'حذف قانون مشاوره هوشمند' })
|
||||
deleteSmartAdvisorRule(@Param('id') id: string) {
|
||||
@Delete("smart-advisor-rules/:id")
|
||||
@ApiOperation({ summary: "حذف قانون مشاوره هوشمند" })
|
||||
deleteSmartAdvisorRule(@Param("id") id: string) {
|
||||
return this.cmsService.deleteSmartAdvisorRule(id);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { CmsController } from './cms.controller';
|
||||
import { CmsService } from './cms.service';
|
||||
import { PrismaModule } from '../prisma/prisma.module';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { CmsController } from "./cms.controller";
|
||||
import { CmsService } from "./cms.service";
|
||||
import { PrismaModule } from "../prisma/prisma.module";
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { CmsService } from "./cms.service";
|
||||
import { PrismaService } from "../prisma/prisma.service";
|
||||
import { NotFoundException } from "@nestjs/common";
|
||||
|
||||
describe("CmsService", () => {
|
||||
let service: CmsService;
|
||||
let prisma: PrismaService;
|
||||
|
||||
const mockPrisma = {
|
||||
heroBanner: {
|
||||
findMany: jest.fn(),
|
||||
findUnique: jest.fn(),
|
||||
create: jest.fn(),
|
||||
update: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
},
|
||||
vetTestimonial: {
|
||||
findMany: jest.fn(),
|
||||
findUnique: jest.fn(),
|
||||
create: jest.fn(),
|
||||
update: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
},
|
||||
smartAdvisorRule: {
|
||||
findMany: jest.fn(),
|
||||
findUnique: jest.fn(),
|
||||
create: jest.fn(),
|
||||
update: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [CmsService, { provide: PrismaService, useValue: mockPrisma }],
|
||||
}).compile();
|
||||
|
||||
service = module.get<CmsService>(CmsService);
|
||||
prisma = module.get<PrismaService>(PrismaService);
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should be defined", () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
describe("Hero Banners", () => {
|
||||
it("should return all hero banners ordered by order asc", async () => {
|
||||
mockPrisma.heroBanner.findMany.mockResolvedValue([
|
||||
{ id: "b1", order: 1 },
|
||||
]);
|
||||
const res = await service.getHeroBanners();
|
||||
expect(res).toEqual([{ id: "b1", order: 1 }]);
|
||||
expect(mockPrisma.heroBanner.findMany).toHaveBeenCalledWith({
|
||||
orderBy: { order: "asc" },
|
||||
});
|
||||
});
|
||||
|
||||
it("should create hero banner", async () => {
|
||||
const dto = {
|
||||
title: "New Banner",
|
||||
imageUrl: "/img.png",
|
||||
link: "/test",
|
||||
order: 1,
|
||||
isActive: true,
|
||||
};
|
||||
mockPrisma.heroBanner.create.mockResolvedValue({ id: "b2", ...dto });
|
||||
const res = await service.createHeroBanner(dto);
|
||||
expect(res.id).toBe("b2");
|
||||
expect(mockPrisma.heroBanner.create).toHaveBeenCalledWith({ data: dto });
|
||||
});
|
||||
|
||||
it("should throw NotFoundException on update if hero banner does not exist", async () => {
|
||||
mockPrisma.heroBanner.findUnique.mockResolvedValue(null);
|
||||
await expect(
|
||||
service.updateHeroBanner("invalid", { title: "x" }),
|
||||
).rejects.toThrow(NotFoundException);
|
||||
});
|
||||
|
||||
it("should update hero banner if exists", async () => {
|
||||
mockPrisma.heroBanner.findUnique.mockResolvedValue({ id: "b1" });
|
||||
mockPrisma.heroBanner.update.mockResolvedValue({
|
||||
id: "b1",
|
||||
title: "Updated",
|
||||
});
|
||||
const res = await service.updateHeroBanner("b1", { title: "Updated" });
|
||||
expect(res.title).toBe("Updated");
|
||||
});
|
||||
|
||||
it("should delete hero banner", async () => {
|
||||
mockPrisma.heroBanner.delete.mockResolvedValue({ id: "b1" });
|
||||
const res = await service.deleteHeroBanner("b1");
|
||||
expect(res.id).toBe("b1");
|
||||
expect(mockPrisma.heroBanner.delete).toHaveBeenCalledWith({
|
||||
where: { id: "b1" },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Vet Testimonials", () => {
|
||||
it("should return vet testimonials ordered by order asc", async () => {
|
||||
mockPrisma.vetTestimonial.findMany.mockResolvedValue([
|
||||
{ id: "t1", order: 1 },
|
||||
]);
|
||||
const res = await service.getVetTestimonials();
|
||||
expect(res).toEqual([{ id: "t1", order: 1 }]);
|
||||
});
|
||||
|
||||
it("should throw NotFoundException on update if vet testimonial does not exist", async () => {
|
||||
mockPrisma.vetTestimonial.findUnique.mockResolvedValue(null);
|
||||
await expect(service.updateVetTestimonial("invalid", {})).rejects.toThrow(
|
||||
NotFoundException,
|
||||
);
|
||||
});
|
||||
|
||||
it("should update vet testimonial if exists", async () => {
|
||||
mockPrisma.vetTestimonial.findUnique.mockResolvedValue({ id: "t1" });
|
||||
mockPrisma.vetTestimonial.update.mockResolvedValue({
|
||||
id: "t1",
|
||||
quote: "Great product",
|
||||
});
|
||||
const res = await service.updateVetTestimonial("t1", {
|
||||
quote: "Great product",
|
||||
});
|
||||
expect(res.quote).toBe("Great product");
|
||||
});
|
||||
|
||||
it("should delete vet testimonial", async () => {
|
||||
mockPrisma.vetTestimonial.delete.mockResolvedValue({ id: "t1" });
|
||||
const res = await service.deleteVetTestimonial("t1");
|
||||
expect(res.id).toBe("t1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Smart Advisor Rules", () => {
|
||||
it("should return rules including product details", async () => {
|
||||
mockPrisma.smartAdvisorRule.findMany.mockResolvedValue([
|
||||
{ id: "r1", product: { id: "p1" } },
|
||||
]);
|
||||
const res = await service.getSmartAdvisorRules();
|
||||
expect(res[0].product.id).toBe("p1");
|
||||
expect(mockPrisma.smartAdvisorRule.findMany).toHaveBeenCalledWith({
|
||||
include: { product: true },
|
||||
});
|
||||
});
|
||||
|
||||
it("should throw NotFoundException on update if rule does not exist", async () => {
|
||||
mockPrisma.smartAdvisorRule.findUnique.mockResolvedValue(null);
|
||||
await expect(
|
||||
service.updateSmartAdvisorRule("invalid", {}),
|
||||
).rejects.toThrow(NotFoundException);
|
||||
});
|
||||
|
||||
it("should delete smart advisor rule", async () => {
|
||||
mockPrisma.smartAdvisorRule.delete.mockResolvedValue({ id: "r1" });
|
||||
const res = await service.deleteSmartAdvisorRule("r1");
|
||||
expect(res.id).toBe("r1");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { PrismaService } from "../prisma/prisma.service";
|
||||
import {
|
||||
CreateHeroBannerDto,
|
||||
CreateVetTestimonialDto,
|
||||
CreateSmartAdvisorRuleDto,
|
||||
} from './dto/cms.dto';
|
||||
} from "./dto/cms.dto";
|
||||
|
||||
@Injectable()
|
||||
export class CmsService {
|
||||
@@ -13,7 +13,7 @@ export class CmsService {
|
||||
// --- Hero Banners ---
|
||||
async getHeroBanners() {
|
||||
return this.prisma.heroBanner.findMany({
|
||||
orderBy: { order: 'asc' },
|
||||
orderBy: { order: "asc" },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ export class CmsService {
|
||||
|
||||
async updateHeroBanner(id: string, dto: Partial<CreateHeroBannerDto>) {
|
||||
const exists = await this.prisma.heroBanner.findUnique({ where: { id } });
|
||||
if (!exists) throw new NotFoundException('Hero banner not found');
|
||||
if (!exists) throw new NotFoundException("Hero banner not found");
|
||||
return this.prisma.heroBanner.update({ where: { id }, data: dto });
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export class CmsService {
|
||||
// --- Vet Testimonials ---
|
||||
async getVetTestimonials() {
|
||||
return this.prisma.vetTestimonial.findMany({
|
||||
orderBy: { order: 'asc' },
|
||||
orderBy: { order: "asc" },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ export class CmsService {
|
||||
const exists = await this.prisma.vetTestimonial.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
if (!exists) throw new NotFoundException('Vet testimonial not found');
|
||||
if (!exists) throw new NotFoundException("Vet testimonial not found");
|
||||
return this.prisma.vetTestimonial.update({ where: { id }, data: dto });
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ export class CmsService {
|
||||
const exists = await this.prisma.smartAdvisorRule.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
if (!exists) throw new NotFoundException('Smart advisor rule not found');
|
||||
if (!exists) throw new NotFoundException("Smart advisor rule not found");
|
||||
return this.prisma.smartAdvisorRule.update({ where: { id }, data: dto });
|
||||
}
|
||||
|
||||
|
||||
@@ -4,94 +4,94 @@ import {
|
||||
IsBoolean,
|
||||
IsNumber,
|
||||
IsUUID,
|
||||
} from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
} from "class-validator";
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
|
||||
export class CreateHeroBannerDto {
|
||||
@ApiProperty({ description: 'عنوان اصلی بنر' })
|
||||
@ApiProperty({ description: "عنوان اصلی بنر" })
|
||||
@IsString()
|
||||
title: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'زیرعنوان بنر' })
|
||||
@ApiPropertyOptional({ description: "زیرعنوان بنر" })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
subtitle?: string;
|
||||
|
||||
@ApiProperty({ description: 'آدرس تصویر بنر' })
|
||||
@ApiProperty({ description: "آدرس تصویر بنر" })
|
||||
@IsString()
|
||||
imageUrl: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'متن دکمه' })
|
||||
@ApiPropertyOptional({ description: "متن دکمه" })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
buttonText?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'لینک دکمه' })
|
||||
@ApiPropertyOptional({ description: "لینک دکمه" })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
buttonLink?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'ترتیب نمایش' })
|
||||
@ApiPropertyOptional({ description: "ترتیب نمایش" })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
order?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'فعال/غیرفعال' })
|
||||
@ApiPropertyOptional({ description: "فعال/غیرفعال" })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
export class CreateVetTestimonialDto {
|
||||
@ApiProperty({ description: 'نام دامپزشک' })
|
||||
@ApiProperty({ description: "نام دامپزشک" })
|
||||
@IsString()
|
||||
vetName: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'نام کلینیک' })
|
||||
@ApiPropertyOptional({ description: "نام کلینیک" })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
clinicName?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'تصویر دامپزشک' })
|
||||
@ApiPropertyOptional({ description: "تصویر دامپزشک" })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
imageUrl?: string;
|
||||
|
||||
@ApiProperty({ description: 'متن نظر و تجربه دامپزشک' })
|
||||
@ApiProperty({ description: "متن نظر و تجربه دامپزشک" })
|
||||
@IsString()
|
||||
quote: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'امتیاز (۱ تا ۵)' })
|
||||
@ApiPropertyOptional({ description: "امتیاز (۱ تا ۵)" })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
rating?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'ترتیب نمایش' })
|
||||
@ApiPropertyOptional({ description: "ترتیب نمایش" })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
order?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'فعال/غیرفعال' })
|
||||
@ApiPropertyOptional({ description: "فعال/غیرفعال" })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
export class CreateSmartAdvisorRuleDto {
|
||||
@ApiProperty({ description: 'شرایط انتخاب (علائم یا حالت بالینی)' })
|
||||
@ApiProperty({ description: "شرایط انتخاب (علائم یا حالت بالینی)" })
|
||||
@IsString()
|
||||
condition: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'نوع پت هدف (سگ/گربه/هر دو)' })
|
||||
@ApiPropertyOptional({ description: "نوع پت هدف (سگ/گربه/هر دو)" })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
targetPetType?: string;
|
||||
|
||||
@ApiProperty({ description: 'شناسه محصول پیشنهادی' })
|
||||
@ApiProperty({ description: "شناسه محصول پیشنهادی" })
|
||||
@IsUUID()
|
||||
recommendedProduct: string;
|
||||
|
||||
@ApiProperty({ description: 'علت و منطق پزشکی تجویز' })
|
||||
@ApiProperty({ description: "علت و منطق پزشکی تجویز" })
|
||||
@IsString()
|
||||
reason: string;
|
||||
}
|
||||
Reference in new issue
Block a user