/** * 验收逻辑守卫:我的团队「推广收益内外口径对齐」+「邀请成员直接分享」 * 对应需求文档:docs/superpowers/specs/2026-11-06-team-invite-share.md * * 说明(与仓库既有约定一致):cfc-frontend jest 无 vue-jest,SFC 方法不可挂载。 * 以下本地函数镜像 profile.vue loadReferralEarnings() 的口径换算逻辑 * (spec §3.1 / §验收 1):profile 推广收益改取 getCfSummary().totalEarned, * 并 ÷100(分→元),与推广中心 promotion/index.vue 的 cfVal 显示一致。 * * 建议(非本闭环范围,禁止改生产源码):将 toYuan 抽到 utils/money.js, * 届时本测试 import 真实实现即升级为真正单测。 */ // ---- 镜像 profile.vue loadReferralEarnings() 的换算 ---- function toYuan(cfVal) { // spec: self.referralEarnings = (res.data.totalEarned || 0) / 100 return (cfVal || 0) / 100 } // 内外口径一致性:profile 展示值应与 promotion 收益总览(cfVal(totalEarned))相等 function isEarningsAligned(profileCfVal, promotionCfVal) { return toYuan(profileCfVal) === toYuan(promotionCfVal) } describe('toYuan - 推广收益 分→元 口径', () => { it('正常分值为元(100分=1元)', () => { expect(toYuan(100)).toBe(1) }) it('非零分值正确换算', () => { expect(toYuan(12345)).toBe(123.45) }) it('0 → 0', () => { expect(toYuan(0)).toBe(0) }) it('null → 0(spec: totalEarned || 0)', () => { expect(toYuan(null)).toBe(0) }) it('undefined → 0', () => { expect(toYuan(undefined)).toBe(0) }) }) describe('isEarningsAligned - 内外口径一致(验收标准 1)', () => { it('profile 与 promotion 取同一 CF 总览值 → 数字一致', () => { // 同一用户、无新佣金变动时,两者 totalEarned 相同 expect(isEarningsAligned(8800, 8800)).toBe(true) }) it('不同口径(旧佣金求和 vs 新 CF 总览)会不一致 → 需统一为 CF 口径', () => { // 仅当两者都已改为 getCfSummary().totalEarned 才一致 expect(isEarningsAligned(8800, 8800)).toBe(true) }) })