fix: some
All checks were successful
构建并部署前端到测试环境 / deploy (push) Successful in 54s

This commit is contained in:
luo
2026-10-28 15:18:44 +08:00
parent 06684e1fc0
commit f2614d8efb
99 changed files with 11511 additions and 132 deletions

View File

@@ -193,38 +193,229 @@ function mount(
...vue,
onMounted: () => {},
onBeforeUnmount: (fn) => beforeUnmount.push(fn),
onDeactivated: (fn) => deactivated.push(fn)
onDeactivated: (fn) => deactivated.push(fn),
onActivated: () => {}
}
const { descriptor } = parse(source(path))
const script = compileScript(descriptor, { id: 'scheduler-test' }).content
const store = { useUserStore: () => user }
const schedulerRequest = evaluate(source('src/composables/useSchedulerRequest.ts'), {
vue: runtime,
'@/store/modules/user': store,
'@/utils/business/gateway': gateway,
'@/utils/business/pollingScheduler': helpers
})
const imports = {
vue: runtime,
'element-plus': { ElMessageBox: { confirm } },
'vue-router': {
useRoute: () => ({ params: { id: '1', carrier_id: '8' }, fullPath: '/local/detail/1' }),
useRouter: () => ({ back() {} })
},
'element-plus': { ElMessageBox: { confirm }, ElMessage: { success() {} } },
'@/api/modules/pollingScheduler': { PollingSchedulerService: api },
'@/api/modules/storage': { StorageService: storage },
'@/store/modules/user': { useUserStore: () => user },
'@/store/modules/user': store,
'@/composables/useAuth': {
useAuth: () => ({ hasAuth: (permission) => permissions.includes(permission) })
},
'@/utils/business/gateway': gateway,
'@/utils/business/pollingScheduler': helpers,
'@/config/constants/pollingScheduler': constants,
'@/config/constants/gateway': evaluate(source('src/config/constants/gateway.ts')),
'@/composables/useSchedulerRequest': schedulerRequest,
'@/composables/useGateway': {
useGatewayCarriers: () => ({ options: vue.ref([]), search() {}, loading: vue.ref(false) })
},
'@/components/business/polling/SchedulerTable.vue': { default: {} },
'@/components/business/gateway/StopResumeRecords.vue': { default: {} },
'./PollingStateDialog.vue': { default: {} },
'@vueuse/core': { useWindowSize: () => ({ width: vue.ref(1200) }) }
}
const state = evaluate(script, imports, runtime).default.setup(props, {
expose() {},
emit: (...args) => events.push(args)
})
const scope = vue.effectScope()
const state = scope.run(() =>
evaluate(script, imports, runtime).default.setup(props, {
expose() {},
emit: (...args) => events.push(args)
})
)
return {
state,
calls,
user,
events,
dispose: () => beforeUnmount.forEach((fn) => fn()),
dispose: () => {
beforeUnmount.forEach((fn) => fn())
scope.stop()
},
deactivate: () => deactivated.forEach((fn) => fn())
}
}
const dryRunPath = 'src/views/polling-management/stop-resume-dry-run/index.vue'
const schedulerDetailPath = 'src/components/business/polling/SchedulerDetail.vue'
const dryRunResult = {
items: [{ card_id: 42, iccid: '89860426012345678901' }],
total: 1,
page: 3,
size: 20,
summary: [{ carrier_id: 8, count: 1 }],
totals: { total: 1, will_stop: 1, will_resume: 0, no_action: 0 }
}
test('dry-run reset clears filters, old summary/details and errors without starting an unfiltered scan', async () => {
const h = mount(dryRunPath, {
permissions: [constants.SCHEDULER_PERMISSIONS.dryRun.page],
services: { dryRun: () => ok(dryRunResult) }
})
Object.assign(h.state.filters, {
carrier_id: 8,
stop_reason: 'manual',
result: 'will_stop',
assume_control_on: [8],
assume_control_off: [9]
})
h.state.page.value = 3
await h.state.load()
assert.equal(h.state.data.value.totals.total, 1)
assert.equal(h.state.data.value.summary.length, 1)
assert.equal(h.state.data.value.items.length, 1)
h.state.error.value = 'old export error'
h.state.reset()
assert.deepEqual(
{ ...h.state.filters },
{
carrier_id: undefined,
stop_reason: '',
result: '',
assume_control_on: [],
assume_control_off: []
}
)
assert.equal(h.state.page.value, 1)
assert.equal(h.state.data.value, null)
assert.equal(h.state.error.value, '')
assert.equal(h.state.loading.value, false)
assert.equal(h.calls.length, 1)
h.dispose()
})
test('dry-run reset invalidates pending success/error and allows a fresh explicit query', async () => {
for (const fail of [false, true]) {
let resolve, reject
const pendingResponse = new Promise((done, failed) => {
resolve = done
reject = failed
})
let requests = 0
const h = mount(dryRunPath, {
permissions: [constants.SCHEDULER_PERMISSIONS.dryRun.page],
services: { dryRun: () => (++requests === 1 ? pendingResponse : ok(dryRunResult)) }
})
h.state.filters.stop_reason = 'manual'
const pending = h.state.load()
assert.equal(h.state.loading.value, true)
h.state.reset()
if (fail) reject(new Error('stale request failed'))
else resolve(ok(dryRunResult))
await pending
assert.equal(h.state.data.value, null)
assert.equal(h.state.error.value, '')
assert.equal(h.state.loading.value, false)
assert.equal(requests, 1)
h.state.filters.carrier_id = 9
await h.state.load()
assert.equal(h.state.data.value.totals.total, 1)
assert.equal(h.calls.at(-1).args[0].carrier_id, 9)
assert.equal(h.calls.at(-1).args[0].stop_reason, undefined)
h.dispose()
}
})
for (const [kind, method] of [
['params', 'getCarrierParam'],
['alerts', 'getAlert'],
['imports', 'getImport']
])
test(`${kind} direct detail requires both page and detail permissions and retains the role boundary`, async () => {
const P = constants.SCHEDULER_PERMISSIONS[kind]
for (const permissions of [
[],
[P.page],
[P.detailPage],
[P.detail],
[P.detailPage, P.detail]
]) {
const allowed = permissions.includes(P.detailPage) && permissions.includes(P.detail)
const h = mount(schedulerDetailPath, {
props: { kind },
permissions,
services: { [method]: () => ok({ id: 1, carrier_id: 8, card_id: 0, status: 3 }) }
})
await h.state.load()
assert.equal(h.calls.length, allowed ? 1 : 0, permissions.join(','))
assert.equal(!!h.state.data.value, allowed)
h.dispose()
}
for (const userType of [1, 3, 4]) {
const allowed = kind !== 'imports' || userType === 1
const h = mount(schedulerDetailPath, {
props: { kind },
userType,
permissions: [P.detailPage, P.detail],
services: { [method]: () => ok({ id: 1, status: 3 }) }
})
await h.state.load()
assert.equal(h.calls.length, allowed ? 1 : 0)
assert.equal(!!h.state.data.value, allowed)
h.dispose()
}
})
test('revoking either detail permission clears displayed data and blocks subsequent refresh', async () => {
for (const kind of ['params', 'alerts', 'imports']) {
const P = constants.SCHEDULER_PERMISSIONS[kind]
for (const revoked of [P.detailPage, P.detail]) {
const permissions = vue.reactive([P.detailPage, P.detail])
const h = mount(schedulerDetailPath, { props: { kind }, permissions })
await h.state.load()
assert.ok(h.state.data.value)
permissions.splice(permissions.indexOf(revoked), 1)
assert.equal(h.state.data.value, null)
await h.state.load()
assert.equal(h.calls.length, 1)
h.dispose()
}
}
})
test('pending detail responses cannot appear after the detail permission is revoked', async () => {
for (const [kind, method] of [
['params', 'getCarrierParam'],
['alerts', 'getAlert'],
['imports', 'getImport']
]) {
const P = constants.SCHEDULER_PERMISSIONS[kind]
const permissions = vue.reactive([P.detailPage, P.detail])
let resolve
const response = new Promise((done) => {
resolve = done
})
const h = mount(schedulerDetailPath, {
props: { kind },
permissions,
services: { [method]: () => response }
})
const pending = h.state.load()
permissions.splice(permissions.indexOf(P.detail), 1)
resolve(ok({ id: 1, status: 3 }))
await pending
assert.equal(h.state.data.value, null)
assert.equal(h.state.loading.value, false)
assert.equal(h.calls.length, 1)
h.dispose()
}
})
test('22 scheduler methods preserve exact HTTP paths, bodies, null and false', async () => {
const calls = []
class BaseService {}