优化
This commit is contained in:
@@ -4,7 +4,9 @@ import {
|
||||
confirmWeightResult,
|
||||
correctWeightResult,
|
||||
createWeightResult,
|
||||
deleteWeightResult,
|
||||
downloadWeightImage,
|
||||
downloadWeightThumbnail,
|
||||
getWeightOcrRawText,
|
||||
getWeightWorkspace,
|
||||
normalizeWeightConfidence,
|
||||
@@ -13,7 +15,7 @@ import {
|
||||
} from './weightOcr'
|
||||
|
||||
vi.mock('@/shared/api/http', () => ({
|
||||
http: { get: vi.fn(), post: vi.fn(), put: vi.fn() },
|
||||
http: { delete: vi.fn(), get: vi.fn(), post: vi.fn(), put: vi.fn() },
|
||||
ApiResponseError: class ApiResponseError extends Error {},
|
||||
unwrapApiResponse: <T>(response: { data: T }) => response.data,
|
||||
}))
|
||||
@@ -21,6 +23,7 @@ vi.mock('@/shared/api/http', () => ({
|
||||
describe('inbound weight OCR API', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(http.get).mockReset()
|
||||
vi.mocked(http.delete).mockReset()
|
||||
vi.mocked(http.post).mockReset()
|
||||
vi.mocked(http.put).mockReset()
|
||||
})
|
||||
@@ -136,4 +139,22 @@ describe('inbound weight OCR API', () => {
|
||||
{ responseType: 'blob' },
|
||||
)
|
||||
})
|
||||
|
||||
it('downloads a thumbnail and deletes a result without converting long IDs', async () => {
|
||||
const image = new Blob(['jpg'], { type: 'image/jpeg' })
|
||||
vi.mocked(http.get).mockResolvedValue(image)
|
||||
vi.mocked(http.delete).mockResolvedValue({ code: '200', message: 'success', data: null })
|
||||
|
||||
await expect(downloadWeightThumbnail('10001', '20001', '9007199254740995')).resolves.toBe(image)
|
||||
expect(http.get).toHaveBeenCalledWith(
|
||||
'/platform/v1/files/measurements/10001/20001/9007199254740995/thumbnail',
|
||||
{ responseType: 'blob' },
|
||||
)
|
||||
|
||||
await deleteWeightResult('10001', '20001', '9007199254740997', 3)
|
||||
expect(http.delete).toHaveBeenCalledWith(
|
||||
'/platform/v1/first-leg/inbounds/20001/weight-results/9007199254740997',
|
||||
{ params: { tenantId: '10001', version: 3 } },
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -94,6 +94,24 @@ export async function downloadWeightImage(tenantId: string, inboundId: string, f
|
||||
}
|
||||
}
|
||||
|
||||
export async function downloadWeightThumbnail(tenantId: string, inboundId: string, fileId: string) {
|
||||
try {
|
||||
const blob = await http.get<Blob, Blob>(
|
||||
`${imageBasePath}/${segment(tenantId)}/${segment(inboundId)}/${segment(fileId)}/thumbnail`,
|
||||
{ responseType: 'blob' },
|
||||
)
|
||||
const responseError = await parseBlobError(blob, 200)
|
||||
if (responseError) throw responseError
|
||||
return blob
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error) && error.response?.data instanceof Blob) {
|
||||
const responseError = await parseBlobError(error.response.data, error.response.status)
|
||||
if (responseError) throw responseError
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export async function createWeightResult(
|
||||
tenantId: string,
|
||||
inboundId: string,
|
||||
@@ -138,3 +156,16 @@ export async function confirmWeightResult(
|
||||
)
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
|
||||
export async function deleteWeightResult(
|
||||
tenantId: string,
|
||||
inboundId: string,
|
||||
resultId: string,
|
||||
version: number,
|
||||
) {
|
||||
const response = await http.delete<ApiEnvelope<null>, ApiEnvelope<null>>(
|
||||
`${measurementBasePath}/${segment(inboundId)}/weight-results/${segment(resultId)}`,
|
||||
{ params: { tenantId, version } },
|
||||
)
|
||||
unwrapApiResponse(response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user