| 123456789101112131415161718192021222324 |
- import test from 'node:test'
- import assert from 'node:assert/strict'
- import fs from 'node:fs'
- import path from 'node:path'
- const apiFile = path.resolve('common/api/index.js')
- const storeFile = path.resolve('common/stores/user.js')
- test('登录失效响应会清除小程序本地登录态', () => {
- const source = fs.readFileSync(apiFile, 'utf8')
- assert.match(source, /const clearLocalSession\s*=\s*\(\)\s*=>\s*\{[\s\S]*removeStorageSync\(['"]token['"]\)/)
- assert.match(source, /if\s*\([\s\S]*登录失效[\s\S]*\)\s*\{\s*clearLocalSession\(\)/)
- assert.match(source, /uni\.showModal\([\s\S]*\)\s*return response/)
- })
- test('主动退出登录会清除 token、用户信息和家庭成员缓存', () => {
- const source = fs.readFileSync(storeFile, 'utf8')
- assert.match(source, /clearSession\(\)[\s\S]*removeStorageSync\(['"]token['"]\)/)
- assert.match(source, /clearSession\(\)[\s\S]*removeStorageSync\(['"]userInfo['"]\)/)
- assert.match(source, /clearSession\(\)[\s\S]*removeStorageSync\(['"]familyMemberInfo['"]\)/)
- assert.match(source, /logout\(\)[\s\S]*this\.clearSession\(\)/)
- })
|