import { describe, expect, it } from "vitest";
import { getOrganizationUpgradeBlockReason } from "./stripe";

describe("getOrganizationUpgradeBlockReason", () => {
  it("returns no_plan when the organization has no active subscription", () => {
    expect(
      getOrganizationUpgradeBlockReason({
        is_trial_expired: false,
        required_plan: "solo",
        required_team_quantity: 1,
        active_subscription_plan: null,
        active_subscription_quantity: 0,
      })
    ).toBe("no_plan");
  });

  it("returns trial_expired when a paid plan no longer covers the organization", () => {
    expect(
      getOrganizationUpgradeBlockReason({
        is_trial_expired: true,
        required_plan: "team",
        required_team_quantity: 3,
        active_subscription_plan: "team",
        active_subscription_quantity: 1,
      })
    ).toBe("trial_expired");
  });

  it("returns null when the organization is compliant", () => {
    expect(
      getOrganizationUpgradeBlockReason({
        is_trial_expired: true,
        required_plan: "solo",
        required_team_quantity: 1,
        active_subscription_plan: "annual",
        active_subscription_quantity: 1,
      })
    ).toBe(null);
  });
});
