新增端對端整合測試(列出→刪除舊 release→重列→列 tag→刪孤立 tag 的呼叫順序)、 loadConfig 去尾斜線測試,並將 id 編碼測試改為驗證非整數 id 被略過。測試共 62 項全數通過。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
82 lines
2.4 KiB
JavaScript
82 lines
2.4 KiB
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { loadConfig } from '../config.js'
|
|
|
|
const base = {
|
|
GITEA_SERVER_URL: 'https://gitea.example.com',
|
|
GITEA_REPOSITORY: 'owner/repo',
|
|
KEEP_COUNT: '2',
|
|
}
|
|
|
|
test('loadConfig 在缺少 GITEA_SERVER_URL 時丟出', () => {
|
|
assert.throws(
|
|
() => loadConfig({ GITEA_REPOSITORY: 'owner/repo', KEEP_COUNT: '2' }),
|
|
/GITEA_SERVER_URL is required/,
|
|
)
|
|
})
|
|
|
|
test('loadConfig 在 KEEP_COUNT 非整數時丟出', () => {
|
|
assert.throws(
|
|
() => loadConfig({ ...base, KEEP_COUNT: 'abc' }),
|
|
/non-negative integer/,
|
|
)
|
|
})
|
|
|
|
test('loadConfig 在 GITEA_SERVER_URL 非合法 URL 時丟出', () => {
|
|
assert.throws(
|
|
() => loadConfig({ ...base, GITEA_SERVER_URL: 'not a url' }),
|
|
/must be a valid URL/,
|
|
)
|
|
})
|
|
|
|
test('loadConfig 在 GITEA_REPOSITORY 含路徑穿越時丟出', () => {
|
|
assert.throws(
|
|
() => loadConfig({ ...base, GITEA_REPOSITORY: '../evil' }),
|
|
/owner\/repo without path traversal/,
|
|
)
|
|
})
|
|
|
|
test('loadConfig 在有效輸入時回傳完整設定物件', () => {
|
|
const cfg = loadConfig(base)
|
|
assert.equal(cfg.serverUrl, 'https://gitea.example.com')
|
|
assert.equal(cfg.repository, 'owner/repo')
|
|
assert.equal(cfg.token, null)
|
|
assert.equal(cfg.keepCount, 2)
|
|
assert.equal(
|
|
cfg.releaseApiUrl,
|
|
'https://gitea.example.com/api/v1/repos/owner/repo/releases',
|
|
)
|
|
assert.equal(
|
|
cfg.tagApiUrl,
|
|
'https://gitea.example.com/api/v1/repos/owner/repo/tags',
|
|
)
|
|
})
|
|
|
|
test('loadConfig 去除 GITEA_SERVER_URL 結尾斜線,避免 API 路徑出現雙斜線', () => {
|
|
const cfg = loadConfig({ ...base, GITEA_SERVER_URL: 'https://gitea.example.com/' })
|
|
assert.equal(cfg.serverUrl, 'https://gitea.example.com')
|
|
assert.equal(
|
|
cfg.releaseApiUrl,
|
|
'https://gitea.example.com/api/v1/repos/owner/repo/releases',
|
|
)
|
|
})
|
|
|
|
test('loadConfig 在提供 token 時保留 token 值', () => {
|
|
const cfg = loadConfig({ ...base, GITEA_TOKEN: 'secret' })
|
|
assert.equal(cfg.token, 'secret')
|
|
})
|
|
|
|
test('loadConfig 在 GITEA_TOKEN 為空字串時視為匿名(token 為 null)', () => {
|
|
const cfg = loadConfig({ ...base, GITEA_TOKEN: '' })
|
|
assert.equal(cfg.token, null)
|
|
})
|
|
|
|
test('loadConfig 接受極短與極長的 GITEA_TOKEN', () => {
|
|
const short = loadConfig({ ...base, GITEA_TOKEN: 'x' })
|
|
assert.equal(short.token, 'x')
|
|
|
|
const longToken = 'a'.repeat(1000)
|
|
const long = loadConfig({ ...base, GITEA_TOKEN: longToken })
|
|
assert.equal(long.token, longToken)
|
|
})
|