Files
admin-web/src/modules/overseas-warehouse/api/cargoDiscards.test.ts
T
2026-10-14 11:43:32 +08:00

16 lines
1.2 KiB
TypeScript

import { beforeEach, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import { downloadCargoDiscardPhoto, getCargoDiscard } from './cargoDiscards'
vi.mock('@/shared/api/http', async importOriginal => ({ ...(await importOriginal<typeof import('@/shared/api/http')>()), http: { get: vi.fn() } }))
beforeEach(() => vi.mocked(http.get).mockReset())
it('reads submitted photos from detail and downloads a blob in the explicit customer scope', async () => {
const photos = [{ fileId: '101', palletNo: 'PALLET-A', fileName: 'discard.png', createdAt: '2026-10-14T10:00:00', submittedAt: '2026-10-14T10:01:00' }]
vi.mocked(http.get).mockResolvedValueOnce({ code: '200', data: { summary: { discardNo: 'CD/1', customerId: '7' }, photos, items: [], histories: [] } })
expect((await getCargoDiscard('CD/1', '7')).photos).toEqual(photos)
const blob = new Blob(['image'], { type: 'image/png' })
vi.mocked(http.get).mockResolvedValueOnce(blob)
expect(await downloadCargoDiscardPhoto('CD/1', '101', '7')).toBe(blob)
expect(http.get).toHaveBeenLastCalledWith('/platform/v1/last-leg/cargo-discards/CD%2F1/photos/files/101/download', { params: { customerId: '7' }, responseType: 'blob' })
})