const assert = require('node:assert/strict'); const fs = require('node:fs'); const vm = require('node:vm'); const path = require('node:path'); const root = path.resolve(__dirname, '../..'); function load(file, api, service) { let page; vm.runInNewContext(fs.readFileSync(path.join(root, file), 'utf8'), { Page: value => { page = value; }, wx: { getStorageSync: () => 'test', showToast() {}, navigateBack() {} }, require: name => name.endsWith('/api') ? api : service, }); page.setData = data => Object.assign(page.data, data); return page; } (async () => { const id = '00000000-0000-0000-0000-000000000001'; const calls = []; const service = { referralService: { getMyReferralHistory: async () => [{ id, type: 'activity', activityId: id, activityDisplayId: 'HD20261014001', referralDisplayId: 'ZF20261014001', status: 'pending' }], confirmReferral: async (value, type) => { calls.push({ value, type }); }, } }; const referral = load('miniapp/pages/referral-confirmation/referral-confirmation.js', {}, service); await referral.load(); assert.equal(referral.data.referrals[0].detail, 'HD20261014001'); assert.equal(referral.data.referrals[0].referralDisplayId, 'ZF20261014001'); await referral.confirm({ currentTarget: { dataset: { index: 0 } } }); assert.equal(calls[0].value, id); assert.equal(calls[0].type, 'activity'); service.referralService.getMyReferralHistory = async () => [{ id, type: 'activity', activityId: id }]; await referral.load(); assert.equal(referral.data.referrals[0].detail, '公益活动'); const urls = []; const detail = load('miniapp/pages/matchmaker-service-detail/matchmaker-service-detail.js', { get: async url => { urls.push(url); return { serviceId: id, serviceDisplayId: 'FW20261014001', userDisplayNumber: 'YH20261014002', followups: [] }; }, }, {}); detail.data.serviceId = id; await detail.loadDetail(); assert.equal(urls[0], `/operator/matchmaker/services/${id}`); assert.equal(detail.data.detail.serviceDisplayId, 'FW20261014001'); const template = fs.readFileSync(path.join(root, 'miniapp/pages/matchmaker-service-detail/matchmaker-service-detail.wxml'), 'utf8'); assert(template.includes('detail.serviceDisplayId')); assert(!template.includes('{{detail.serviceId}}')); console.log('PASS: 小程序真实页面脚本显示业务编号、缺号不回退 UUID、确认和详情请求保留内部 UUID。'); })().catch(error => { console.error(error); process.exitCode = 1; });