import { describe, expect, it, vi } from "vitest";

import { TipPaymentPlansResponse } from "@/data/dto/payment";
import { PaymentRepository } from "@/data/repositories/payment_repository";
import type { PaymentApi } from "@/data/services/api";
import { Result } from "@/utils/result";

describe("PaymentRepository", () => {
  it("adapts tip plans without caching them as subscription plans", async () => {
    const getTipPlans = vi.fn().mockResolvedValue(
      TipPaymentPlansResponse.from({
        plans: [
          {
            planId: "tip_coffee_usd_9_99",
            planName: "Medium Coffee",
            amountCents: 999,
            currency: "USD",
          },
        ],
      }),
    );
    const repository = new PaymentRepository({
      getTipPlans,
    } as unknown as PaymentApi);

    const result = await repository.getTipPlans();

    expect(getTipPlans).toHaveBeenCalledOnce();
    expect(Result.isOk(result) && result.data.plans[0]).toMatchObject({
      planId: "tip_coffee_usd_9_99",
      planName: "Medium Coffee",
      orderType: "tip",
      amountCents: 999,
      currency: "USD",
      isFirstRechargeOffer: false,
    });
  });
});
