| Server IP : 65.108.144.40 / Your IP : 216.73.217.165 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 User : dev ( 1000) PHP Version : 8.2.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/dev/aipossible/aipossible-server/test/ |
Upload File : |
import { Test, TestingModule } from "@nestjs/testing";
import { INestApplication } from "@nestjs/common";
import request from "supertest";
import { AppModule } from "../src/app.module";
import { PrismaService } from "../src/common/prisma/prisma.service";
import { BlockType } from "../src/authoring/types";
import { AuthGuard } from "@nestjs/passport";
describe("ModulesController (e2e)", () => {
let app: INestApplication;
let prisma: PrismaService;
const testModuleCode = "TEST_DELIVERY_100";
beforeAll(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
})
.overrideGuard(AuthGuard("jwt"))
.useValue({ canActivate: () => true })
.compile();
app = moduleFixture.createNestApplication();
await app.init();
prisma = app.get<PrismaService>(PrismaService);
// Setup: Create a module with a quiz block containing correct answers
// Ensure cleanup first
await prisma.contentBlock.deleteMany({
where: { section: { module: { code: testModuleCode } } },
});
await prisma.moduleSection.deleteMany({
where: { module: { code: testModuleCode } },
});
await prisma.module.deleteMany({ where: { code: testModuleCode } });
const module = await prisma.module.create({
data: {
code: testModuleCode,
title: "Test Delivery Module",
isPublished: true,
},
});
const section = await prisma.moduleSection.create({
data: {
moduleId: module.id,
title: "Section 1",
order: 1,
},
});
// Create a QUIZ block via Prisma directly (simulating ingestion)
const quizPayload = {
question: "What is 2+2?",
choices: [
{ id: "a", text: "3", isCorrect: false },
{ id: "b", text: "4", isCorrect: true, feedback: "Correct!" },
],
explanation: "Simple math.",
};
await prisma.contentBlock.create({
data: {
sectionId: section.id,
type: BlockType.QUIZ,
order: 1,
payload: quizPayload,
},
});
});
afterAll(async () => {
// Cleanup
const module = await prisma.module.findUnique({
where: { code: testModuleCode },
});
if (module) {
await prisma.contentBlock.deleteMany({
where: { section: { module: { code: testModuleCode } } },
});
await prisma.moduleSection.deleteMany({
where: { module: { code: testModuleCode } },
});
await prisma.module.delete({ where: { code: testModuleCode } });
}
await app.close();
});
it("/modules/:code (GET) - Should return sanitized content", async () => {
const res = await request(app.getHttpServer())
.get(`/modules/${testModuleCode}`)
.expect(200);
const moduleData = res.body;
expect(moduleData.code).toBe(testModuleCode);
const quizBlock = moduleData.sections[0].blocks[0];
expect(quizBlock.type).toBe(BlockType.QUIZ);
// Check sanitization
const choices = quizBlock.payload.choices;
expect(choices).toHaveLength(2);
expect(choices[0]).not.toHaveProperty("isCorrect");
expect(choices[1]).not.toHaveProperty("isCorrect");
expect(choices[1]).not.toHaveProperty("feedback"); // Should be removed
expect(quizBlock.payload).not.toHaveProperty("explanation");
});
});