IBAN e causale restano da comunicare a mano dall'admin; la richiesta registra solo l'ordine in attesa. Co-authored-by: Cursor <cursoragent@cursor.com>
76 lines
3.0 KiB
Ruby
76 lines
3.0 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 l'ordine a listino senza inviare 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(0)
|
|
|
|
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 "non reinvia istruzioni se l'ordine è già in attesa" do
|
|
first = described_class.call(club: club, user: user, plan_slug: "premium_light", interval: "yearly")
|
|
ActionMailer::Base.deliveries.clear
|
|
|
|
expect {
|
|
second = described_class.call(club: club, user: user, plan_slug: "premium_light", interval: "yearly")
|
|
expect(second.id).to eq(first.id)
|
|
}.not_to change { ActionMailer::Base.deliveries.size }
|
|
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
|