Files
MatchLiveTv/backend/spec/services/billing/request_bank_transfer_spec.rb
eminuxandCursor e436f5ece4 Aggiunge pagamento con bonifico e importo concordato per società.
Il piano si attiva solo dopo la conferma admin; Stripe resta a listino se non c'è un prezzo commerciale.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-18 23:20:43 +02:00

66 lines
2.6 KiB
Ruby

require "rails_helper"
RSpec.describe Billing::RequestBankTransfer do
let(:user) { User.create!(email: "owner-bt@test.it", name: "Coach", password: "Password123", role: "coach") }
let(:club) do
c = Club.create!(
name: "Bonifico Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff",
billing_entity_type: "company", billing_legal_name: "ASD Bonifico", billing_email: "bill@test.it",
billing_address_line: "Via 1", billing_city: "Milano", billing_province: "MI", billing_postal_code: "20100",
billing_country: "IT", billing_vat_number: "12345678901", billing_recipient_code: "ABCDEFG"
)
ClubMembership.create!(user: user, club: c, role: "owner")
load Rails.root.join("db/seeds/plans.rb")
Billing::AssignPlan.call(club: c, plan_slug: "free")
c
end
before do
allow(MatchLiveTv).to receive_messages(
bank_transfer_configured?: true,
bank_transfer_iban: "IT60X0542811101000000123456",
bank_transfer_account_holder: "Match Live TV",
bank_transfer_bank_name: "Banca Test",
bank_transfer_bic: "TESTITMM",
bank_transfer_proof_email: "info@matchlivetv.it"
)
end
it "crea un ordine a listino e invia le istruzioni" do
expect {
described_class.call(club: club, user: user, plan_slug: "premium_light", interval: "yearly")
}.to change { club.billing_transfer_orders.count }.by(1)
.and change { ActionMailer::Base.deliveries.size }.by(1)
order = club.billing_transfer_orders.last
expect(order).to be_awaiting_payment
expect(order.kind).to eq("list_price")
expect(order.amount_cents).to eq(5900)
expect(order.billing_payment.status).to eq("pending")
expect(order.billing_payment.provider).to eq("bank_transfer")
expect(club.reload.subscription.plan.slug).to eq("free")
end
it "usa l'importo concordato se presente" do
Billing::SetClubQuote.upsert(
club: club, plan_slug: "premium_full", interval: "yearly",
amount_euros: "150", note: "Accordo 2026", admin: nil
)
order = described_class.call(club: club, user: user, plan_slug: "premium_full", interval: "yearly")
expect(order.kind).to eq("commercial_quote")
expect(order.amount_cents).to eq(15_000)
end
it "rifiuta un piano diverso dal prezzo concordato" do
Billing::SetClubQuote.upsert(
club: club, plan_slug: "premium_full", interval: "yearly",
amount_euros: "150", note: nil, admin: nil
)
expect {
described_class.call(club: club, user: user, plan_slug: "premium_light", interval: "yearly")
}.to raise_error(Billing::RequestBankTransfer::Error, /prezzo concordato/)
end
end