/* 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 { mergeChannelSettings } from './baiduChannelSettings.js'; test('channel form preserves unknown and existing settings while changing mode', () => { const saved = JSON.stringify({ proxy: 'http://proxy', future_field: { value: 7 }, baidu_liveness_header_mode: 'legacy', }); const updated = JSON.parse( mergeChannelSettings(saved, { proxy: 'http://new-proxy' }, 62, 'omit'), ); assert.deepEqual(updated, { proxy: 'http://new-proxy', future_field: { value: 7 }, baidu_liveness_header_mode: 'omit', }); assert.equal( JSON.parse(mergeChannelSettings('', {}, 62, undefined)) .baidu_liveness_header_mode, 'legacy', ); assert.deepEqual( JSON.parse(mergeChannelSettings(saved, {}, 61, 'omit')), JSON.parse(saved), ); }); test('invalid saved settings and mode fail without silent replacement', () => { for (const raw of ['null', '[]', '{bad']) assert.throws(() => mergeChannelSettings(raw, {}, 62, 'omit')); for (const mode of ['other', false, null]) assert.throws(() => mergeChannelSettings('{}', {}, 62, mode)); });