Files
one-pipe-system/scripts/tests/octoberBrowserFixtures.mjs
luo 16effb69f3
All checks were successful
构建并部署前端到测试环境 / deploy (push) Successful in 55s
fix: some
2026-10-13 17:43:38 +08:00

272 lines
7.8 KiB
JavaScript

const time = '2026-10-13T10:00:00+08:00'
const order = {
id: 1,
order_no: 'MOCK-ORDER-001',
order_type: 'single_card',
buyer_type: 'personal',
payment_status: 2,
payment_status_text: '已支付',
payment_method: 'wechat',
total_amount: 1000,
actual_paid_amount: 1000,
third_party_trade_no: 'MOCK-TRADE-001',
payment_channel: 'wechat',
payment_merchant_name: '模拟收款商户',
commission_status: 2,
commission_result: 2,
created_at: time,
updated_at: time,
paid_at: time,
items: [],
payments: [
{
payment_no: 'MOCK-PAY-002',
payment_method: 'wechat',
payment_channel: 'wechat',
payment_merchant_name: '模拟收款商户',
third_party_trade_no: 'MOCK-TRADE-001',
amount: 1000,
status: 1,
created_at: time,
paid_at: time,
expire_at: null
},
{
payment_no: 'MOCK-PAY-001',
payment_method: 'alipay',
payment_channel: 'fuiou',
payment_merchant_name: '模拟收款商户',
third_party_trade_no: '',
amount: 1000,
status: 2,
created_at: time,
paid_at: null,
expire_at: null
}
]
}
const application = {
id: 1,
status: 4,
status_name: '审批提交失败',
recoverable: true,
approval_submission_status: 3,
paid_amount: 1000,
created_at: time
}
const registration = {
id: 1,
status: 3,
recoverable: true,
phone: '13800000000',
username: 'mock-user',
shop_name: '模拟店铺',
created_at: time
}
const rule = {
id: 1,
package_id: 1,
package_name: '模拟套餐',
threshold_percent: 80,
enabled: true,
enabled_name: '启用',
remark: '',
updated_at: time
}
const traffic = {
id: 1,
package_name: '模拟套餐',
threshold_percent: 80,
threshold_mb: 819.2,
used_mb: 0,
limit_mb: 1024,
triggered_at: time,
notification_status: 1,
asset_type: 'iot_card',
asset_identifier: 'MOCK-ASSET'
}
const exchange = {
id: 1,
exchange_no: 'MOCK-EXCHANGE-001',
status: 3,
status_name: '已发货待确认',
status_text: '已发货待确认',
old_asset_type: 'iot_card',
old_asset_identifier: 'MOCK-OLD-ASSET',
new_asset_identifier: 'MOCK-NEW-ASSET',
flow_type: 'shipping',
flow_type_name: '物流换货',
migration_status: 'pending',
created_at: time,
updated_at: time
}
const associations = [
{
id: 101,
asset_id: 1001,
asset_type: 'iot_card',
asset_identifier: exchange.new_asset_identifier,
phone: '13800000000',
status: 1,
status_name: '有效',
established_at: time
},
{
id: 102,
asset_id: 1001,
asset_type: 'iot_card',
asset_identifier: exchange.new_asset_identifier,
phone: '13800000000',
status: 0,
status_name: '已失效',
established_at: time
},
{
id: 103,
asset_id: 1002,
asset_type: 'iot_card',
asset_identifier: exchange.old_asset_identifier,
phone: '13800000000',
status: 1,
status_name: '有效',
established_at: time
},
{
id: 104,
asset_id: 1002,
asset_type: 'iot_card',
asset_identifier: exchange.old_asset_identifier,
phone: '13900000000',
status: 1,
status_name: '有效',
established_at: time
}
]
export const mockApiPlugin = {
name: 'october-local-mock-api',
configureServer(server) {
server.middlewares.use((req, res, next) => {
const url = new URL(req.url, 'http://127.0.0.1')
const path = url.pathname
if (!path.startsWith('/api/')) return next()
if (path === '/api/auth/login' || path === '/api/auth/me') {
const user = {
id: 1,
user_type: 1,
username: '模拟管理员',
phone: '13800000000',
roles: ['R_SUPER']
}
res.setHeader('Content-Type', 'application/json; charset=utf-8')
res.end(
JSON.stringify({
code: 0,
msg: 'mock',
data: {
access_token: 'local-mock-only',
refresh_token: '',
expires_in: 3600,
user,
permissions: ['*:*:*'],
buttons: [],
menus: [{ url: '/asset-management', name: '资产管理' }]
}
})
)
return
}
if (req.method !== 'GET') {
if (path === '/api/admin/exchanges/2/complete') {
res.setHeader('Content-Type', 'application/json; charset=utf-8')
res.end(
JSON.stringify({
code: 1202,
data: null,
msg: '该资产已完成过换货,如需再次换货请使用换货后的新资产'
})
)
return
}
if (path === '/api/admin/phone-asset-associations/batch-unbind') {
let body = ''
req.on('data', (chunk) => {
body += chunk
})
req.on('end', () => {
const request = JSON.parse(body)
const items = request.assets.map((asset) => {
const matches = associations.filter(
(row) =>
row.asset_id === asset.asset_id &&
row.asset_type === asset.asset_type &&
row.status === 1
)
matches.forEach((row) => {
row.status = 0
row.status_name = '已失效'
})
return { ...asset, success: true, unbound_count: matches.length, reason: '' }
})
res.setHeader('Content-Type', 'application/json; charset=utf-8')
res.end(
JSON.stringify({
code: 0,
msg: 'mock',
data: { success_count: items.length, fail_count: 0, items }
})
)
})
return
}
res.setHeader('Content-Type', 'application/json; charset=utf-8')
res.end(
JSON.stringify({
code: 1202,
msg: '新资产已绑定手机号,请先在后台解除该资产的手机号绑定,再重新提交换货申请',
data: { phone: '13800000000' }
})
)
return
}
const page = (items) => ({
items,
list: items,
total: items.length,
page: 1,
size: 20,
page_size: 20
})
let data = page([])
if (path === '/api/admin/phone-asset-associations')
data = page(
associations.filter(
(row) =>
(!url.searchParams.get('asset_identifier') ||
row.asset_identifier === url.searchParams.get('asset_identifier')) &&
(!url.searchParams.get('phone') || row.phone === url.searchParams.get('phone'))
)
)
if (path === '/api/admin/orders/1') data = order
if (path === '/api/admin/exchanges')
data = page([exchange, { ...exchange, id: 2, exchange_no: 'MOCK-EXCHANGE-002' }])
if (path === '/api/admin/exchanges/1') data = exchange
if (path === '/api/admin/exchanges/2')
data = { ...exchange, id: 2, exchange_no: 'MOCK-EXCHANGE-002' }
if (path === '/api/admin/orders') data = page([order])
if (path === '/api/admin/employee-collection-applications/1')
data = { application, allocations: [], attempts: [] }
if (path === '/api/admin/employee-collection-applications') data = page([application])
if (path === '/api/admin/agent-distribution-registrations/1') data = registration
if (path === '/api/admin/agent-distribution-registrations') data = page([registration])
if (path === '/api/admin/package-traffic-alert-rules') data = page([rule])
if (path === '/api/admin/package-traffic-alert-rules/1') data = rule
if (path === '/api/admin/package-traffic-alerts') data = page([traffic])
if (path === '/api/admin/package-traffic-alerts/1') data = traffic
res.setHeader('Content-Type', 'application/json; charset=utf-8')
res.end(JSON.stringify({ code: 0, msg: 'mock', data }))
})
}
}