60 lines
3.4 KiB
JavaScript
60 lines
3.4 KiB
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { makeRosterSnapshot, resolveRoster } from './roster.mjs'
|
|
|
|
// Deliberately not contiguous: no logic may use a department ID as an array index.
|
|
const departments = [{ dept_id: 17, dept_name: '预览一组' }, { dept_id: 39, dept_name: '预览二组' }]
|
|
const seed = new Date(2027, 0, 1, 9, 17)
|
|
const snapshot = { ...makeRosterSnapshot(departments, seed), departments }
|
|
const doctorPath = '/adminapi/auth.admin/lists', rosterPath = '/adminapi/doctor.roster/lists'
|
|
const doctorQuery = { role_id: '1', exclude_disabled: '1' }
|
|
const read = (path, q) => {
|
|
const response = resolveRoster(path, q, snapshot)
|
|
assert.deepEqual([response.code, response.show, response.msg], [1, 0, ''])
|
|
return response.data
|
|
}
|
|
|
|
test('相邻周跨年、同日期排班不漂移、每段有合法医生部门关系', () => {
|
|
const { slots, doctors } = snapshot
|
|
assert.ok(slots.length > 0)
|
|
assert.equal(new Set(slots.map(s => s.id)).size, slots.length)
|
|
assert.ok(doctors.every(d => departments.some(dep => dep.dept_id === d.dept_id)))
|
|
assert.ok(slots.every(s => doctors.some(d => d.id === s.doctor_id) && s.start_time < s.end_time))
|
|
assert.deepEqual(new Set(slots.map(s => s.status)), new Set([1, 2, 3, 4]))
|
|
for (const [start, end] of [['2026-12-21','2026-12-27'],['2026-12-28','2027-01-03'],['2027-01-04','2027-01-10']]) {
|
|
const week = read(rosterPath, { start_date: start, end_date: end })
|
|
assert.equal(week.count, week.lists.length)
|
|
assert.equal(new Set(week.lists.map(s => s.date)).size, 7)
|
|
assert.ok(week.lists.every(s => s.date >= start && s.date <= end))
|
|
}
|
|
const next = makeRosterSnapshot(departments, new Date(2027, 0, 4))
|
|
const interval = s => s.date >= '2026-12-28' && s.date <= '2027-01-10'
|
|
assert.deepEqual(slots.filter(interval), next.slots.filter(interval))
|
|
assert.deepEqual(makeRosterSnapshot([], seed), { doctors: [], slots: [] })
|
|
})
|
|
|
|
test('医生列表限制角色、部门和分页;排班按日期、医生与状态合并过滤', () => {
|
|
const all = read(doctorPath, new URLSearchParams(doctorQuery))
|
|
assert.equal(all.count, snapshot.doctors.length)
|
|
const d = all.lists[0]
|
|
assert.deepEqual(d.dept_id, [17])
|
|
assert.equal(d.dept_name, departments[0].dept_name)
|
|
assert.deepEqual(read(doctorPath, { ...doctorQuery, name: d.name }).lists, [d])
|
|
assert.deepEqual(read(doctorPath, { ...doctorQuery, page_no: 2, page_size: 1 }).lists, [all.lists[1]])
|
|
const slot = snapshot.slots.find(s => s.doctor_id === d.id && s.status === 1)
|
|
const matches = read(rosterPath, { start_date: slot.date, end_date: slot.date, doctor_id: String(d.id), status: '1', period: 'segment' })
|
|
assert.ok(matches.lists.some(s => s.id === slot.id))
|
|
assert.ok(matches.lists.every(s => s.doctor_id === d.id && s.status === 1 && s.date === slot.date))
|
|
assert.equal(read(rosterPath, { doctor_id: -1 }).count, 0)
|
|
})
|
|
|
|
test('通用账号、导出、写入和未开放路由均不模拟', () => {
|
|
for (const q of [{}, { role_id: 1 }, { ...doctorQuery, role_id: 2 }, { ...doctorQuery, export: 1 }]) {
|
|
assert.equal(resolveRoster(doctorPath, q, snapshot), null)
|
|
}
|
|
for (const action of ['save', 'delete', 'batchSave', 'copy', 'detail']) {
|
|
assert.equal(resolveRoster('/adminapi/doctor.roster/' + action, {}, snapshot), null)
|
|
}
|
|
assert.equal(resolveRoster(rosterPath, { export: 2 }, snapshot), null)
|
|
})
|