优化
This commit is contained in:
@@ -42,7 +42,7 @@ test('H5 proxy and App API roots normalize request upload and download paths to
|
||||
globalThis.uni.uploadFile = (options) => { uploads.push(options.url); options.success({ statusCode: 200, data: JSON.stringify({ code: '200', data: { fileId: '1' } }), header: {} }) }
|
||||
globalThis.uni.downloadFile = (options) => { downloads.push(options.url); options.success({ statusCode: 200, tempFilePath: '/tmp/photo.jpg', header: {} }) }
|
||||
|
||||
session.apiBase = '/api'
|
||||
session.apiBase = '/gateway-api'
|
||||
await resolvePallet('PLT-1')
|
||||
await overseasUpload('/api/pda/v1/last-leg/photos/files', '/tmp/photo.jpg')
|
||||
await overseasDownload('/api/pda/v1/last-leg/photos/files/1/download')
|
||||
@@ -53,15 +53,15 @@ test('H5 proxy and App API roots normalize request upload and download paths to
|
||||
await overseasDownload('/api/pda/v1/last-leg/photos/files/1/download')
|
||||
|
||||
assert.deepEqual(requests, [
|
||||
'/api/pda/v1/last-leg/pallet-operations/pallets/resolve',
|
||||
'/gateway-api/pda/v1/last-leg/pallet-operations/pallets/resolve',
|
||||
'https://overseas.example.com/api/pda/v1/last-leg/pallet-operations/pallets/resolve'
|
||||
])
|
||||
assert.deepEqual(uploads, [
|
||||
'/api/pda/v1/last-leg/photos/files',
|
||||
'/gateway-api/pda/v1/last-leg/photos/files',
|
||||
'https://overseas.example.com/api/pda/v1/last-leg/photos/files'
|
||||
])
|
||||
assert.deepEqual(downloads, [
|
||||
'/api/pda/v1/last-leg/photos/files/1/download',
|
||||
'/gateway-api/pda/v1/last-leg/photos/files/1/download',
|
||||
'https://overseas.example.com/api/pda/v1/last-leg/photos/files/1/download'
|
||||
])
|
||||
for (const url of [...requests, ...uploads, ...downloads]) assert.doesNotMatch(url, /\/api\/api\//)
|
||||
@@ -175,10 +175,10 @@ test('H5 blob photo uses authenticated multipart fetch instead of uni.uploadFile
|
||||
return new Response(JSON.stringify({ code: '200', data: { fileId: 'h5-1' } }), { status: 200 })
|
||||
}
|
||||
try {
|
||||
session.apiBase = '/api'
|
||||
session.apiBase = '/gateway-api'
|
||||
assert.deepEqual(await overseasUpload('/api/pda/v1/last-leg/photos/files', 'blob:http://localhost/photo'), { fileId: 'h5-1' })
|
||||
assert.equal(uploadFileCalls, 0)
|
||||
assert.equal(uploaded.url, '/api/pda/v1/last-leg/photos/files')
|
||||
assert.equal(uploaded.url, '/gateway-api/pda/v1/last-leg/photos/files')
|
||||
assert.equal(uploaded.options.headers.Authorization, `Bearer ${value.accessToken}`)
|
||||
assert.ok(uploaded.options.body instanceof FormData)
|
||||
} finally {
|
||||
@@ -200,14 +200,14 @@ test('H5 File photo is appended directly without rereading a temporary blob URL'
|
||||
let calls = 0
|
||||
globalThis.uni.uploadFile = (options) => {
|
||||
calls += 1
|
||||
assert.equal(options.url, '/api/pda/photo')
|
||||
assert.equal(options.url, '/gateway-api/pda/photo')
|
||||
assert.equal(options.header.Authorization, `Bearer ${value.accessToken}`)
|
||||
assert.equal(options.files[0].file, selected)
|
||||
assert.equal(options.files[0].name, 'file')
|
||||
options.success({ statusCode: 200, data: JSON.stringify({ code: '200', data: { fileId: 'direct-file' } }), header: {} })
|
||||
}
|
||||
try {
|
||||
session.apiBase = '/api'
|
||||
session.apiBase = '/gateway-api'
|
||||
assert.deepEqual(await overseasUpload('/pda/photo', selected), { fileId: 'direct-file' })
|
||||
assert.equal(calls, 1)
|
||||
} finally {
|
||||
@@ -222,7 +222,7 @@ test('native file runtime rejects an H5-relative overseas root before upload wit
|
||||
prepareSession()
|
||||
const originalLocation = globalThis.location
|
||||
globalThis.location = { protocol: 'file:' }
|
||||
session.apiBase = '/api'
|
||||
session.apiBase = '/gateway-api'
|
||||
let uploadCalls = 0
|
||||
globalThis.uni.uploadFile = () => { uploadCalls += 1 }
|
||||
try {
|
||||
@@ -267,7 +267,7 @@ test('authenticated photo download maps the public api path through the H5 overs
|
||||
}
|
||||
assert.equal(await overseasDownload('/api/pda/v1/last-leg/receiving-containers/current/unload-photos/files/99/download'), '/tmp/restored.jpg')
|
||||
assert.equal(calls.length, 1)
|
||||
assert.equal(calls[0].url, '/api/pda/v1/last-leg/receiving-containers/current/unload-photos/files/99/download')
|
||||
assert.equal(calls[0].url, '/gateway-api/pda/v1/last-leg/receiving-containers/current/unload-photos/files/99/download')
|
||||
assert.equal(calls[0].header.Authorization, `Bearer ${value.accessToken}`)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user