test(release-cleanup): 新增 validate/releases/tags/gitea-client 單元測試
以 node:test 內建測試器涵蓋純函式(isEmptyOrNull/requireValue/requireInteger、 selectReleasesToDelete、categorizeTags)與 GiteaClient 分頁/刪除邏輯,共 19 項測試。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
b1aa8730a2
commit
15ffa4ffb6
@@ -0,0 +1,37 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { isEmptyOrNull, requireValue, requireInteger } from '../validate.js'
|
||||
|
||||
test('isEmptyOrNull 對空值回傳 true', () => {
|
||||
assert.equal(isEmptyOrNull(''), true)
|
||||
assert.equal(isEmptyOrNull(null), true)
|
||||
assert.equal(isEmptyOrNull(undefined), true)
|
||||
assert.equal(isEmptyOrNull('null'), true)
|
||||
})
|
||||
|
||||
test('isEmptyOrNull 對有效值回傳 false', () => {
|
||||
assert.equal(isEmptyOrNull('value'), false)
|
||||
assert.equal(isEmptyOrNull('0'), false)
|
||||
assert.equal(isEmptyOrNull(0), false)
|
||||
})
|
||||
|
||||
test('requireValue 對空值丟出錯誤', () => {
|
||||
assert.throws(() => requireValue('NAME', ''), /NAME is required/)
|
||||
assert.throws(() => requireValue('NAME', 'null'), /NAME is required/)
|
||||
})
|
||||
|
||||
test('requireValue 對有效值不丟出錯誤', () => {
|
||||
assert.doesNotThrow(() => requireValue('NAME', 'value'))
|
||||
})
|
||||
|
||||
test('requireInteger 接受非負整數', () => {
|
||||
assert.doesNotThrow(() => requireInteger('KEEP_COUNT', '0'))
|
||||
assert.doesNotThrow(() => requireInteger('KEEP_COUNT', '10'))
|
||||
assert.doesNotThrow(() => requireInteger('KEEP_COUNT', 5))
|
||||
})
|
||||
|
||||
test('requireInteger 拒絕非整數或負數', () => {
|
||||
assert.throws(() => requireInteger('KEEP_COUNT', '-1'), /non-negative integer/)
|
||||
assert.throws(() => requireInteger('KEEP_COUNT', '1.5'), /non-negative integer/)
|
||||
assert.throws(() => requireInteger('KEEP_COUNT', 'abc'), /non-negative integer/)
|
||||
})
|
||||
Reference in New Issue
Block a user