feat: 用户多应用成员关系与微信扫码登录
- 新增 user_app / user_identity 模型、应用注册表与成员关系服务,启动时校验配置覆盖 - 新增微信开放平台扫码登录:二维码地址、回调与 ticket 换取 token - 管理端接口改为路由层声明 appIds + 角色鉴权,新增批量用户信息、锁定、授权与个人配置 - 删除账号同步清理成员关系与外部身份,避免关系被新账号复用 - 补充多应用、应用配置、注册表测试与迁移/建号脚本
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
hasConfigSchema,
|
||||
validateAppConfig,
|
||||
resolveConfig,
|
||||
flattenLeaves,
|
||||
plainConfig,
|
||||
} from '../models/app_config.js';
|
||||
|
||||
describe('validateAppConfig', () => {
|
||||
it('接受已声明字段', () => {
|
||||
const value = validateAppConfig('wxapp-escort', {
|
||||
theme: 'dark',
|
||||
notifications: { marketing: false },
|
||||
});
|
||||
assert.equal(value.theme, 'dark');
|
||||
assert.equal(value.notifications.marketing, false);
|
||||
});
|
||||
|
||||
it('拒绝未声明 key(不能借 config 改权限)', () => {
|
||||
assert.throws(
|
||||
() => validateAppConfig('wxapp-escort', { role: ['admin'] }),
|
||||
/not allowed/
|
||||
);
|
||||
});
|
||||
|
||||
it('拒绝非法枚举值', () => {
|
||||
assert.throws(() => validateAppConfig('wxapp-escort', { theme: 'blue' }));
|
||||
});
|
||||
|
||||
it('未配置 schema 的应用抛错', () => {
|
||||
assert.equal(hasConfigSchema('ttapp-escort'), false);
|
||||
assert.throws(() => validateAppConfig('ttapp-escort', { theme: 'dark' }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveConfig', () => {
|
||||
it('空配置返回默认值', () => {
|
||||
assert.deepEqual(resolveConfig('wxapp-escort', {}), {
|
||||
theme: 'system',
|
||||
language: 'zh-CN',
|
||||
notifications: { orderStatus: true, marketing: false },
|
||||
});
|
||||
});
|
||||
|
||||
it('嵌套对象做一层深合并', () => {
|
||||
const config = resolveConfig('wxapp-escort', {
|
||||
notifications: { marketing: true },
|
||||
});
|
||||
assert.equal(config.notifications.marketing, true);
|
||||
assert.equal(config.notifications.orderStatus, true);
|
||||
});
|
||||
|
||||
it('兼容 Map 存储', () => {
|
||||
const config = resolveConfig('wxapp-escort-admin', new Map([['pageSize', 50]]));
|
||||
assert.equal(config.pageSize, 50);
|
||||
assert.equal(config.soundAlert, true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('flattenLeaves', () => {
|
||||
it('展开嵌套对象为叶子路径', () => {
|
||||
assert.deepEqual(flattenLeaves({ notifications: { marketing: false } }), {
|
||||
'notifications.marketing': false,
|
||||
});
|
||||
});
|
||||
|
||||
it('数组和标量整体替换', () => {
|
||||
assert.deepEqual(flattenLeaves({ list: [1, 2], theme: 'dark' }), {
|
||||
list: [1, 2],
|
||||
theme: 'dark',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('plainConfig', () => {
|
||||
it('Map 与普通对象都返回普通对象', () => {
|
||||
assert.deepEqual(plainConfig(new Map([['a', 1]])), { a: 1 });
|
||||
assert.deepEqual(plainConfig({ a: 1 }), { a: 1 });
|
||||
assert.deepEqual(plainConfig(null), {});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user