@isnow890/naver-search-mcp 1.0.19 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/index.js +66 -103
- package/package.json +6 -9
- package/dist/package.json +0 -43
- package/dist/src/handlers/unified-search.handlers.js +0 -144
- package/dist/src/schemas/unified-search.schemas.js +0 -70
- package/dist/src/tools/unified-search.tools.js +0 -14
- package/dist/tests/unified-search.handlers.test.js +0 -194
- package/dist/tests/unified-search.schemas.test.js +0 -187
- package/dist/tests/unified-search.tools.test.js +0 -38
package/dist/src/index.js
CHANGED
|
@@ -1,109 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import pkg from "../package.json" with { type: "json" };
|
|
4
|
-
console.error("[MCP] dotenv import 완료");
|
|
5
|
-
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
6
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
7
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
8
3
|
import { NaverSearchClient } from "./clients/naver-search.client.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (!NAVER_CLIENT_ID || !NAVER_CLIENT_SECRET) {
|
|
18
|
-
console.error("[MCP] Error: NAVER_CLIENT_ID and NAVER_CLIENT_SECRET environment variables are required");
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
// 네이버 검색 클라이언트 초기화
|
|
22
|
-
const client = NaverSearchClient.getInstance();
|
|
23
|
-
client.initialize({
|
|
24
|
-
clientId: NAVER_CLIENT_ID,
|
|
25
|
-
clientSecret: NAVER_CLIENT_SECRET,
|
|
26
|
-
});
|
|
27
|
-
console.error("[MCP] NaverSearchClient 초기화 완료");
|
|
28
|
-
// MCP 서버 인스턴스 생성
|
|
29
|
-
const server = new Server({
|
|
30
|
-
name: "naver-search",
|
|
31
|
-
version: pkg.version,
|
|
32
|
-
}, {
|
|
33
|
-
capabilities: {
|
|
34
|
-
tools: {},
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
console.error("[MCP] Server 인스턴스 생성 완료");
|
|
38
|
-
// 도구 목록을 반환하는 핸들러 등록
|
|
39
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
40
|
-
console.error("[MCP] ListToolsRequestSchema 핸들러 호출됨");
|
|
41
|
-
return {
|
|
42
|
-
tools: [
|
|
43
|
-
//...searchTools,
|
|
44
|
-
// // ...datalabTools,
|
|
45
|
-
...unifiedSearchTools
|
|
46
|
-
],
|
|
47
|
-
};
|
|
4
|
+
import { searchTools } from "./tools/search.tools.js";
|
|
5
|
+
import { datalabTools } from "./tools/datalab.tools.js";
|
|
6
|
+
import { searchToolHandlers } from "./handlers/search.handlers.js";
|
|
7
|
+
import { datalabToolHandlers } from "./handlers/datalab.handlers.js";
|
|
8
|
+
// Configuration schema for Smithery
|
|
9
|
+
export const configSchema = z.object({
|
|
10
|
+
NAVER_CLIENT_ID: z.string().describe("Naver API Client ID"),
|
|
11
|
+
NAVER_CLIENT_SECRET: z.string().describe("Naver API Client Secret")
|
|
48
12
|
});
|
|
49
|
-
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
13
|
+
export default function ({ config }) {
|
|
14
|
+
// Create a new MCP server per MCP spec
|
|
15
|
+
const server = new McpServer({
|
|
16
|
+
name: "naver-search",
|
|
17
|
+
version: "1.0.18",
|
|
18
|
+
});
|
|
19
|
+
// Initialize Naver client with config
|
|
20
|
+
const client = NaverSearchClient.getInstance();
|
|
21
|
+
client.initialize({
|
|
22
|
+
clientId: config.NAVER_CLIENT_ID,
|
|
23
|
+
clientSecret: config.NAVER_CLIENT_SECRET,
|
|
24
|
+
});
|
|
25
|
+
const toolHandlers = {
|
|
26
|
+
...searchToolHandlers,
|
|
27
|
+
...datalabToolHandlers,
|
|
61
28
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
server.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return createErrorResponse(error);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
// 서버 시작 함수
|
|
85
|
-
async function runServer() {
|
|
86
|
-
try {
|
|
87
|
-
console.error("[MCP] runServer 진입");
|
|
88
|
-
const transport = new StdioServerTransport();
|
|
89
|
-
// 서버 에러 핸들링
|
|
90
|
-
process.on("uncaughtException", (error) => {
|
|
91
|
-
console.error("[MCP] Uncaught Exception:", error);
|
|
29
|
+
// Add all search tools
|
|
30
|
+
searchTools.forEach(tool => {
|
|
31
|
+
server.tool(tool.name, tool.description, tool.inputSchema, async (args) => {
|
|
32
|
+
try {
|
|
33
|
+
const handler = toolHandlers[tool.name];
|
|
34
|
+
if (!handler)
|
|
35
|
+
throw new Error(`Unknown tool: ${tool.name}`);
|
|
36
|
+
const result = await handler(args);
|
|
37
|
+
return {
|
|
38
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
43
|
+
return {
|
|
44
|
+
content: [{ type: "text", text: `Error: ${errorMessage}` }],
|
|
45
|
+
isError: true,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
92
48
|
});
|
|
93
|
-
|
|
94
|
-
|
|
49
|
+
});
|
|
50
|
+
// Add all datalab tools
|
|
51
|
+
datalabTools.forEach(tool => {
|
|
52
|
+
server.tool(tool.name, tool.description, tool.inputSchema, async (args) => {
|
|
53
|
+
try {
|
|
54
|
+
const handler = toolHandlers[tool.name];
|
|
55
|
+
if (!handler)
|
|
56
|
+
throw new Error(`Unknown tool: ${tool.name}`);
|
|
57
|
+
const result = await handler(args);
|
|
58
|
+
return {
|
|
59
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
64
|
+
return {
|
|
65
|
+
content: [{ type: "text", text: `Error: ${errorMessage}` }],
|
|
66
|
+
isError: true,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
95
69
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
console.error("[MCP] Fatal error running server:", error);
|
|
101
|
-
process.exit(1);
|
|
102
|
-
}
|
|
70
|
+
});
|
|
71
|
+
return server.server;
|
|
103
72
|
}
|
|
104
|
-
// 서버 시작
|
|
105
|
-
console.error("[MCP] runServer 호출 직전");
|
|
106
|
-
runServer().catch((error) => {
|
|
107
|
-
console.error("[MCP] Fatal error running server (catch):", error);
|
|
108
|
-
process.exit(1);
|
|
109
|
-
});
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isnow890/naver-search-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "Naver Search MCP Server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "./src/index.ts",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"files": [
|
|
8
9
|
"dist"
|
|
@@ -12,8 +13,7 @@
|
|
|
12
13
|
"build": "tsc",
|
|
13
14
|
"prepare": "npm run build",
|
|
14
15
|
"watch": "tsc --watch",
|
|
15
|
-
"start": "node dist/src/index.js"
|
|
16
|
-
"test": "npx cross-env NODE_OPTIONS=--experimental-vm-modules npx jest"
|
|
16
|
+
"start": "node dist/src/index.js"
|
|
17
17
|
},
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=18"
|
|
@@ -21,17 +21,14 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@modelcontextprotocol/sdk": "1.10.2",
|
|
23
23
|
"axios": "^1.6.7",
|
|
24
|
-
"dotenv": "^16.4.5",
|
|
25
|
-
"sharp": "^0.33.2",
|
|
26
24
|
"zod": "^3.22.4",
|
|
27
|
-
"zod-to-json-schema": "^3.23.5"
|
|
25
|
+
"zod-to-json-schema": "^3.23.5",
|
|
26
|
+
"sharp": "^0.33.2",
|
|
27
|
+
"dotenv": "^16.4.5"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/jest": "^29.5.14",
|
|
31
30
|
"@types/node": "^22",
|
|
32
|
-
"jest": "^29.7.0",
|
|
33
31
|
"shx": "^0.3.4",
|
|
34
|
-
"ts-jest": "^29.3.2",
|
|
35
32
|
"typescript": "^5.3.3"
|
|
36
33
|
},
|
|
37
34
|
"author": "isnow890",
|
package/dist/package.json
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@isnow890/naver-search-mcp",
|
|
3
|
-
"version": "1.0.19",
|
|
4
|
-
"description": "Naver Search MCP Server",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"prebuild": "shx rm -rf dist",
|
|
12
|
-
"build": "tsc",
|
|
13
|
-
"prepare": "npm run build",
|
|
14
|
-
"watch": "tsc --watch",
|
|
15
|
-
"start": "node dist/src/index.js",
|
|
16
|
-
"test": "npx cross-env NODE_OPTIONS=--experimental-vm-modules npx jest"
|
|
17
|
-
},
|
|
18
|
-
"engines": {
|
|
19
|
-
"node": ">=18"
|
|
20
|
-
},
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@modelcontextprotocol/sdk": "1.10.2",
|
|
23
|
-
"axios": "^1.6.7",
|
|
24
|
-
"dotenv": "^16.4.5",
|
|
25
|
-
"sharp": "^0.33.2",
|
|
26
|
-
"zod": "^3.22.4",
|
|
27
|
-
"zod-to-json-schema": "^3.23.5"
|
|
28
|
-
},
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"@types/jest": "^29.5.14",
|
|
31
|
-
"@types/node": "^22",
|
|
32
|
-
"jest": "^29.7.0",
|
|
33
|
-
"shx": "^0.3.4",
|
|
34
|
-
"ts-jest": "^29.3.2",
|
|
35
|
-
"typescript": "^5.3.3"
|
|
36
|
-
},
|
|
37
|
-
"author": "isnow890",
|
|
38
|
-
"license": "MIT",
|
|
39
|
-
"bin": {
|
|
40
|
-
"naver-search-mcp": "dist/src/index.js"
|
|
41
|
-
},
|
|
42
|
-
"type": "module"
|
|
43
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { searchToolHandlers } from "./search.handlers.js";
|
|
2
|
-
import { datalabToolHandlers } from "./datalab.handlers.js";
|
|
3
|
-
import { UnifiedSearchSchema } from "../schemas/unified-search.schemas.js";
|
|
4
|
-
/**
|
|
5
|
-
* 통합 검색 핸들러
|
|
6
|
-
* 일반 검색과 트렌드 검색을 통합하여 처리
|
|
7
|
-
* @param args 통합 검색 파라미터
|
|
8
|
-
* @returns 검색 결과
|
|
9
|
-
*/
|
|
10
|
-
export async function handleUnifiedSearch(args) {
|
|
11
|
-
// Zod를 사용하여 입력 파라미터 검증
|
|
12
|
-
const parsedArgs = UnifiedSearchSchema.parse(args);
|
|
13
|
-
// 검색 유형에 따라 처리
|
|
14
|
-
if (parsedArgs.searchType === "general") {
|
|
15
|
-
return handleGeneralSearch(parsedArgs);
|
|
16
|
-
}
|
|
17
|
-
else if (parsedArgs.searchType === "trend") {
|
|
18
|
-
return handleTrendSearch(parsedArgs);
|
|
19
|
-
}
|
|
20
|
-
throw new Error("지원하지 않는 검색 유형입니다.");
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 일반 검색 핸들러
|
|
24
|
-
* @param search 일반 검색 파라미터
|
|
25
|
-
* @returns 검색 결과
|
|
26
|
-
*/
|
|
27
|
-
async function handleGeneralSearch(search) {
|
|
28
|
-
const { generalType, params } = search;
|
|
29
|
-
// 모든 검색 타입을 통합하여 검색하는 경우
|
|
30
|
-
if (generalType === "all") {
|
|
31
|
-
return handleAllGeneralSearch(params);
|
|
32
|
-
}
|
|
33
|
-
// 단일 검색 유형인 경우
|
|
34
|
-
const handlerKey = `search_${generalType}`;
|
|
35
|
-
const handler = searchToolHandlers[handlerKey];
|
|
36
|
-
if (!handler) {
|
|
37
|
-
throw new Error(`'${generalType}' 유형에 대한 검색 핸들러가 없습니다.`);
|
|
38
|
-
}
|
|
39
|
-
return handler(params);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* 모든 일반 검색을 병렬로 수행하는 핸들러
|
|
43
|
-
* @param params 검색 파라미터
|
|
44
|
-
* @returns 모든 검색 결과 (검색 유형별로 객체 키 할당)
|
|
45
|
-
*/
|
|
46
|
-
async function handleAllGeneralSearch(params) {
|
|
47
|
-
// 모든 가능한 일반 검색 타입 (local과 다른 타입은 파라미터가 다르므로 주의)
|
|
48
|
-
// 검색할 타입 목록 (local은 파라미터가 다르므로 처리 방식 구분)
|
|
49
|
-
const generalTypes = [
|
|
50
|
-
"webkr", "news", "blog", "shop", "image",
|
|
51
|
-
"kin", "book", "encyc", "academic", "cafearticle"
|
|
52
|
-
];
|
|
53
|
-
// Promise 배열 생성 및 결과 수집
|
|
54
|
-
const searchPromises = generalTypes.map(type => {
|
|
55
|
-
const handlerKey = `search_${type}`;
|
|
56
|
-
const handler = searchToolHandlers[handlerKey];
|
|
57
|
-
return handler(params)
|
|
58
|
-
.then(result => ({ type, result }))
|
|
59
|
-
.catch(error => ({ type, error: error.message }));
|
|
60
|
-
});
|
|
61
|
-
// local 검색은 파라미터가 다르지만 동일 인터페이스로 처리
|
|
62
|
-
const localHandler = searchToolHandlers["search_local"];
|
|
63
|
-
searchPromises.push(localHandler(params)
|
|
64
|
-
.then(result => ({ type: "local", result }))
|
|
65
|
-
.catch(error => ({ type: "local", error: error.message })));
|
|
66
|
-
// 모든 검색 병렬 실행
|
|
67
|
-
const results = await Promise.all(searchPromises);
|
|
68
|
-
// 결과를 유형별로 객체로 변환
|
|
69
|
-
return results.reduce((acc, item) => {
|
|
70
|
-
const { type } = item;
|
|
71
|
-
if ('result' in item) {
|
|
72
|
-
acc[type] = item.result;
|
|
73
|
-
}
|
|
74
|
-
else if ('error' in item) {
|
|
75
|
-
acc[type] = { error: item.error };
|
|
76
|
-
}
|
|
77
|
-
return acc;
|
|
78
|
-
}, {});
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* 트렌드 검색 핸들러
|
|
82
|
-
* @param search 트렌드 검색 파라미터
|
|
83
|
-
* @returns 검색 결과
|
|
84
|
-
*/
|
|
85
|
-
async function handleTrendSearch(search) {
|
|
86
|
-
const { trendType, params } = search;
|
|
87
|
-
// 모든 트렌드 타입을 통합하여 검색하는 경우
|
|
88
|
-
if (trendType === "all") {
|
|
89
|
-
return handleAllTrendSearch(params);
|
|
90
|
-
}
|
|
91
|
-
// 단일 트렌드 검색 유형인 경우
|
|
92
|
-
const handlerKey = `datalab_${trendType}`;
|
|
93
|
-
const handler = datalabToolHandlers[handlerKey];
|
|
94
|
-
if (!handler) {
|
|
95
|
-
throw new Error(`'${trendType}' 유형에 대한 트렌드 검색 핸들러가 없습니다.`);
|
|
96
|
-
}
|
|
97
|
-
return handler(params);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* 모든 트렌드 검색을 병렬로 수행하는 핸들러
|
|
101
|
-
* @param params 트렌드 검색 파라미터
|
|
102
|
-
* @returns 모든 트렌드 검색 결과 (검색 유형별로 객체 키 할당)
|
|
103
|
-
*/
|
|
104
|
-
async function handleAllTrendSearch(params) {
|
|
105
|
-
// 파라미터 유형에 따라 가능한 트렌드 검색 타입 결정
|
|
106
|
-
const trendTypes = [
|
|
107
|
-
"search"
|
|
108
|
-
];
|
|
109
|
-
// 쇼핑 관련 트렌드는 category 파라미터가 있어야 함
|
|
110
|
-
if (params.category) {
|
|
111
|
-
trendTypes.push("shopping_category", "shopping_by_device", "shopping_by_gender", "shopping_by_age", "shopping_keywords");
|
|
112
|
-
// 키워드 관련 트렌드는 keyword 파라미터가 있어야 함
|
|
113
|
-
if (params.keyword) {
|
|
114
|
-
trendTypes.push("shopping_keyword_by_device", "shopping_keyword_by_gender", "shopping_keyword_by_age");
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// Promise 배열 생성 및 결과 수집
|
|
118
|
-
const trendPromises = trendTypes.map(type => {
|
|
119
|
-
const handlerKey = `datalab_${type}`;
|
|
120
|
-
const handler = datalabToolHandlers[handlerKey];
|
|
121
|
-
// 일부 트렌드 검색은 파라미터 형식이 다를 수 있으므로
|
|
122
|
-
// 에러가 발생해도 다른 검색은 계속 진행하도록 처리
|
|
123
|
-
return handler(params)
|
|
124
|
-
.then((result) => ({ type, result }))
|
|
125
|
-
.catch((error) => ({ type, error: error.message }));
|
|
126
|
-
});
|
|
127
|
-
// 모든 트렌드 검색 병렬 실행
|
|
128
|
-
const results = await Promise.all(trendPromises);
|
|
129
|
-
// 결과를 유형별로 객체로 변환
|
|
130
|
-
return results.reduce((acc, item) => {
|
|
131
|
-
const { type } = item;
|
|
132
|
-
if ('result' in item) {
|
|
133
|
-
acc[type] = item.result;
|
|
134
|
-
}
|
|
135
|
-
else if ('error' in item) {
|
|
136
|
-
acc[type] = { error: item.error };
|
|
137
|
-
}
|
|
138
|
-
return acc;
|
|
139
|
-
}, {});
|
|
140
|
-
}
|
|
141
|
-
// 통합 검색 도구 핸들러 맵
|
|
142
|
-
export const unifiedSearchToolHandlers = {
|
|
143
|
-
unified_search: (args) => handleUnifiedSearch(args)
|
|
144
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { SearchArgsSchema, NaverLocalSearchParamsSchema } from "./search.schemas.js";
|
|
3
|
-
import { DatalabSearchSchema, DatalabShoppingSchema, DatalabShoppingDeviceSchema, DatalabShoppingGenderSchema, DatalabShoppingAgeSchema, DatalabShoppingKeywordsSchema, DatalabShoppingKeywordDeviceSchema, DatalabShoppingKeywordGenderSchema, DatalabShoppingKeywordAgeSchema } from "./datalab.schemas.js";
|
|
4
|
-
// 통합 검색 유형 정의
|
|
5
|
-
export const UnifiedSearchTypeSchema = z.enum([
|
|
6
|
-
"general", // 일반 검색
|
|
7
|
-
"trend" // 트렌드 검색
|
|
8
|
-
]).describe("검색 방식 - general: 일반 검색, trend: 트렌드 분석");
|
|
9
|
-
// 일반 검색 유형 정의
|
|
10
|
-
export const GeneralSearchTypeSchema = z.enum([
|
|
11
|
-
"all", // 모든 검색
|
|
12
|
-
"webkr", // 웹문서
|
|
13
|
-
"news", // 뉴스
|
|
14
|
-
"blog", // 블로그
|
|
15
|
-
"shop", // 쇼핑
|
|
16
|
-
"image", // 이미지
|
|
17
|
-
"kin", // 지식iN
|
|
18
|
-
"book", // 책
|
|
19
|
-
"encyc", // 지식백과
|
|
20
|
-
"academic", // 전문자료
|
|
21
|
-
"local", // 지역
|
|
22
|
-
"cafearticle" // 카페글
|
|
23
|
-
]).describe("검색 카테고리 - all: 모든 카테고리 통합 검색, webkr: 웹문서, news: 뉴스, blog: 블로그, shop: 쇼핑, image: 이미지, kin: 지식iN, book: 책, encyc: 지식백과, academic: 전문자료, local: 지역, cafearticle: 카페글");
|
|
24
|
-
// 트렌드 검색 유형 정의
|
|
25
|
-
export const TrendSearchTypeSchema = z.enum([
|
|
26
|
-
"all", // 모든 트렌드 검색
|
|
27
|
-
"search", // 검색어 트렌드
|
|
28
|
-
"shopping_category", // 쇼핑 카테고리별 트렌드
|
|
29
|
-
"shopping_by_device", // 쇼핑 기기별 트렌드
|
|
30
|
-
"shopping_by_gender", // 쇼핑 성별 트렌드
|
|
31
|
-
"shopping_by_age", // 쇼핑 연령별 트렌드
|
|
32
|
-
"shopping_keywords", // 쇼핑 키워드별 트렌드
|
|
33
|
-
"shopping_keyword_by_device", // 쇼핑 키워드 기기별 트렌드
|
|
34
|
-
"shopping_keyword_by_gender", // 쇼핑 키워드 성별 트렌드
|
|
35
|
-
"shopping_keyword_by_age" // 쇼핑 키워드 연령별 트렌드
|
|
36
|
-
]).describe("트렌드 분석 유형 - all: 모든 트렌드 통합 검색, search: 일반 검색어 트렌드, shopping_category: 쇼핑 카테고리별 트렌드, shopping_by_device: 쇼핑 기기별(PC/모바일) 트렌드, shopping_by_gender: 쇼핑 성별 트렌드, shopping_by_age: 쇼핑 연령별 트렌드, shopping_keywords: 쇼핑 키워드별 트렌드, shopping_keyword_by_device: 쇼핑 키워드 기기별 트렌드, shopping_keyword_by_gender: 쇼핑 키워드 성별 트렌드, shopping_keyword_by_age: 쇼핑 키워드 연령별 트렌드");
|
|
37
|
-
// 통합 검색 베이스 스키마
|
|
38
|
-
export const UnifiedSearchBaseSchema = z.object({
|
|
39
|
-
searchType: UnifiedSearchTypeSchema.describe("검색 유형 (일반/트렌드)"),
|
|
40
|
-
});
|
|
41
|
-
// 일반 검색 스키마
|
|
42
|
-
export const GeneralSearchSchema = UnifiedSearchBaseSchema.extend({
|
|
43
|
-
searchType: z.literal("general"),
|
|
44
|
-
generalType: GeneralSearchTypeSchema.describe("일반 검색 유형"),
|
|
45
|
-
params: z.union([
|
|
46
|
-
SearchArgsSchema,
|
|
47
|
-
NaverLocalSearchParamsSchema
|
|
48
|
-
]).describe("검색 매개변수")
|
|
49
|
-
});
|
|
50
|
-
// 트렌드 검색 스키마
|
|
51
|
-
export const TrendSearchSchema = UnifiedSearchBaseSchema.extend({
|
|
52
|
-
searchType: z.literal("trend"),
|
|
53
|
-
trendType: TrendSearchTypeSchema.describe("트렌드 검색 유형"),
|
|
54
|
-
params: z.union([
|
|
55
|
-
DatalabSearchSchema,
|
|
56
|
-
DatalabShoppingSchema,
|
|
57
|
-
DatalabShoppingDeviceSchema,
|
|
58
|
-
DatalabShoppingGenderSchema,
|
|
59
|
-
DatalabShoppingAgeSchema,
|
|
60
|
-
DatalabShoppingKeywordsSchema,
|
|
61
|
-
DatalabShoppingKeywordDeviceSchema,
|
|
62
|
-
DatalabShoppingKeywordGenderSchema,
|
|
63
|
-
DatalabShoppingKeywordAgeSchema
|
|
64
|
-
]).describe("트렌드 검색 매개변수")
|
|
65
|
-
});
|
|
66
|
-
// 통합 검색 스키마
|
|
67
|
-
export const UnifiedSearchSchema = z.union([
|
|
68
|
-
GeneralSearchSchema,
|
|
69
|
-
TrendSearchSchema
|
|
70
|
-
]);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
|
-
import { UnifiedSearchSchema } from "../schemas/unified-search.schemas.js";
|
|
3
|
-
/**
|
|
4
|
-
* 통합 검색 도구
|
|
5
|
-
* 일반 검색과 트렌드 검색을 통합해 하나의 인터페이스로 제공
|
|
6
|
-
* 'all' 옵션을 사용하면 여러 검색을 병렬로 처리하여 모든 결과를 한 번에 반환
|
|
7
|
-
*/
|
|
8
|
-
export const unifiedSearchTools = [
|
|
9
|
-
{
|
|
10
|
-
name: "unified_search",
|
|
11
|
-
description: "Perform a unified search for either general content or trend analysis. Use 'all' for generalType or trendType to search across all categories in parallel. (일반 콘텐츠 검색 또는 트렌드 분석을 위한 통합 검색. generalType 또는 trendType에 'all'을 사용하면 모든 카테고리를 병렬로 검색 가능)",
|
|
12
|
-
inputSchema: zodToJsonSchema(UnifiedSearchSchema),
|
|
13
|
-
}
|
|
14
|
-
];
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* unified-search.handlers.test.ts
|
|
3
|
-
*
|
|
4
|
-
* 통합 검색 핸들러에 대한 테스트
|
|
5
|
-
*/
|
|
6
|
-
import { handleUnifiedSearch } from '../src/handlers/unified-search.handlers.js';
|
|
7
|
-
import { NaverSearchClient } from '../src/clients/naver-search.client.js';
|
|
8
|
-
// NaverSearchClient 모킹
|
|
9
|
-
jest.mock('../src/clients/naver-search.client.js', () => {
|
|
10
|
-
const mockInstance = {
|
|
11
|
-
search: jest.fn(),
|
|
12
|
-
searchAcademic: jest.fn(),
|
|
13
|
-
searchLocal: jest.fn(),
|
|
14
|
-
searchTrend: jest.fn(),
|
|
15
|
-
datalabShoppingCategory: jest.fn(),
|
|
16
|
-
datalabShoppingByDevice: jest.fn(),
|
|
17
|
-
datalabShoppingByGender: jest.fn(),
|
|
18
|
-
datalabShoppingByAge: jest.fn(),
|
|
19
|
-
datalabShoppingKeywords: jest.fn(),
|
|
20
|
-
datalabShoppingKeywordByDevice: jest.fn(),
|
|
21
|
-
datalabShoppingKeywordByGender: jest.fn(),
|
|
22
|
-
datalabShoppingKeywordByAge: jest.fn(),
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
getInstance: jest.fn(() => mockInstance),
|
|
26
|
-
__mockInstance: mockInstance
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
// 테스트 전에 모든 모의 함수 초기화
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
jest.clearAllMocks();
|
|
32
|
-
});
|
|
33
|
-
// 모킹된 클라이언트 인스턴스 가져오기
|
|
34
|
-
const mockClient = NaverSearchClient.getInstance().__mockInstance;
|
|
35
|
-
describe('Unified Search Handlers', () => {
|
|
36
|
-
describe('handleUnifiedSearch - General Search', () => {
|
|
37
|
-
it('일반 검색 - 단일 유형(webkr)을 처리한다', async () => {
|
|
38
|
-
// 모의 응답 설정
|
|
39
|
-
const mockResponse = { items: [{ title: '테스트 결과' }] };
|
|
40
|
-
mockClient.search.mockResolvedValue(mockResponse);
|
|
41
|
-
// 테스트 호출
|
|
42
|
-
const result = await handleUnifiedSearch({
|
|
43
|
-
searchType: 'general',
|
|
44
|
-
generalType: 'webkr',
|
|
45
|
-
params: {
|
|
46
|
-
query: '테스트 검색어',
|
|
47
|
-
display: 10,
|
|
48
|
-
sort: 'sim'
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
// 검증
|
|
52
|
-
expect(mockClient.search).toHaveBeenCalledWith('webkr', {
|
|
53
|
-
query: '테스트 검색어',
|
|
54
|
-
display: 10,
|
|
55
|
-
sort: 'sim'
|
|
56
|
-
});
|
|
57
|
-
expect(result).toEqual(mockResponse);
|
|
58
|
-
});
|
|
59
|
-
it('일반 검색 - 모든 유형(all)을 병렬 처리한다', async () => {
|
|
60
|
-
const mockWebkrResponse = { items: [{ title: '웹문서 결과' }] };
|
|
61
|
-
const mockNewsResponse = { items: [{ title: '뉴스 결과' }] };
|
|
62
|
-
const mockBlogResponse = { items: [{ title: '블로그 결과' }] };
|
|
63
|
-
mockClient.search.mockImplementation((type, params) => {
|
|
64
|
-
switch (type) {
|
|
65
|
-
case 'webkr': return Promise.resolve(mockWebkrResponse);
|
|
66
|
-
case 'news': return Promise.resolve(mockNewsResponse);
|
|
67
|
-
case 'blog': return Promise.resolve(mockBlogResponse);
|
|
68
|
-
default: return Promise.resolve({ items: [] });
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
mockClient.searchLocal.mockResolvedValue({ items: [{ title: '지역 결과' }] });
|
|
72
|
-
mockClient.searchAcademic.mockResolvedValue({ items: [{ title: '전문자료 결과' }] });
|
|
73
|
-
// 테스트 호출
|
|
74
|
-
const result = await handleUnifiedSearch({
|
|
75
|
-
searchType: 'general',
|
|
76
|
-
generalType: 'all',
|
|
77
|
-
params: {
|
|
78
|
-
query: '통합 검색어',
|
|
79
|
-
display: 5,
|
|
80
|
-
sort: 'sim'
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
// 검증
|
|
84
|
-
expect(mockClient.search).toHaveBeenCalled();
|
|
85
|
-
expect(mockClient.searchLocal).toHaveBeenCalled();
|
|
86
|
-
expect(result).toHaveProperty('webkr');
|
|
87
|
-
expect(result).toHaveProperty('news');
|
|
88
|
-
expect(result).toHaveProperty('blog');
|
|
89
|
-
expect(result).toHaveProperty('local');
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
describe('handleUnifiedSearch - Trend Search', () => {
|
|
93
|
-
it('트렌드 검색 - 단일 유형(search)을 처리한다', async () => {
|
|
94
|
-
// 모의 응답 설정
|
|
95
|
-
const mockResponse = { results: [{ data: [{ period: '2023-01-01', ratio: 100 }] }] };
|
|
96
|
-
mockClient.searchTrend.mockResolvedValue(mockResponse);
|
|
97
|
-
// 테스트 호출
|
|
98
|
-
const result = await handleUnifiedSearch({
|
|
99
|
-
searchType: 'trend',
|
|
100
|
-
trendType: 'search',
|
|
101
|
-
params: {
|
|
102
|
-
startDate: '2023-01-01',
|
|
103
|
-
endDate: '2023-01-31',
|
|
104
|
-
timeUnit: 'date',
|
|
105
|
-
keywordGroups: [{
|
|
106
|
-
groupName: '게임',
|
|
107
|
-
keywords: ['롤', '피파']
|
|
108
|
-
}]
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
// 검증
|
|
112
|
-
expect(mockClient.searchTrend).toHaveBeenCalledWith({
|
|
113
|
-
startDate: '2023-01-01',
|
|
114
|
-
endDate: '2023-01-31',
|
|
115
|
-
timeUnit: 'date',
|
|
116
|
-
keywordGroups: [{
|
|
117
|
-
groupName: '게임',
|
|
118
|
-
keywords: ['롤', '피파']
|
|
119
|
-
}]
|
|
120
|
-
});
|
|
121
|
-
expect(result).toEqual(mockResponse);
|
|
122
|
-
});
|
|
123
|
-
it('트렌드 검색 - 모든 유형(all)을 병렬 처리한다', async () => {
|
|
124
|
-
// 모의 응답 설정
|
|
125
|
-
const mockSearchResponse = { results: [{ title: '검색어 트렌드' }] };
|
|
126
|
-
const mockCategoryResponse = { results: [{ title: '카테고리 트렌드' }] };
|
|
127
|
-
mockClient.searchTrend.mockResolvedValue(mockSearchResponse);
|
|
128
|
-
mockClient.datalabShoppingCategory.mockResolvedValue(mockCategoryResponse);
|
|
129
|
-
mockClient.datalabShoppingByDevice.mockResolvedValue({ results: [{ title: '기기별 트렌드' }] });
|
|
130
|
-
mockClient.datalabShoppingKeywords.mockResolvedValue({ results: [{ title: '키워드 트렌드' }] });
|
|
131
|
-
// 테스트 호출
|
|
132
|
-
const result = await handleUnifiedSearch({
|
|
133
|
-
searchType: 'trend',
|
|
134
|
-
trendType: 'all',
|
|
135
|
-
params: {
|
|
136
|
-
startDate: '2023-01-01',
|
|
137
|
-
endDate: '2023-01-31',
|
|
138
|
-
timeUnit: 'date',
|
|
139
|
-
category: '50000000',
|
|
140
|
-
keywordGroups: [{
|
|
141
|
-
groupName: '게임',
|
|
142
|
-
keywords: ['롤', '피파']
|
|
143
|
-
}]
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
// 검증
|
|
147
|
-
expect(mockClient.searchTrend).toHaveBeenCalled();
|
|
148
|
-
expect(result).toHaveProperty('search');
|
|
149
|
-
// category 파라미터가 있으면 쇼핑 관련 함수들도 호출된다
|
|
150
|
-
expect(mockClient.datalabShoppingCategory).toHaveBeenCalled();
|
|
151
|
-
expect(mockClient.datalabShoppingByDevice).toHaveBeenCalled();
|
|
152
|
-
expect(result).toHaveProperty('shopping_category');
|
|
153
|
-
expect(result).toHaveProperty('shopping_by_device');
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
describe('Error Handling', () => {
|
|
157
|
-
it('일반 검색에서 에러 발생 시 에러 메시지를 포함한 응답을 반환한다', async () => {
|
|
158
|
-
// 에러 발생 시뮬레이션
|
|
159
|
-
mockClient.search.mockRejectedValue(new Error('API 에러'));
|
|
160
|
-
// 테스트 호출
|
|
161
|
-
await expect(handleUnifiedSearch({
|
|
162
|
-
searchType: 'general',
|
|
163
|
-
generalType: 'webkr',
|
|
164
|
-
params: { query: '에러 테스트' }
|
|
165
|
-
})).rejects.toThrow('API 에러');
|
|
166
|
-
});
|
|
167
|
-
it('모든 검색에서 일부 API가 실패해도 성공한 결과는 반환한다', async () => {
|
|
168
|
-
mockClient.search.mockImplementation((type) => {
|
|
169
|
-
if (type === 'webkr') {
|
|
170
|
-
return Promise.resolve({ items: [{ title: '웹문서 결과' }] });
|
|
171
|
-
}
|
|
172
|
-
else if (type === 'news') {
|
|
173
|
-
return Promise.reject(new Error('뉴스 API 에러'));
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
return Promise.resolve({ items: [] });
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
// 테스트 호출
|
|
180
|
-
const result = await handleUnifiedSearch({
|
|
181
|
-
searchType: 'general',
|
|
182
|
-
generalType: 'all',
|
|
183
|
-
params: { query: '부분 에러 테스트' }
|
|
184
|
-
});
|
|
185
|
-
// 성공한 API 결과 확인
|
|
186
|
-
expect(result).toHaveProperty('webkr');
|
|
187
|
-
expect(result.webkr).toEqual({ items: [{ title: '웹문서 결과' }] });
|
|
188
|
-
// 실패한 API 결과 확인
|
|
189
|
-
expect(result).toHaveProperty('news');
|
|
190
|
-
expect(result.news).toHaveProperty('error');
|
|
191
|
-
expect(result.news.error).toBe('뉴스 API 에러');
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
});
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* unified-search.schemas.test.ts
|
|
3
|
-
*
|
|
4
|
-
* 통합 검색 스키마에 대한 테스트
|
|
5
|
-
*/
|
|
6
|
-
import { UnifiedSearchSchema, GeneralSearchSchema, TrendSearchSchema, GeneralSearchTypeSchema, TrendSearchTypeSchema } from '../src/schemas/unified-search.schemas.js';
|
|
7
|
-
describe('Unified Search Schemas', () => {
|
|
8
|
-
describe('GeneralSearchTypeSchema', () => {
|
|
9
|
-
it('"all" 옵션을 포함한다', () => {
|
|
10
|
-
const values = Object.values(GeneralSearchTypeSchema.enum);
|
|
11
|
-
expect(values).toContain('all');
|
|
12
|
-
});
|
|
13
|
-
it('모든 일반 검색 타입을 포함한다', () => {
|
|
14
|
-
const values = Object.values(GeneralSearchTypeSchema.enum);
|
|
15
|
-
const expectedTypes = [
|
|
16
|
-
'all', 'webkr', 'news', 'blog', 'shop', 'image',
|
|
17
|
-
'kin', 'book', 'encyc', 'academic', 'local', 'cafearticle'
|
|
18
|
-
];
|
|
19
|
-
expectedTypes.forEach(type => {
|
|
20
|
-
expect(values).toContain(type);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
describe('TrendSearchTypeSchema', () => {
|
|
25
|
-
it('"all" 옵션을 포함한다', () => {
|
|
26
|
-
const values = Object.values(TrendSearchTypeSchema.enum);
|
|
27
|
-
expect(values).toContain('all');
|
|
28
|
-
});
|
|
29
|
-
it('모든 트렌드 검색 타입을 포함한다', () => {
|
|
30
|
-
const values = Object.values(TrendSearchTypeSchema.enum);
|
|
31
|
-
const expectedTypes = [
|
|
32
|
-
'all', 'search', 'shopping_category', 'shopping_by_device',
|
|
33
|
-
'shopping_by_gender', 'shopping_by_age', 'shopping_keywords',
|
|
34
|
-
'shopping_keyword_by_device', 'shopping_keyword_by_gender',
|
|
35
|
-
'shopping_keyword_by_age'
|
|
36
|
-
];
|
|
37
|
-
expectedTypes.forEach(type => {
|
|
38
|
-
expect(values).toContain(type);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe('GeneralSearchSchema', () => {
|
|
43
|
-
it('유효한 일반 검색 객체를 검증한다', () => {
|
|
44
|
-
// 유효한 일반 검색 객체
|
|
45
|
-
const validGeneralSearch = {
|
|
46
|
-
searchType: 'general',
|
|
47
|
-
generalType: 'webkr',
|
|
48
|
-
params: {
|
|
49
|
-
query: '테스트 검색어',
|
|
50
|
-
display: 10,
|
|
51
|
-
sort: 'sim'
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
// 스키마 검증 시 에러가 발생하지 않아야 함
|
|
55
|
-
expect(() => GeneralSearchSchema.parse(validGeneralSearch)).not.toThrow();
|
|
56
|
-
});
|
|
57
|
-
it('유효한 일반 검색 all 옵션을 검증한다', () => {
|
|
58
|
-
// all 옵션을 사용한 유효한 일반 검색 객체
|
|
59
|
-
const validAllGeneralSearch = {
|
|
60
|
-
searchType: 'general',
|
|
61
|
-
generalType: 'all',
|
|
62
|
-
params: {
|
|
63
|
-
query: '통합 검색어',
|
|
64
|
-
display: 5
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
expect(() => GeneralSearchSchema.parse(validAllGeneralSearch)).not.toThrow();
|
|
68
|
-
});
|
|
69
|
-
it('유효하지 않은 일반 검색 객체를 거부한다', () => {
|
|
70
|
-
// 필수 필드 누락
|
|
71
|
-
const missingParams = {
|
|
72
|
-
searchType: 'general',
|
|
73
|
-
generalType: 'webkr'
|
|
74
|
-
// params 누락
|
|
75
|
-
};
|
|
76
|
-
// 잘못된 generalType
|
|
77
|
-
const invalidType = {
|
|
78
|
-
searchType: 'general',
|
|
79
|
-
generalType: 'invalid-type',
|
|
80
|
-
params: { query: '검색어' }
|
|
81
|
-
};
|
|
82
|
-
// 필수 필드가 없으면 에러가 발생해야 함
|
|
83
|
-
expect(() => GeneralSearchSchema.parse(missingParams)).toThrow();
|
|
84
|
-
// 잘못된 타입이면 에러가 발생해야 함
|
|
85
|
-
expect(() => GeneralSearchSchema.parse(invalidType)).toThrow();
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
describe('TrendSearchSchema', () => {
|
|
89
|
-
it('유효한 트렌드 검색 객체를 검증한다', () => {
|
|
90
|
-
// 유효한 트렌드 검색 객체
|
|
91
|
-
const validTrendSearch = {
|
|
92
|
-
searchType: 'trend',
|
|
93
|
-
trendType: 'search',
|
|
94
|
-
params: {
|
|
95
|
-
startDate: '2023-01-01',
|
|
96
|
-
endDate: '2023-01-31',
|
|
97
|
-
timeUnit: 'date',
|
|
98
|
-
keywordGroups: [{
|
|
99
|
-
groupName: '게임',
|
|
100
|
-
keywords: ['롤', '피파']
|
|
101
|
-
}]
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
expect(() => TrendSearchSchema.parse(validTrendSearch)).not.toThrow();
|
|
105
|
-
});
|
|
106
|
-
it('유효한 트렌드 검색 all 옵션을 검증한다', () => {
|
|
107
|
-
// all 옵션을 사용한 유효한 트렌드 검색 객체
|
|
108
|
-
const validAllTrendSearch = {
|
|
109
|
-
searchType: 'trend',
|
|
110
|
-
trendType: 'all',
|
|
111
|
-
params: {
|
|
112
|
-
startDate: '2023-01-01',
|
|
113
|
-
endDate: '2023-01-31',
|
|
114
|
-
timeUnit: 'date',
|
|
115
|
-
category: '50000000',
|
|
116
|
-
keywordGroups: [{
|
|
117
|
-
groupName: '게임',
|
|
118
|
-
keywords: ['롤', '피파']
|
|
119
|
-
}]
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
expect(() => TrendSearchSchema.parse(validAllTrendSearch)).not.toThrow();
|
|
123
|
-
});
|
|
124
|
-
it('유효하지 않은 트렌드 검색 객체를 거부한다', () => {
|
|
125
|
-
// 필수 필드 누락
|
|
126
|
-
const missingParams = {
|
|
127
|
-
searchType: 'trend',
|
|
128
|
-
trendType: 'search'
|
|
129
|
-
// params 누락
|
|
130
|
-
};
|
|
131
|
-
// 잘못된 trendType
|
|
132
|
-
const invalidType = {
|
|
133
|
-
searchType: 'trend',
|
|
134
|
-
trendType: 'invalid-type',
|
|
135
|
-
params: {
|
|
136
|
-
startDate: '2023-01-01',
|
|
137
|
-
endDate: '2023-01-31',
|
|
138
|
-
timeUnit: 'date'
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
// 필수 필드가 없으면 에러가 발생해야 함
|
|
142
|
-
expect(() => TrendSearchSchema.parse(missingParams)).toThrow();
|
|
143
|
-
// 잘못된 타입이면 에러가 발생해야 함
|
|
144
|
-
expect(() => TrendSearchSchema.parse(invalidType)).toThrow();
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
describe('UnifiedSearchSchema', () => {
|
|
148
|
-
it('일반 검색과 트렌드 검색 객체를 모두 허용한다', () => {
|
|
149
|
-
// 유효한 일반 검색 객체
|
|
150
|
-
const validGeneralSearch = {
|
|
151
|
-
searchType: 'general',
|
|
152
|
-
generalType: 'webkr',
|
|
153
|
-
params: {
|
|
154
|
-
query: '테스트 검색어',
|
|
155
|
-
display: 10
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
// 유효한 트렌드 검색 객체
|
|
159
|
-
const validTrendSearch = {
|
|
160
|
-
searchType: 'trend',
|
|
161
|
-
trendType: 'search',
|
|
162
|
-
params: {
|
|
163
|
-
startDate: '2023-01-01',
|
|
164
|
-
endDate: '2023-01-31',
|
|
165
|
-
timeUnit: 'date',
|
|
166
|
-
keywordGroups: [{
|
|
167
|
-
groupName: '게임',
|
|
168
|
-
keywords: ['롤', '피파']
|
|
169
|
-
}]
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
expect(() => UnifiedSearchSchema.parse(validGeneralSearch)).not.toThrow();
|
|
173
|
-
expect(() => UnifiedSearchSchema.parse(validTrendSearch)).not.toThrow();
|
|
174
|
-
});
|
|
175
|
-
it('유효하지 않은 검색 유형을 거부한다', () => {
|
|
176
|
-
// 잘못된 searchType
|
|
177
|
-
const invalidSearchType = {
|
|
178
|
-
searchType: 'invalid-type',
|
|
179
|
-
generalType: 'webkr',
|
|
180
|
-
params: {
|
|
181
|
-
query: '테스트 검색어'
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
expect(() => UnifiedSearchSchema.parse(invalidSearchType)).toThrow();
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* unified-search.tools.test.ts
|
|
3
|
-
*
|
|
4
|
-
* 통합 검색 도구에 대한 테스트
|
|
5
|
-
*/
|
|
6
|
-
import { unifiedSearchTools } from '../src/tools/unified-search.tools.js';
|
|
7
|
-
describe('Unified Search Tools', () => {
|
|
8
|
-
it('통합 검색 도구가 정의되어 있다', () => {
|
|
9
|
-
expect(unifiedSearchTools).toBeDefined();
|
|
10
|
-
expect(Array.isArray(unifiedSearchTools)).toBe(true);
|
|
11
|
-
expect(unifiedSearchTools.length).toBeGreaterThan(0);
|
|
12
|
-
});
|
|
13
|
-
it('통합 검색 도구가 올바른 구조를 가지고 있다', () => {
|
|
14
|
-
const unifiedSearchTool = unifiedSearchTools[0];
|
|
15
|
-
expect(unifiedSearchTool).toHaveProperty('name', 'unified_search');
|
|
16
|
-
expect(unifiedSearchTool).toHaveProperty('description');
|
|
17
|
-
expect(unifiedSearchTool).toHaveProperty('inputSchema');
|
|
18
|
-
});
|
|
19
|
-
it('통합 검색 도구 설명에 "all" 옵션에 대한 정보가 포함되어 있다', () => {
|
|
20
|
-
const unifiedSearchTool = unifiedSearchTools[0];
|
|
21
|
-
expect(unifiedSearchTool.description).toContain('all');
|
|
22
|
-
expect(unifiedSearchTool.description).toContain('통합 검색');
|
|
23
|
-
});
|
|
24
|
-
it('통합 검색 도구의 스키마가 올바르게 정의되어 있다', () => {
|
|
25
|
-
const unifiedSearchTool = unifiedSearchTools[0];
|
|
26
|
-
const schema = unifiedSearchTool.inputSchema;
|
|
27
|
-
// 스키마가 객체이고 필요한 속성을 가지고 있는지 확인
|
|
28
|
-
expect(typeof schema).toBe('object');
|
|
29
|
-
expect(schema).toBeDefined();
|
|
30
|
-
// 스키마가 JSON Schema 형식인지 확인
|
|
31
|
-
expect(schema).toHaveProperty('$schema');
|
|
32
|
-
// 스키마가 일반 검색과 트렌드 검색을 포함하는지 간접적으로 확인
|
|
33
|
-
const schemaStr = JSON.stringify(schema);
|
|
34
|
-
expect(schemaStr).toContain('general');
|
|
35
|
-
expect(schemaStr).toContain('trend');
|
|
36
|
-
expect(schemaStr).toContain('all');
|
|
37
|
-
});
|
|
38
|
-
});
|