v4.0.17企业微信API插件优化
This commit is contained in:
@@ -3,7 +3,10 @@ import { maskContactPhone } from './phone';
|
||||
import {
|
||||
clampWecomPluginPageSize,
|
||||
isWecomPluginEnabled,
|
||||
matchWecomPluginByApiKey,
|
||||
parseWecomPluginDateRange,
|
||||
parseWecomPluginMetricsKind,
|
||||
toWecomPluginMetricsView,
|
||||
toWecomPluginUserView,
|
||||
verifyWecomPluginApiKey,
|
||||
wecomPluginMetricsPeriod,
|
||||
@@ -23,6 +26,17 @@ describe('verifyWecomPluginApiKey', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('matchWecomPluginByApiKey', () => {
|
||||
it('returns the matching enabled instance', () => {
|
||||
const rows = [
|
||||
{ id: '1', apiKey: 'alpha-key-aaaa' },
|
||||
{ id: '2', apiKey: 'beta-key-bbbbb' },
|
||||
];
|
||||
expect(matchWecomPluginByApiKey('beta-key-bbbbb', rows)?.id).toBe('2');
|
||||
expect(matchWecomPluginByApiKey('missing', rows)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('isWecomPluginEnabled', () => {
|
||||
it('requires both the switch and a non-empty key', () => {
|
||||
expect(isWecomPluginEnabled({ WECOM_PLUGIN_ENABLED: 'true', WECOM_PLUGIN_API_KEY: 'k' })).toBe(
|
||||
@@ -52,6 +66,35 @@ describe('clampWecomPluginPageSize / parseWecomPluginMetricsKind', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseWecomPluginDateRange / toWecomPluginMetricsView', () => {
|
||||
it('parses YYYY-MM-DD range with inclusive end day', () => {
|
||||
const range = parseWecomPluginDateRange('2026-09-01', '2026-09-03');
|
||||
expect(range?.gte?.toISOString()).toBe(new Date('2026-09-01T00:00:00+08:00').toISOString());
|
||||
expect(range?.lt?.toISOString()).toBe(new Date('2026-09-04T00:00:00+08:00').toISOString());
|
||||
});
|
||||
|
||||
it('exposes newStores alias on metrics stats', () => {
|
||||
const view = toWecomPluginMetricsView({
|
||||
usersTotal: 1,
|
||||
usersIncrement: 0,
|
||||
partnersTotal: 1,
|
||||
partnersIncrement: 0,
|
||||
storesTotal: 10,
|
||||
storesIncrement: 2,
|
||||
ordersTotal: 0,
|
||||
ordersIncrement: 0,
|
||||
orderAmountTotal: 0,
|
||||
orderAmountIncrement: 0,
|
||||
redeemsTotal: 0,
|
||||
redeemsIncrement: 0,
|
||||
redeemAmountTotal: 0,
|
||||
redeemAmountIncrement: 0,
|
||||
});
|
||||
expect(view.newStores).toBe(2);
|
||||
expect(view.storesIncrement).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toWecomPluginUserView', () => {
|
||||
it('masks phone and fills empty nickname', () => {
|
||||
expect(toWecomPluginUserView({ userNo: 'DK1', nickname: null, phone: '13800138000' })).toEqual({
|
||||
|
||||
Reference in New Issue
Block a user