fix: 轮询按运营商账户限流
All checks were successful
构建并部署前端到测试环境 / deploy (push) Successful in 55s

This commit is contained in:
luo
2026-10-26 14:31:15 +08:00
parent 049f8257fb
commit 06684e1fc0
88 changed files with 7919 additions and 486 deletions

View File

@@ -56,6 +56,8 @@ const carrier = (enabled) => ({
function harness(userType, responseCarrier = carrier(1)) {
const writes = []
const attempts = []
let list
const confirmations = []
const user = vue.reactive({ info: { user_type: userType }, permissions: [], buttons: [] })
const permission = evaluate(read('src/composables/usePermission.ts'), {
@@ -66,7 +68,17 @@ function harness(userType, responseCarrier = carrier(1)) {
getCarriers: async () => ({ code: 0, data: { items: [responseCarrier], total: 1 } }),
getCarrierDetail: async () => ({ code: 0, data: responseCarrier }),
createCarrier: async (data) => writes.push({ method: 'create', data: { ...data } }),
updateCarrier: async (id, data) => writes.push({ method: 'update', id, data: { ...data } })
updateCarrier: async (id, data) => {
attempts.push({ id, data: { ...data } })
if (
list?.originalRealnameControlEnabled.value === 0 &&
data.realname_control_enabled === 1 &&
!data.realname_control_confirm
)
throw new Error('开启实名管控将停机 12 张卡,请确认后重试')
writes.push({ method: 'update', id, data: { ...data } })
return { code: 0, data: responseCarrier }
}
}
const runtimeVue = { ...vue, onMounted: () => {} }
const imports = {
@@ -75,7 +87,7 @@ function harness(userType, responseCarrier = carrier(1)) {
'@vueuse/core': { useWindowSize: () => ({ width: vue.ref(1200) }) },
'@/api/modules': { CarrierService: service },
'element-plus': {
ElMessage: { success() {}, warning() {} },
ElMessage: { success() {}, warning() {}, error() {} },
ElMessageBox: {
confirm: async (...args) => {
confirmations.push(args)
@@ -102,8 +114,10 @@ function harness(userType, responseCarrier = carrier(1)) {
}
const setup = (name) =>
evaluate(components[name].script, imports, runtimeVue).default.setup({}, { expose() {} })
list = setup('index')
return {
list: setup('index'),
list,
attempts,
detail: setup('detail'),
writes,
confirmations,
@@ -189,8 +203,8 @@ test('editing then creating resets control state; default creation sends numeric
})
for (const userType of [1, 2]) {
test(`user_type=${userType}: enabling control requires confirmation before PUT and sends true`, async () => {
const { list, writes, confirmations, messageBox } = harness(userType)
test(`user_type=${userType}: initial PUT obtains actual impact before confirmed retry`, async () => {
const { list, writes, confirmations, messageBox, attempts } = harness(userType)
list.showDialog('edit', carrier(0))
list.form.realname_control_enabled = 1
let confirm
@@ -201,8 +215,11 @@ for (const userType of [1, 2]) {
})
}
const pending = list.handleSubmit(validForm)
await new Promise((resolve) => setImmediate(resolve))
assert.equal(confirmations.length, 1)
assert.match(confirmations[0][0], /未实名的开机卡会在下一次评估时被停机/)
assert.equal(confirmations[0][0], '开启实名管控将停机 12 张卡,请确认后重试')
assert.equal(attempts.length, 1)
assert.equal(attempts[0].data.realname_control_confirm, undefined)
assert.deepEqual(writes, [])
assert.equal(list.submitLoading.value, true)
await list.handleSubmit(validForm)
@@ -275,7 +292,7 @@ test('opening another carrier resets the original control state after a cancelle
assert.equal(Object.hasOwn(writes[0].data, 'realname_control_confirm'), false)
})
test('a failed PUT requires a fresh confirmation on retry', async (t) => {
test('an unrelated PUT error never triggers confirmation or automatic retry', async (t) => {
const { list, writes, confirmations, service } = harness(2)
t.mock.method(console, 'error', () => {})
list.showDialog('edit', carrier(0))
@@ -285,13 +302,13 @@ test('a failed PUT requires a fresh confirmation on retry', async (t) => {
throw new Error('PUT failed')
}
await list.handleSubmit(validForm)
assert.equal(confirmations.length, 1)
assert.equal(confirmations.length, 0)
assert.deepEqual(writes, [])
assert.equal(list.dialogVisible.value, true)
assert.equal(list.submitLoading.value, false)
service.updateCarrier = updateCarrier
await list.handleSubmit(validForm)
assert.equal(confirmations.length, 2)
assert.equal(confirmations.length, 1)
assert.equal(writes[0].data.realname_control_confirm, true)
})
@@ -353,6 +370,9 @@ test('carrier endpoints preserve the field in list/detail responses and create/u
calls.push({ method: 'PUT', url, data })
return Promise.resolve({ code: 0, data })
}
static put(url, data) {
return this.update(url, data)
}
}
const { CarrierService } = evaluate(read('src/api/modules/carrier.ts'), {
'../BaseService': { BaseService }