This commit is contained in:
@@ -4,6 +4,7 @@ const storage = {}
|
||||
const requests = []
|
||||
const navigations = []
|
||||
const scheduled = []
|
||||
const modals = []
|
||||
let clearedSessions = 0
|
||||
let globalData = { wechatLoginState: { status: 'SUCCESS', accessToken: 'expired-token' } }
|
||||
|
||||
@@ -15,6 +16,7 @@ global.wx = {
|
||||
removeStorageSync: key => { delete storage[key] },
|
||||
request: options => requests.push(options),
|
||||
showToast: () => {},
|
||||
showModal: options => modals.push(options),
|
||||
reLaunch: options => navigations.push(options.url)
|
||||
}
|
||||
global.getApp = () => ({
|
||||
@@ -45,6 +47,18 @@ async function rejectWithUnauthorized(options) {
|
||||
return pending
|
||||
}
|
||||
|
||||
async function rejectWithAgreementRequired(options, message) {
|
||||
const pending = request(options).then(
|
||||
() => { throw new Error('Expected request to reject') },
|
||||
error => error
|
||||
)
|
||||
requests[requests.length - 1].success({
|
||||
statusCode: 200,
|
||||
data: { code: 4510, message }
|
||||
})
|
||||
return pending
|
||||
}
|
||||
|
||||
async function run() {
|
||||
auth.setSession({ accessToken: 'expired-token' }, true)
|
||||
|
||||
@@ -70,6 +84,21 @@ async function run() {
|
||||
assert.strictEqual(scheduled.length, 1)
|
||||
scheduled.shift()()
|
||||
assert.deepStrictEqual(navigations, ['/pages/login/index', '/pages/login/index'])
|
||||
|
||||
const agreementMessage = '用户协议与隐私政策已更新(当前版本 2026.11.04-R2),请阅读并同意后继续使用'
|
||||
auth.setSession({ accessToken: 'agreement-token' }, true)
|
||||
const agreementError = await rejectWithAgreementRequired({ url: '/manager/calendar' }, agreementMessage)
|
||||
assert.strictEqual(agreementError.message, agreementMessage)
|
||||
assert.strictEqual(modals.length, 1)
|
||||
assert.strictEqual(clearedSessions, 3)
|
||||
assert.strictEqual(globalData.wechatLoginState, null)
|
||||
|
||||
const duplicatedError = await rejectWithAgreementRequired({ url: '/manager/customers' }, agreementMessage)
|
||||
assert.strictEqual(duplicatedError.message, agreementMessage)
|
||||
assert.strictEqual(modals.length, 1)
|
||||
|
||||
modals[0].success()
|
||||
assert.deepStrictEqual(navigations, ['/pages/login/index', '/pages/login/index', '/pages/login/index'])
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
|
||||
Reference in New Issue
Block a user