import { beforeEach, describe, expect, it, vi } from 'vitest' import { applicationApi } from './application' const request = vi.hoisted(() => ({ get: vi.fn() })) vi.mock('./index', () => ({ default: request })) describe('application API 分页参数', () => { beforeEach(() => { vi.clearAllMocks() request.get.mockResolvedValue({ data: { items: [], total: 0 } }) }) it('把页码换算成后端认识的 limit/offset,第 2 页不再是 offset=0', async () => { await applicationApi.getMy('', 2, 20) expect(request.get).toHaveBeenCalledWith('/applications/my', { params: { status: '', limit: 20, offset: 20 } }) }) it('审批页的 getAll 同样换算,且不落下 status 筛选', async () => { await applicationApi.getAll('pending', 3, 10) expect(request.get).toHaveBeenCalledWith('/applications', { params: { status: 'pending', limit: 10, offset: 20 } }) }) it('第 1 页从 offset=0 开始', async () => { await applicationApi.getAll('', 1, 20) expect(request.get).toHaveBeenCalledWith('/applications', { params: { status: '', limit: 20, offset: 0 } }) }) it('页码或每页条数非法时退回第 1 页的默认值,不产生负 offset', async () => { await applicationApi.getMy('', 0, 0) expect(request.get).toHaveBeenCalledWith('/applications/my', { params: { status: '', limit: 20, offset: 0 } }) }) })