81 lines
4.4 KiB
JavaScript
81 lines
4.4 KiB
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { resolveFixture } from './fixtures.mjs'
|
|
|
|
const read = (path, query) => {
|
|
const result = resolveFixture('/adminapi/' + path, query)
|
|
assert.equal(result.code, 1)
|
|
assert.deepEqual([result.msg, result.show], ['', 0])
|
|
return result.data
|
|
}
|
|
const orders = q => read('order.order/lists', q)
|
|
|
|
test('分页、每种状态、订单号、患者与医助过滤使用同一数据集', () => {
|
|
const first = orders({}), second = orders(new URLSearchParams('page_no=2&page_size=15'))
|
|
assert.ok(first.count > 15)
|
|
assert.equal(first.lists.length, 15)
|
|
assert.equal(second.count, first.count)
|
|
assert.ok(!first.lists.some(r => second.lists.some(other => other.id === r.id)))
|
|
assert.deepEqual(orders({ order_no: 'NO-MATCH' }).lists, [])
|
|
for (const status of [1, 2, 3, 4, 5]) {
|
|
const { lists } = orders({ status: String(status) })
|
|
assert.ok(lists.length && lists.every(r => r.status === status))
|
|
}
|
|
const r = first.lists[0]
|
|
assert.deepEqual(orders({ order_no: r.order_no.toLowerCase(), patient_keyword: r.patient.phone,
|
|
order_type: r.order_type, assistant_id: r.creator.id, status: r.status, create_time_start: r.create_time,
|
|
create_time_end: r.create_time }).lists, [r])
|
|
assert.equal(orders({ create_time_end: '2000-01-01' }).count, 0)
|
|
assert.equal(orders({ patient_association: 'pending' }).count + orders({ patient_association: 'associated' }).count, first.count)
|
|
assert.ok(orders({ patient_association: 'pending' }).lists.every(r => !r.patient))
|
|
assert.ok(read('tcm.diagnosis/getAssistants').some(a => a.id === r.creator_id))
|
|
assert.ok(read('tcm.diagnosis/searchPatient', { keyword: r.patient.patient_name }).lists.some(p => p.id === r.patient_id))
|
|
})
|
|
|
|
test('订单详情和日志只读取演示数据,统计按日期返回', () => {
|
|
const sample = orders({}).lists[0]
|
|
assert.deepEqual(read('order.order/detail', { id: sample.id }), sample)
|
|
assert.equal(resolveFixture('/adminapi/order.order/detail', { id: -1 }).code, 0)
|
|
const records = read('order.order/actionLogs', { order_id: sample.id })
|
|
assert.ok(records.count && records.lists.every(l => l.order_id === sample.id))
|
|
assert.ok(read('order.order/actionLogStats').list.length)
|
|
assert.deepEqual(read('order.order/actionLogStats', { start_time: '1999-01-01', end_time: '1999-01-07' }).list, [])
|
|
})
|
|
|
|
test('工作台图表均有数据;今日收益、类型、周期和排行榜可核对', () => {
|
|
const revenue = read('order.order/todayRevenue')
|
|
const today = read('order.order/orderStats', { order_type: -1, days: 0 })
|
|
assert.deepEqual([revenue.count, revenue.amount], [today.today_total, today.today_amount])
|
|
assert.ok(revenue.count && Number(revenue.amount) > 0)
|
|
const count = rs => rs.reduce((n, a) => n + a.count, 0)
|
|
assert.equal(count(today.ranking), revenue.count)
|
|
const week = read('order.order/orderStats', { order_type: -1, days: 7 })
|
|
assert.ok(count(week.ranking) > revenue.count)
|
|
assert.ok(week.chart.xAxis.length && week.departments.every(d => d.total > 0))
|
|
for (let type = 0; type <= 8; type++) {
|
|
const result = read('order.order/orderStats', { order_type: type, days: 30 })
|
|
assert.ok(result.order_type_name && result.ranking.length)
|
|
}
|
|
const diagnosis = read('tcm.diagnosis/assistantDiagnosisStats', { days: 14 })
|
|
assert.equal(diagnosis.today_total, count(diagnosis.today_ranking))
|
|
assert.ok(diagnosis.chart.xAxis.length && count(diagnosis.ranking) > diagnosis.today_total)
|
|
const wb = read('workbench/index')
|
|
for (const series of [wb.visitor, wb.sale]) {
|
|
assert.equal(series.date.length, series.list[0].data.length)
|
|
assert.ok(series.list[0].data.every(n => n > 0))
|
|
}
|
|
})
|
|
|
|
test('未列入白名单的路径一律不生成响应(包括会写入的 GET)', () => {
|
|
for (const p of ['order.order/create', 'order.order/delete', 'order.order/edit', 'order.order/syncWechatWorkBills',
|
|
'order.order/syncWechatWorkBillsDebug', 'order.order/export', 'order.order/pay', 'unknown']) {
|
|
assert.equal(resolveFixture('/adminapi/' + p), null)
|
|
}
|
|
assert.equal(resolveFixture('/api/workbench/index'), null)
|
|
})
|
|
|
|
test('隐藏导出控件只获得合成条数,不生成导出文件', () => {
|
|
assert.equal(read('order.order/export', { export: '1' }).count, orders({}).count)
|
|
assert.equal(resolveFixture('/adminapi/order.order/export', { export: '2' }), null)
|
|
})
|