import test from 'node:test'; import assert from 'node:assert/strict'; import { createRemoteConfig } from '../../YouleNexus/assets/framework/config/remote-config.ts'; import type { RuntimeConfig } from '../../YouleNexus/assets/framework/config/runtime-config.ts'; import { resolveSharePolicy,sharePayload,resolveQrCodePolicy } from '../../YouleNexus/assets/framework/presentation/share-model.ts'; test('QR entry uses scoped WechatPublicNo_ewm and exact image share parameters',()=>{ const identity={agentid:'a',channelid:'c',gameid:'g',marketid:4,version:1}; const config=(data:Record)=>({identity,remoteConfig:createRemoteConfig(data,identity)} as RuntimeConfig); assert.equal(resolveQrCodePolicy(config({})),null); const result=resolveQrCodePolicy(config({WechatPublicNo_ewm:'root.png',agentlist:[{agentid:'a',WechatPublicNo_ewm:'https://example.test/qr.png'}],sharename:'标题',shareDesc:'说明'})); assert.deepEqual(result,{url:'https://example.test/qr.png',share:{sharefriend:1,type:3,webpageUrl:'https://example.test/qr.png',title:'标题说明',description:undefined,sharetype:0}}); assert.throws(()=>resolveQrCodePolicy(config({WechatPublicNo_ewm:123})),/WechatPublicNo_ewm/); }); test('share reads url_download and preserves original friend and timeline payloads',()=>{ const identity={agentid:'a',channelid:'c',gameid:'g',marketid:4,version:1}; const remoteConfig=createRemoteConfig({url_download:'https://example.test/app',sharename:'标题',hall_config:{shareDesc:'描述',shareType:1,shareImgUrl:'https://example.test/share.png'}},identity); const policy=resolveSharePolicy({identity,remoteConfig} as RuntimeConfig); assert.equal(policy.url,'https://example.test/app?agentid=a&channelid=c&gameid=g&marketid=4'); assert.deepEqual(sharePayload(policy,1),{sharefriend:1,type:1,webpageUrl:policy.url,title:'标题',description:'描述',sharetype:0}); assert.deepEqual(sharePayload(policy,2),{sharefriend:2,type:3,webpageUrl:'https://example.test/share.png',title:'标题描述',description:undefined,sharetype:0}); assert.equal(sharePayload({...policy,imageTimeline:false},2),null); });