require "rails_helper"

RSpec.describe Billing::Stripe::InvoicePaymentRefs do
  it "legge payment_intent dalla raccolta payments (API Basil+)" do
    pi = double(id: "pi_new")
    payment = double(payment_intent: pi)
    invoice = double(
      payments: double(data: [double(payment: payment)])
    )

    expect(described_class.payment_intent_id(invoice)).to eq("pi_new")
    expect(described_class.charge_id(invoice)).to be_nil
  end

  it "non accede a payment_intent top-level sull'invoice" do
    invoice = double(payments: double(data: []))
    expect(invoice).not_to receive(:payment_intent)
    expect(described_class.payment_intent_id(invoice)).to be_nil
  end
end
