- 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.
98 lines
3.0 KiB
TypeScript
98 lines
3.0 KiB
TypeScript
import { Test, TestingModule } from "@nestjs/testing";
|
|
import { SettingsService } from "./settings.service";
|
|
import { PrismaService } from "../prisma/prisma.service";
|
|
import { SmsService } from "../common/services/sms.service";
|
|
|
|
describe("SettingsService", () => {
|
|
let service: SettingsService;
|
|
let prisma: PrismaService;
|
|
|
|
const mockPrisma = {
|
|
uiText: {
|
|
findMany: jest.fn(),
|
|
upsert: jest.fn(),
|
|
},
|
|
setting: {
|
|
findMany: jest.fn().mockResolvedValue([]),
|
|
upsert: jest.fn(),
|
|
},
|
|
scientificTerm: {
|
|
findMany: jest.fn(),
|
|
upsert: jest.fn(),
|
|
delete: jest.fn(),
|
|
},
|
|
};
|
|
|
|
const mockSmsService = {
|
|
getSmsLogs: jest.fn(),
|
|
sendOtp: jest.fn(),
|
|
};
|
|
|
|
beforeEach(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
providers: [
|
|
SettingsService,
|
|
{ provide: PrismaService, useValue: mockPrisma },
|
|
{ provide: SmsService, useValue: mockSmsService },
|
|
],
|
|
}).compile();
|
|
|
|
service = module.get<SettingsService>(SettingsService);
|
|
prisma = module.get<PrismaService>(PrismaService);
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it("should be defined", () => {
|
|
expect(service).toBeDefined();
|
|
});
|
|
|
|
it("should getUiTexts", async () => {
|
|
mockPrisma.uiText.findMany.mockResolvedValue([{ key: "k", value: "v" }]);
|
|
const result = await service.getUiTexts();
|
|
expect(prisma.uiText.findMany).toHaveBeenCalled();
|
|
expect(result).toHaveLength(1);
|
|
});
|
|
|
|
it("should updateUiText", async () => {
|
|
mockPrisma.uiText.upsert.mockResolvedValue({ key: "k", value: "v2" });
|
|
const result = await service.updateUiText("k", "v2");
|
|
expect(prisma.uiText.upsert).toHaveBeenCalledWith({
|
|
where: { key: "k" },
|
|
update: { value: "v2" },
|
|
create: { key: "k", value: "v2" },
|
|
});
|
|
expect(result.value).toBe("v2");
|
|
});
|
|
|
|
it("should getScientificTerms", async () => {
|
|
mockPrisma.scientificTerm.findMany.mockResolvedValue([{ key: "k" }]);
|
|
const result = await service.getScientificTerms();
|
|
expect(prisma.scientificTerm.findMany).toHaveBeenCalled();
|
|
expect(result).toHaveLength(1);
|
|
});
|
|
|
|
it("should upsertScientificTerm", async () => {
|
|
mockPrisma.scientificTerm.upsert.mockResolvedValue({ key: "k", term: "t" });
|
|
const data = { term: "t", definition: "d", wikiId: "w" };
|
|
const result = await service.upsertScientificTerm("k", data);
|
|
expect(prisma.scientificTerm.upsert).toHaveBeenCalledWith({
|
|
where: { key: "k" },
|
|
update: { term: "t", definition: "d", wikiId: "w" },
|
|
create: { key: "k", term: "t", definition: "d", wikiId: "w" },
|
|
});
|
|
expect(result.term).toBe("t");
|
|
});
|
|
|
|
it("should deleteScientificTerm", async () => {
|
|
mockPrisma.scientificTerm.delete.mockResolvedValue({ key: "k" });
|
|
const result = await service.deleteScientificTerm("k");
|
|
expect(prisma.scientificTerm.delete).toHaveBeenCalledWith({
|
|
where: { key: "k" },
|
|
});
|
|
expect(result.key).toBe("k");
|
|
});
|
|
});
|