team-invite-share.test.js 2.1 KB

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