import { describe, expect, it } from "vitest";
import { buildUserBasicInfoPayload } from "./user-basic-info-payload";

const user = {
  id: 37,
  avatar: "https://example.com/avatar.png",
  balance: 1200,
  commission: 300,
  referral_percentage: 10,
  only_first_purchase: true,
  gift_amount: 500,
  telegram: 123_456,
  refer_code: "INVITE37",
  referer_id: 7,
  enable: true,
  is_admin: false,
  enable_balance_notify: true,
  enable_login_notify: true,
  enable_subscribe_notify: false,
  enable_trade_notify: false,
  user_group_id: 2,
  group_locked: false,
  auth_methods: [],
  user_devices: [],
  remark: "old remark",
  rules: [],
  created_at: 1_700_000_000,
  updated_at: 1_700_000_100,
} satisfies API.User;

describe("buildUserBasicInfoPayload", () => {
  it("keeps the full basic user fields when updating a remark", () => {
    expect(buildUserBasicInfoPayload(user, "new remark")).toEqual({
      user_id: 37,
      avatar: "https://example.com/avatar.png",
      balance: 1200,
      commission: 300,
      referral_percentage: 10,
      only_first_purchase: true,
      gift_amount: 500,
      telegram: 123_456,
      refer_code: "INVITE37",
      referer_id: 7,
      enable: true,
      is_admin: false,
      remark: "new remark",
    });
  });

  it("preserves an intentionally cleared remark", () => {
    expect(buildUserBasicInfoPayload(user, "").remark).toBe("");
  });
});
