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>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Billing::ConfirmBankTransfer do
|
||||
let(:admin) { AdminAccount.create!(username: "ops-bt", password: "Password123") }
|
||||
let(:user) { User.create!(email: "owner-confirm@test.it", name: "Coach", password: "Password123", role: "coach") }
|
||||
let(:club) do
|
||||
c = Club.create!(
|
||||
name: "Confirm Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff",
|
||||
billing_entity_type: "company", billing_legal_name: "ASD Confirm", billing_email: "fatture@confirm.test",
|
||||
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
|
||||
|
||||
def request_order
|
||||
Billing::RequestBankTransfer.call(club: club, user: user, plan_slug: "premium_full", interval: "yearly")
|
||||
end
|
||||
|
||||
it "attiva il piano e invia la mail di attivazione senza PDF" do
|
||||
order = request_order
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
described_class.call(order: order, admin: admin)
|
||||
|
||||
sub = club.reload.subscription
|
||||
expect(sub.plan.slug).to eq("premium_full")
|
||||
expect(sub).to be_bank_transfer
|
||||
expect(sub.cancel_at_period_end).to be true
|
||||
expect(sub.current_period_end).to be_within(2.seconds).of(1.year.from_now)
|
||||
expect(order.reload).to be_paid
|
||||
expect(order.billing_payment.status).to eq("paid")
|
||||
expect(ActionMailer::Base.deliveries.last.subject).to include("Premium Full")
|
||||
end
|
||||
|
||||
it "con PDF invia una sola email di attivazione con fattura" do
|
||||
order = request_order
|
||||
ActionMailer::Base.deliveries.clear
|
||||
pdf = { io: StringIO.new("%PDF-1.4 test"), filename: "fattura.pdf", content_type: "application/pdf" }
|
||||
|
||||
expect {
|
||||
described_class.call(order: order, admin: admin, pdf: pdf)
|
||||
}.to change { ActionMailer::Base.deliveries.size }.by(1)
|
||||
|
||||
expect(order.billing_payment.reload.invoice.pdf).to be_attached
|
||||
expect(ActionMailer::Base.deliveries.last.subject).to include("fattura")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user