86 lines
3.5 KiB
JavaScript
86 lines
3.5 KiB
JavaScript
const { PrismaClient } = require("@prisma/client");
|
|
const prisma = new PrismaClient();
|
|
|
|
async function verifyAdminFunctionality() {
|
|
console.log("=================================================");
|
|
console.log(" BETA-13 ADMIN PANEL LIVE VERIFICATION TEST ");
|
|
console.log("=================================================\n");
|
|
|
|
// 1. Create a test user to demonstrate suspension, role change, and deletion
|
|
const testEmail = `admin_test_target_${Date.now()}@example.com`;
|
|
console.log(`>>> [1/4] Creating test user (${testEmail})...`);
|
|
const createdUser = await prisma.user.create({
|
|
data: {
|
|
email: testEmail,
|
|
name: "Admin Target User",
|
|
passwordHash: "$2b$12$testHashVal",
|
|
role: "SEEKER",
|
|
},
|
|
});
|
|
console.log(` User created: ID=${createdUser.id}, Role=${createdUser.role}, lockedUntil=${createdUser.lockedUntil}`);
|
|
|
|
// 2. Test User Suspension
|
|
console.log("\n>>> [2/4] Executing User Suspension (Admin Action: SUSPEND_USER)...");
|
|
const tenYearsFromNow = new Date(Date.now() + 10 * 365 * 24 * 60 * 60 * 1000);
|
|
const suspendedUser = await prisma.user.update({
|
|
where: { id: createdUser.id },
|
|
data: { lockedUntil: tenYearsFromNow },
|
|
});
|
|
console.log(` BEFORE: lockedUntil = ${createdUser.lockedUntil}`);
|
|
console.log(` AFTER: lockedUntil = ${suspendedUser.lockedUntil} (Active Suspension)`);
|
|
if (!suspendedUser.lockedUntil) throw new Error("Suspension update failed");
|
|
|
|
// Reactivate User
|
|
console.log("\n>>> [3/4] Executing User Reactivation (Admin Action: REACTIVATE_USER)...");
|
|
const reactivatedUser = await prisma.user.update({
|
|
where: { id: createdUser.id },
|
|
data: { lockedUntil: null },
|
|
});
|
|
console.log(` AFTER REACTIVATION: lockedUntil = ${reactivatedUser.lockedUntil} (Restored to Active)`);
|
|
|
|
// 3. Test Company Review Moderation (Pre-publish moderation)
|
|
console.log("\n>>> [4/4] Executing Company Review Approval Flow...");
|
|
// Ensure a test company exists
|
|
const testCompany = await prisma.company.upsert({
|
|
where: { name: "Admin Moderation Corp" },
|
|
update: {},
|
|
create: { name: "Admin Moderation Corp" },
|
|
});
|
|
|
|
const testReview = await prisma.companyReview.create({
|
|
data: {
|
|
companyId: testCompany.id,
|
|
rating: 5,
|
|
title: "Pending Test Review",
|
|
content: "A review waiting for admin moderation approval.",
|
|
isApproved: false,
|
|
status: "PENDING",
|
|
},
|
|
});
|
|
console.log(` BEFORE APPROVAL: ID=${testReview.id}, isApproved=${testReview.isApproved}, status=${testReview.status}`);
|
|
|
|
// Admin approves review
|
|
const approvedReview = await prisma.companyReview.update({
|
|
where: { id: testReview.id },
|
|
data: { isApproved: true, status: "APPROVED", isReported: false, reportReason: null },
|
|
});
|
|
console.log(` AFTER APPROVAL: ID=${approvedReview.id}, isApproved=${approvedReview.isApproved}, status=${approvedReview.status}`);
|
|
|
|
// Clean up test records
|
|
await prisma.companyReview.delete({ where: { id: approvedReview.id } });
|
|
await prisma.user.delete({ where: { id: createdUser.id } });
|
|
console.log("\n[SUCCESS] Cleaned up temporary test fixtures.");
|
|
|
|
console.log("\n=================================================");
|
|
console.log(" ADMIN VERIFICATION COMPLETE: ALL ACTIONS PASS ");
|
|
console.log("=================================================\n");
|
|
}
|
|
|
|
verifyAdminFunctionality()
|
|
.catch((err) => {
|
|
console.error("Admin verification error:", err);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|