This commit is contained in:
2026-09-20 15:03:28 +08:00
parent 158ea8c8ea
commit 53c887d353
2 changed files with 64 additions and 0 deletions
@@ -0,0 +1,37 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import { listPdaReleases, publishPdaRelease, uploadPdaRelease, withdrawPdaRelease } from './pdaReleases'
vi.mock('@/shared/api/http', async () => {
const actual = await vi.importActual<typeof import('@/shared/api/http')>('@/shared/api/http')
return { ...actual, http: { get: vi.fn(), post: vi.fn() } }
})
describe('PDA release API', () => {
beforeEach(() => vi.clearAllMocks())
it('keeps domestic and overseas lists isolated and uses only File service admin routes', async () => {
vi.mocked(http.get).mockResolvedValue({ code: '200', data: [], message: 'success' })
await listPdaReleases('domestic')
await listPdaReleases('overseas')
expect(http.get).toHaveBeenNthCalledWith(1, '/platform/v1/files/pda-releases/domestic')
expect(http.get).toHaveBeenNthCalledWith(2, '/platform/v1/files/pda-releases/overseas')
})
it('uploads a draft with compatibility fields and publishes or withdraws by release identity', async () => {
vi.mocked(http.post).mockResolvedValue({ code: '200', data: { id: 'release-1' }, message: 'success' })
const file = new File(['PK\u0003\u0004'], 'app.wgt', { type: 'application/octet-stream' })
await uploadPdaRelease('overseas', { packageType: 'wgt', versionName: '0.0.4', versionCode: 3,
minAppVersionCode: 3, mandatory: true, releaseNotes: '修复扫码', file })
const [url, form, options] = vi.mocked(http.post).mock.calls[0]!
expect(url).toBe('/platform/v1/files/pda-releases/overseas')
expect(form).toBeInstanceOf(FormData)
expect((form as FormData).get('file')).toBe(file)
expect((form as FormData).get('minAppVersionCode')).toBe('3')
expect(options).toMatchObject({ timeout: 600_000 })
await publishPdaRelease('release-1')
await withdrawPdaRelease('release-1')
expect(http.post).toHaveBeenNthCalledWith(2, '/platform/v1/files/pda-releases/release-1/publish', {})
expect(http.post).toHaveBeenNthCalledWith(3, '/platform/v1/files/pda-releases/release-1/withdraw', {})
})
})