✨ feat(frontend): 支持上传后台校验与断线恢复

This commit is contained in:
orion committed 2026-09-18 11:51:35 +08:00
1 parent e8c12af834
commit 1ea2fa3c6e
10 files changed
+108 -12

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
import {test} from 'node:test'
import assert from 'node:assert/strict'
import {waitForUploadCompletion} from '../src/services/upload-completion.ts'
test('pending verification is polled until a code is issued and finalizing is announced once',async()=>{
const responses=[{code:202},{code:202},{code:200,detail:{code:'ABCD2345'}}];let checks=0,notices=0
const result=await waitForUploadCompletion(async()=>responses[checks++],()=>notices++)
assert.equal(result.detail.code,'ABCD2345');assert.equal(checks,3);assert.equal(notices,1)
})
test('legacy synchronous success and failure are returned without polling',async()=>{
for(const code of [200,400]){let calls=0;const r=await waitForUploadCompletion(async()=>{calls++;return {code}});assert.equal(r.code,code);assert.equal(calls,1)}
})
test('non-retryable authentication failure stops polling',async()=>{
let calls=0;await assert.rejects(waitForUploadCompletion(async()=>{calls++;throw Object.assign(new Error('unauthorized'),{response:{status:401}})}),/unauthorized/);assert.equal(calls,1)
})
test('transient network failure during verification retries the same completion request',async()=>{
let calls=0;const result=await waitForUploadCompletion(async()=>{
calls++;if(calls===1)return {code:202};if(calls===2)throw new Error('offline');return {code:200,detail:{code:'SAMECODE'}}
});assert.equal(calls,3);assert.equal(result.detail.code,'SAMECODE')
})