deleted-user-session.test.js 1.1 KB

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