GuDingZiChan/print-agent/tests/driver-manifest.test.mjs
WuYongJie 0dc3c09315 feat(资产与打印): 提交近期借还盘点与打印助手源码
- 提交借用单缺失异常处理、扫码借还搜索与站内消息快捷处理源码
- 提交盘点范围、多终端打印、组织同步与认证模式相关源码
- 提交 .NET/Node 打印助手及版本清单源码
2026-03-27 20:18:31 +08:00

46 lines
1.5 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import path from 'node:path'
import {
loadDriverResources,
resolveDriverDownloadUrl
} from '../src/services/driverManifest.js'
const repoRoot = path.resolve(import.meta.dirname, '..', '..')
test('loadDriverResources 能读取官方与归档版驱动清单', async () => {
const resources = await loadDriverResources(repoRoot)
assert.equal(resources.officialLatest.version, 'latest')
assert.match(resources.officialLatest.sourceUrl, /^https:\/\/www\.x-printer\.cn\//)
assert.equal(resources.companyArchive.version, '2026.01.28.01')
assert.equal(
resources.companyArchive.relativePath,
'downloads/printer-driver/xprinter/archive/2026.01.28.01/xprinter-driver-2026.01.28.01.exe'
)
})
test('resolveDriverDownloadUrl 会把归档版相对路径转为服务器下载地址', async () => {
const resources = await loadDriverResources(repoRoot)
const url = resolveDriverDownloadUrl('https://www.jsgdzc.cn', resources.companyArchive)
assert.equal(
url,
'https://www.jsgdzc.cn/downloads/printer-driver/xprinter/archive/2026.01.28.01/xprinter-driver-2026.01.28.01.exe'
)
})
test('resolveDriverDownloadUrl 会自动去掉服务器地址末尾的 /api', async () => {
const resources = await loadDriverResources(repoRoot)
const url = resolveDriverDownloadUrl(
'https://www.jsgdzc.cn/api',
resources.companyArchive
)
assert.equal(
url,
'https://www.jsgdzc.cn/downloads/printer-driver/xprinter/archive/2026.01.28.01/xprinter-driver-2026.01.28.01.exe'
)
})