test: 整併測試至 app/test 並解決 AI 審查 findings #8
@@ -77,6 +77,24 @@ test('fetchReleases 對無法解析的 JSON 回應拋錯', async () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('fetchReleases 解析失敗時截斷過長的回應片段', async () => {
|
||||||
|
const huge = `{${'x'.repeat(5000)}`;
|
||||||
|
await withFetch(
|
||||||
|
async () => jsonResponse(huge, true),
|
||||||
|
async () => {
|
||||||
|
await assert.rejects(
|
||||||
|
() => fetchReleases('https://gitea.example.com/api'),
|
||||||
|
(err) => {
|
||||||
|
const match = err.message.match(/片段:「([\s\S]*)」$/);
|
||||||
|
assert.ok(match, '錯誤訊息應包含回應內容片段');
|
||||||
|
assert.ok(Array.from(match[1]).length <= 200, '片段應截斷至 200 字元內');
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('fetchReleases 對非陣列回應拋錯', async () => {
|
test('fetchReleases 對非陣列回應拋錯', async () => {
|
||||||
await withFetch(
|
await withFetch(
|
||||||
async () => jsonResponse({ message: 'oops' }),
|
async () => jsonResponse({ message: 'oops' }),
|
||||||
|
|||||||
Reference in New Issue
Block a user