122 lines
3.4 KiB
JavaScript
122 lines
3.4 KiB
JavaScript
|
|
const { PrismaClient } = require("@prisma/client");
|
||
|
|
|
||
|
|
const prisma = new PrismaClient();
|
||
|
|
|
||
|
|
async function testTemplateCreation() {
|
||
|
|
console.log("🧪 템플릿 생성 테스트 시작...");
|
||
|
|
|
||
|
|
try {
|
||
|
|
// 1. 테이블 존재 여부 확인
|
||
|
|
console.log("1. 템플릿 테이블 존재 여부 확인 중...");
|
||
|
|
|
||
|
|
try {
|
||
|
|
const count = await prisma.template_standards.count();
|
||
|
|
console.log(`✅ template_standards 테이블 발견 (현재 ${count}개 레코드)`);
|
||
|
|
} catch (error) {
|
||
|
|
if (error.code === "P2021") {
|
||
|
|
console.log("❌ template_standards 테이블이 존재하지 않습니다.");
|
||
|
|
console.log("👉 데이터베이스 마이그레이션이 필요합니다.");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
throw error;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 2. 샘플 템플릿 생성 테스트
|
||
|
|
console.log("2. 샘플 템플릿 생성 중...");
|
||
|
|
|
||
|
|
const sampleTemplate = {
|
||
|
|
template_code: "test-button-" + Date.now(),
|
||
|
|
template_name: "테스트 버튼",
|
||
|
|
template_name_eng: "Test Button",
|
||
|
|
description: "테스트용 버튼 템플릿",
|
||
|
|
category: "button",
|
||
|
|
icon_name: "mouse-pointer",
|
||
|
|
default_size: {
|
||
|
|
width: 80,
|
||
|
|
height: 36,
|
||
|
|
},
|
||
|
|
layout_config: {
|
||
|
|
components: [
|
||
|
|
{
|
||
|
|
type: "widget",
|
||
|
|
widgetType: "button",
|
||
|
|
label: "테스트 버튼",
|
||
|
|
position: { x: 0, y: 0 },
|
||
|
|
size: { width: 80, height: 36 },
|
||
|
|
style: {
|
||
|
|
backgroundColor: "#3b82f6",
|
||
|
|
color: "#ffffff",
|
||
|
|
border: "none",
|
||
|
|
borderRadius: "6px",
|
||
|
|
},
|
||
|
|
},
|
||
|
|
],
|
||
|
|
},
|
||
|
|
sort_order: 999,
|
||
|
|
is_active: "Y",
|
||
|
|
is_public: "Y",
|
||
|
|
company_code: "*",
|
||
|
|
created_by: "test",
|
||
|
|
updated_by: "test",
|
||
|
|
};
|
||
|
|
|
||
|
|
const created = await prisma.template_standards.create({
|
||
|
|
data: sampleTemplate,
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log("✅ 샘플 템플릿 생성 성공:", created.template_code);
|
||
|
|
|
||
|
|
// 3. 생성된 템플릿 조회 테스트
|
||
|
|
console.log("3. 템플릿 조회 테스트 중...");
|
||
|
|
|
||
|
|
const retrieved = await prisma.template_standards.findUnique({
|
||
|
|
where: { template_code: created.template_code },
|
||
|
|
});
|
||
|
|
|
||
|
|
if (retrieved) {
|
||
|
|
console.log("✅ 템플릿 조회 성공:", retrieved.template_name);
|
||
|
|
console.log(
|
||
|
|
"📄 Layout Config:",
|
||
|
|
JSON.stringify(retrieved.layout_config, null, 2)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 4. 카테고리 목록 조회 테스트
|
||
|
|
console.log("4. 카테고리 목록 조회 테스트 중...");
|
||
|
|
|
||
|
|
const categories = await prisma.template_standards.findMany({
|
||
|
|
where: { is_active: "Y" },
|
||
|
|
select: { category: true },
|
||
|
|
distinct: ["category"],
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log(
|
||
|
|
"✅ 발견된 카테고리:",
|
||
|
|
categories.map((c) => c.category)
|
||
|
|
);
|
||
|
|
|
||
|
|
// 5. 테스트 데이터 정리
|
||
|
|
console.log("5. 테스트 데이터 정리 중...");
|
||
|
|
|
||
|
|
await prisma.template_standards.delete({
|
||
|
|
where: { template_code: created.template_code },
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log("✅ 테스트 데이터 정리 완료");
|
||
|
|
|
||
|
|
console.log("🎉 모든 테스트 통과!");
|
||
|
|
} catch (error) {
|
||
|
|
console.error("❌ 테스트 실패:", error);
|
||
|
|
console.error("📋 상세 정보:", {
|
||
|
|
message: error.message,
|
||
|
|
code: error.code,
|
||
|
|
stack: error.stack?.split("\n").slice(0, 5),
|
||
|
|
});
|
||
|
|
} finally {
|
||
|
|
await prisma.$disconnect();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 스크립트 실행
|
||
|
|
testTemplateCreation();
|