db3dba1e96
- 合入 weiyuan 新功能前端:分佣 V2 / 伙伴工作台、智能路由、企业资金与分析、官网设置与预约演示等, semi-ui 已全部迁移到 antd 6 / @/components/ui,不重新引入 Semi - 分佣二级菜单与页头去重、伙伴入口探测(企业伙伴走企业中心「企业分佣」)、超管侧栏入口恢复 - 适配层 DatePicker / TimePicker 统一 onChange(Date|Date[]|null, 文本) 契约;生产构建剔除调试日志 - 图片链接刷新:同任务请求复用、后台刷新不弹全局错误、离页停止批量请求 - 恢复 bun.lock(与 package-lock.json 共存);docs 规范与 CHANGELOG 更新 - 停止跟踪 .env.playwright.local(本地登录凭据,已加入 .gitignore)
168 lines
4.4 KiB
JavaScript
168 lines
4.4 KiB
JavaScript
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
getInitialOperationForm,
|
|
validateContractSignedConversion,
|
|
partnerIdentityPayload,
|
|
levelBindingPayload,
|
|
} from './operationForm.js';
|
|
|
|
test('company payload requires only organization and omits legacy administrator identity', () => {
|
|
assert.deepEqual(
|
|
partnerIdentityPayload({
|
|
type: 'company',
|
|
name: '企业',
|
|
organization_id: 44,
|
|
user_id: 9,
|
|
}),
|
|
{ type: 'company', name: '企业', organization_id: 44 },
|
|
);
|
|
assert.throws(
|
|
() =>
|
|
partnerIdentityPayload({
|
|
type: 'individual',
|
|
name: '个人',
|
|
organization_id: 44,
|
|
}),
|
|
/身份/,
|
|
);
|
|
assert.deepEqual(
|
|
partnerIdentityPayload({
|
|
type: 'individual',
|
|
name: '个人',
|
|
user_id: 9,
|
|
organization_id: 44,
|
|
}),
|
|
{ type: 'individual', name: '个人', user_id: 9 },
|
|
);
|
|
});
|
|
|
|
test('binding submits configuration identity and selected time for server-side version resolution', () => {
|
|
assert.deepEqual(
|
|
levelBindingPayload(
|
|
{ config_id: 55, tier_id: 999, effective_from: 123 },
|
|
{ type: 'enterprise', key: 'gold' },
|
|
),
|
|
{
|
|
config_id: 55,
|
|
effective_from: 123,
|
|
level_type: 'enterprise',
|
|
level_key: 'gold',
|
|
},
|
|
);
|
|
assert.throws(
|
|
() =>
|
|
levelBindingPayload(
|
|
{ config_id: 55, effective_from: 123 },
|
|
{ type: 'enterprise', key: 'default' },
|
|
),
|
|
/默认/,
|
|
);
|
|
});
|
|
|
|
test('contract signing validation explains when the signed date is after conversion time', () => {
|
|
assert.equal(
|
|
validateContractSignedConversion(
|
|
{
|
|
reference: '1488999',
|
|
contract_subject: '测试公司',
|
|
signed_at: 1_000,
|
|
fact_at: 900,
|
|
},
|
|
(key) => key,
|
|
),
|
|
'合同签署日期不能晚于实际转化事实时间',
|
|
);
|
|
});
|
|
|
|
test('contract signing validation accepts a signed date at or before conversion time', () => {
|
|
assert.equal(
|
|
validateContractSignedConversion(
|
|
{
|
|
reference: '1488999',
|
|
contract_subject: '测试公司',
|
|
signed_at: 900,
|
|
fact_at: 900,
|
|
},
|
|
(key) => key,
|
|
),
|
|
'',
|
|
);
|
|
});
|
|
|
|
test('tier editing hydrates legacy channels and starts a new effective version', () => {
|
|
const form = getInitialOperationForm(
|
|
{
|
|
kind: 'tier-create',
|
|
row: { id: 12, source_type: 'channel', source_id: 7, effective_from: 10 },
|
|
},
|
|
200000,
|
|
);
|
|
assert.deepEqual(form.channel_ids, [7]);
|
|
assert.equal(form.previous_tier_id, 12);
|
|
assert.equal(form.effective_from, 200);
|
|
});
|
|
|
|
test('shared tier editing preserves every model or channel target', () => {
|
|
const form = getInitialOperationForm({
|
|
kind: 'tier-create',
|
|
row: {
|
|
id: 13,
|
|
source_type: 'model',
|
|
model_names: ['gpt-4o', 'gpt-4o-mini'],
|
|
},
|
|
});
|
|
assert.deepEqual(form.model_names, ['gpt-4o', 'gpt-4o-mini']);
|
|
assert.deepEqual(form.channel_ids, []);
|
|
});
|
|
|
|
test('new partner form always starts in draft status', () => {
|
|
const form = getInitialOperationForm(
|
|
{
|
|
kind: 'partner-create',
|
|
row: { status: 'protected', display_name: '测试伙伴' },
|
|
},
|
|
1_700_000_000_000,
|
|
);
|
|
|
|
assert.equal(form.status, 'draft');
|
|
assert.equal(form.display_name, '测试伙伴');
|
|
});
|
|
|
|
test('customer assignment form keeps protected status', () => {
|
|
const form = getInitialOperationForm(
|
|
{ kind: 'assignment-create', row: {} },
|
|
1_700_000_000_000,
|
|
);
|
|
|
|
assert.equal(form.status, 'protected');
|
|
});
|
|
|
|
test('editing a partner preserves the row status', () => {
|
|
const form = getInitialOperationForm(
|
|
{ kind: 'partner-edit', row: { status: 'active' } },
|
|
1_700_000_000_000,
|
|
);
|
|
|
|
assert.equal(form.status, 'active');
|
|
});
|