Repository navigation
Expand file tree
/
Copy pathapi.test.ts
More file actions
74 lines (66 loc) · 2.7 KB
/
Copy pathapi.test.ts
File metadata and controls
74 lines (66 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { describe, expect, it } from "vitest";
import { handleSearchRequest } from "../src/api";
import { createLocalSearchBackend } from "../src/backends";
describe("handleSearchRequest", () => {
it("POST 임베딩 요청에 대해 위치 후보를 JSON으로 반환한다", async () => {
const response = await handleSearchRequest(
new Request("https://path-finder.test/api/search", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ embedding: [1, 0, 0], topK: 1, modelId: "tiny-sample-v1" }),
}),
{
"tiny-sample-v1": createLocalSearchBackend([
{ id: "a", label: "A 구역", vector: [1, 0, 0] },
{ id: "b", label: "B 구역", vector: [0, 1, 0] },
]),
},
);
expect(response.status).toBe(200);
await expect(response.json()).resolves.toMatchObject({
modelId: "tiny-sample-v1",
confidence: { level: "confident" },
results: [{ id: "a", label: "A 구역", rank: 1 }],
});
});
it("응답에는 내부 검색용 원본 벡터를 포함하지 않는다", async () => {
const response = await handleSearchRequest(
new Request("https://path-finder.test/api/search", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ embedding: [1, 0, 0], topK: 1 }),
}),
{ "tiny-sample-v1": createLocalSearchBackend([{ id: "a", label: "A 구역", vector: [1, 0, 0] }]) },
);
const body = await response.json();
expect(body.results[0]).not.toHaveProperty("vector");
});
it("임베딩이 없는 요청은 400으로 거절한다", async () => {
const response = await handleSearchRequest(
new Request("https://path-finder.test/api/search", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ topK: 1 }),
}),
{ "tiny-sample-v1": createLocalSearchBackend([]) },
);
expect(response.status).toBe(400);
await expect(response.json()).resolves.toMatchObject({
error: "embedding 배열이 필요합니다.",
});
});
it("알 수 없는 modelId는 400으로 거절한다", async () => {
const response = await handleSearchRequest(
new Request("https://path-finder.test/api/search", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ embedding: [1, 0, 0], topK: 1, modelId: "missing" }),
}),
{ "tiny-sample-v1": createLocalSearchBackend([]) },
);
expect(response.status).toBe(400);
await expect(response.json()).resolves.toMatchObject({
error: "지원하지 않는 modelId입니다: missing",
});
});
});