Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { nativeSettingsSource } from '../../../YouleNexus/assets/framework/config/sources/native-settings.ts';
|
|
|
|
test('优先从 window.settings 读取 agentid/channelid/marketid', () => {
|
|
const win = {
|
|
settings: {
|
|
getothername: (name: string) => (name === 'agent' ? 'NA' : ''),
|
|
getchannelName: () => 'NC',
|
|
getmarketname: () => 7,
|
|
},
|
|
};
|
|
assert.deepEqual(nativeSettingsSource(win)(), { agentid: 'NA', channelid: 'NC', marketid: 7 });
|
|
});
|
|
|
|
test('settings 抛错时回退到全局 app_agent / app_market', () => {
|
|
const win: any = {
|
|
settings: { getothername: () => { throw new Error('no bridge'); },
|
|
getchannelName: () => { throw new Error('no bridge'); },
|
|
getmarketname: () => { throw new Error('no bridge'); } },
|
|
app_agent: 'GA',
|
|
app_market: 5,
|
|
};
|
|
assert.deepEqual(nativeSettingsSource(win)(), { agentid: 'GA', marketid: 5 });
|
|
});
|
|
|
|
test('完全无原生注入 → 空对象', () => {
|
|
assert.deepEqual(nativeSettingsSource({})(), {});
|
|
});
|