/* 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 . 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'); });