统一甲屿云命名体系
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import type { AxiosAdapter, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const messageError = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('ant-design-vue', () => ({
|
||||
message: {
|
||||
error: messageError
|
||||
}
|
||||
}))
|
||||
|
||||
import adminApi, {
|
||||
adminAfterSaleApi,
|
||||
adminArtistScheduleApi,
|
||||
adminCampaignApi,
|
||||
adminDashboardApi,
|
||||
adminInventoryApi,
|
||||
adminPaymentApi
|
||||
} from '../../src/api/admin'
|
||||
import api from '../../src/api'
|
||||
import { afterSaleApi, growthApi, paymentApi } from '../../src/api/order'
|
||||
|
||||
type CapturedRequest = {
|
||||
method?: string
|
||||
url?: string
|
||||
params?: any
|
||||
data?: any
|
||||
}
|
||||
|
||||
function okResponse(config: InternalAxiosRequestConfig): AxiosResponse {
|
||||
return {
|
||||
data: {
|
||||
code: 200,
|
||||
message: 'ok',
|
||||
data: {}
|
||||
},
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {},
|
||||
config,
|
||||
request: {}
|
||||
}
|
||||
}
|
||||
|
||||
function parseData(data: unknown) {
|
||||
return typeof data === 'string' && data ? JSON.parse(data) : data
|
||||
}
|
||||
|
||||
function captureAdapter(requests: CapturedRequest[]): AxiosAdapter {
|
||||
return (config: InternalAxiosRequestConfig) => {
|
||||
requests.push({
|
||||
method: config.method,
|
||||
url: config.url,
|
||||
params: config.params,
|
||||
data: parseData(config.data)
|
||||
})
|
||||
return Promise.resolve(okResponse(config))
|
||||
}
|
||||
}
|
||||
|
||||
describe('vNext API contracts', () => {
|
||||
const originalAdminAdapter = adminApi.defaults.adapter
|
||||
const originalApiAdapter = api.defaults.adapter
|
||||
|
||||
beforeEach(() => {
|
||||
messageError.mockClear()
|
||||
localStorage.clear()
|
||||
sessionStorage.clear()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
adminApi.defaults.adapter = originalAdminAdapter
|
||||
api.defaults.adapter = originalApiAdapter
|
||||
localStorage.clear()
|
||||
sessionStorage.clear()
|
||||
})
|
||||
|
||||
it('uses backend admin vNext endpoints', async () => {
|
||||
const requests: CapturedRequest[] = []
|
||||
adminApi.defaults.adapter = captureAdapter(requests)
|
||||
|
||||
await adminArtistScheduleApi.listSchedules({ artistId: 9, startDate: '2026-06-01', endDate: '2026-06-07' })
|
||||
await adminArtistScheduleApi.saveSchedule({ artistId: 9, workDate: '2026-06-01', startTime: '09:00', endTime: '18:00' })
|
||||
await adminPaymentApi.manualConfirmOrder(42, 'cash verified')
|
||||
await adminAfterSaleApi.listAfterSales({ status: 'APPLIED', page: 1, size: 20 })
|
||||
await adminAfterSaleApi.approveAfterSale(5, { auditReason: 'approved' })
|
||||
await adminInventoryApi.saveItem({ itemName: 'Base Gel', category: 'gel', unit: 'bottle', stockQuantity: 12 })
|
||||
await adminInventoryApi.adjustStock(7, { changeType: 'IN', changeQuantity: 3, remark: 'restock' })
|
||||
await adminCampaignApi.saveCampaign({ title: 'Summer Set', scene: 'HOME', status: 1 })
|
||||
await adminDashboardApi.getAnalytics()
|
||||
|
||||
expect(requests).toEqual([
|
||||
{ method: 'get', url: '/artist-schedule/list', params: { artistId: 9, startDate: '2026-06-01', endDate: '2026-06-07' }, data: undefined },
|
||||
{ method: 'post', url: '/artist-schedule/save', params: undefined, data: { artistId: 9, workDate: '2026-06-01', startTime: '09:00', endTime: '18:00' } },
|
||||
{ method: 'post', url: '/payment/order/42/manual-confirm', params: { remark: 'cash verified' }, data: undefined },
|
||||
{ method: 'get', url: '/after-sale/list', params: { status: 'APPLIED', page: 1, size: 20 }, data: undefined },
|
||||
{ method: 'put', url: '/after-sale/5/approve', params: undefined, data: { auditReason: 'approved' } },
|
||||
{ method: 'post', url: '/inventory/save', params: undefined, data: { itemName: 'Base Gel', category: 'gel', unit: 'bottle', stockQuantity: 12 } },
|
||||
{ method: 'post', url: '/inventory/7/adjust', params: undefined, data: { changeType: 'IN', changeQuantity: 3, remark: 'restock' } },
|
||||
{ method: 'post', url: '/campaign/save', params: undefined, data: { title: 'Summer Set', scene: 'HOME', status: 1 } },
|
||||
{ method: 'get', url: '/dashboard/analytics', params: undefined, data: undefined }
|
||||
])
|
||||
})
|
||||
|
||||
it('uses backend user vNext endpoints', async () => {
|
||||
const requests: CapturedRequest[] = []
|
||||
api.defaults.adapter = captureAdapter(requests)
|
||||
|
||||
await paymentApi.prepareOrderPayment(42)
|
||||
await paymentApi.mockSuccess(42)
|
||||
await afterSaleApi.apply({ orderId: 42, type: 'REFUND', reason: 'schedule changed', refundAmount: 88 })
|
||||
await afterSaleApi.listMy({ page: 1, size: 5 })
|
||||
await growthApi.getSummary()
|
||||
|
||||
expect(requests).toEqual([
|
||||
{ method: 'post', url: '/payment/order/42/prepare', params: undefined, data: undefined },
|
||||
{ method: 'post', url: '/payment/order/42/mock-success', params: undefined, data: undefined },
|
||||
{ method: 'post', url: '/after-sale/apply', params: undefined, data: { orderId: 42, type: 'REFUND', reason: 'schedule changed', refundAmount: 88 } },
|
||||
{ method: 'get', url: '/after-sale/my', params: { page: 1, size: 5 }, data: undefined },
|
||||
{ method: 'get', url: '/growth/summary', params: undefined, data: undefined }
|
||||
])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user