48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import test from "node:test"
|
|
import { GET } from "@/app/api/admin/manuals-knowledge/route"
|
|
|
|
const ORIGINAL_ADMIN_API_TOKEN = process.env.ADMIN_API_TOKEN
|
|
|
|
test.afterEach(() => {
|
|
if (typeof ORIGINAL_ADMIN_API_TOKEN === "string") {
|
|
process.env.ADMIN_API_TOKEN = ORIGINAL_ADMIN_API_TOKEN
|
|
} else {
|
|
delete process.env.ADMIN_API_TOKEN
|
|
}
|
|
})
|
|
|
|
test("manuals knowledge admin route requires admin auth", async () => {
|
|
process.env.ADMIN_API_TOKEN = "secret-token"
|
|
|
|
const response = await GET(
|
|
new Request("http://localhost/api/admin/manuals-knowledge?query=rvv+660")
|
|
)
|
|
|
|
assert.equal(response.status, 401)
|
|
})
|
|
|
|
test("manuals knowledge admin route returns retrieval details for authorized queries", async () => {
|
|
process.env.ADMIN_API_TOKEN = "secret-token"
|
|
|
|
const response = await GET(
|
|
new Request(
|
|
"http://localhost/api/admin/manuals-knowledge?query=RVV+660+service+manual",
|
|
{
|
|
headers: {
|
|
"x-admin-token": "secret-token",
|
|
},
|
|
}
|
|
)
|
|
)
|
|
|
|
assert.equal(response.status, 200)
|
|
|
|
const body = await response.json()
|
|
|
|
assert.equal(body.summary.ran, true)
|
|
assert.equal(Array.isArray(body.result.manualCandidates), true)
|
|
assert.equal(body.result.manualCandidates.length > 0, true)
|
|
assert.equal(Array.isArray(body.result.topChunks), true)
|
|
assert.equal(Array.isArray(body.summary.topChunkCitations), true)
|
|
})
|