import { expect, test } from "vitest";
import { aggregateMetricMaps, metricTooltip } from "./metrics.js";

test("describes recharge metrics with the Finance source of truth", () => {
  expect(metricTooltip("recharge_usd_minor")).toContain("Finance 口径");
  expect(metricTooltip("google_recharge_usd_minor")).toContain("Google 成功充值");
  expect(metricTooltip("mifapay_recharge_usd_minor")).toContain("非 Google 三方成功充值");
  expect(metricTooltip("coin_seller_recharge_usd_minor")).toContain("已核验币商充值订单 + H5 币商身份成功充值");
  expect(metricTooltip("arppu_usd_minor")).toContain("当前不展示");
});

test("keeps ARPU and ARPPU unavailable after aggregating Finance-aligned recharge", () => {
  const metrics = aggregateMetricMaps([
    { active_users: 10, finance_recharge_aligned: true, paid_users: 2, recharge_usd_minor: 600 },
    { active_users: 5, finance_recharge_aligned: true, paid_users: 1, recharge_usd_minor: 300 }
  ]);

  expect(metrics.recharge_usd_minor).toBe(900);
  expect(metrics.finance_recharge_aligned).toBe(true);
  expect(metrics.arpu_usd_minor).toBeNull();
  expect(metrics.arppu_usd_minor).toBeNull();
});
