diff --git a/app/test/releases.test.js b/app/test/releases.test.js index 0091e8c..06690d6 100644 --- a/app/test/releases.test.js +++ b/app/test/releases.test.js @@ -140,6 +140,20 @@ test('cleanupReleases 在刪除回傳非 204 時記錄錯誤至 stderr', async ( assert.match(chunks.join(''), /\[ERR\]/) }) +test('cleanupReleases 對含 null/異常結構的 release 不拋例外且照常處理正常項目', async () => { + const client = fakeClient([ + { id: 3, tag_name: 'v3', name: 'n3', created_at: '2024-03-01T00:00:00Z' }, + null, + { created_at: '2024-02-01T00:00:00Z' }, // 缺 id/tag_name + { id: 1, tag_name: 'v1', name: 'n1', created_at: '2024-01-01T00:00:00Z' }, + ]) + await assert.doesNotReject(() => + cleanupReleases(client, { releaseApiUrl: 'http://x/releases', keepCount: 1 }), + ) + // 保留最新(id=3);待刪除者中僅 id=1 為有效正整數 id,其餘(null、缺 id)被略過 + assert.deepEqual(client.deleted, ['http://x/releases/1']) +}) + test('cleanupReleases 略過沒有 id 的 release', async () => { const client = fakeClient([ { id: 1, tag_name: 'v3', name: 'n3', created_at: '2024-03-01T00:00:00Z' }, diff --git a/app/test/tags.test.js b/app/test/tags.test.js index 226c4f9..5e80792 100644 --- a/app/test/tags.test.js +++ b/app/test/tags.test.js @@ -114,6 +114,18 @@ test('cleanupOrphanTags 在刪除回傳非 204 時繼續處理其餘 tag 並記 assert.match(chunks.join(''), /\[ERR\]/) }) +test('cleanupOrphanTags 在 fetchAllPages 拋錯時向外拋出', async () => { + const client = { + async fetchAllPages() { + throw new Error('GET http://x/releases?page=1 failed: HTTP 500') + }, + async deleteResource() { + return 204 + }, + } + await assert.rejects(() => cleanupOrphanTags(client, config), /HTTP 500/) +}) + test('cleanupOrphanTags 對含特殊字元的 tag 名稱進行 URL 編碼(防路徑穿越)', async () => { const client = fakeClient({ releases: [],