Dopo la conferma admin la card restava su «Paga con bonifico»; la società parte da Free, l'owner è staff trasmissione e le mail non bloccano se manca SMTP. Co-authored-by: Cursor <cursoragent@cursor.com>
148 lines
4.9 KiB
Ruby
148 lines
4.9 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Public::BillingHelper, type: :helper do
|
|
before do
|
|
load Rails.root.join("db/seeds/plans.rb")
|
|
allow(MatchLiveTv).to receive(:stripe_enabled?).and_return(true)
|
|
allow(MatchLiveTv).to receive(:stripe_premium_light_yearly_price_id).and_return("py")
|
|
allow(MatchLiveTv).to receive(:stripe_premium_light_monthly_price_id).and_return("pm")
|
|
allow(MatchLiveTv).to receive(:stripe_premium_full_yearly_price_id).and_return("fy")
|
|
allow(MatchLiveTv).to receive(:stripe_premium_full_monthly_price_id).and_return("fm")
|
|
end
|
|
|
|
let(:premium_light) { Plan["premium_light"] }
|
|
let(:premium_full) { Plan["premium_full"] }
|
|
|
|
it "propone due opzioni checkout da free" do
|
|
action = helper.plan_billing_action(
|
|
current_slug: "free",
|
|
target_plan: premium_light,
|
|
stripe_subscription_active: false
|
|
)
|
|
expect(action[:kind]).to eq(:checkout_options)
|
|
expect(action[:intervals]).to eq(%w[monthly yearly])
|
|
end
|
|
|
|
it "segna piano corrente quando non ci sono altri intervalli" do
|
|
allow(MatchLiveTv).to receive(:stripe_premium_light_monthly_price_id).and_return(nil)
|
|
action = helper.plan_billing_action(
|
|
current_slug: "premium_light",
|
|
target_plan: premium_light,
|
|
stripe_subscription_active: true,
|
|
current_interval: "yearly"
|
|
)
|
|
expect(action[:kind]).to eq(:current)
|
|
expect(action[:label]).to include("€59/anno")
|
|
end
|
|
|
|
it "propone cambio intervallo sullo stesso piano" do
|
|
action = helper.plan_billing_action(
|
|
current_slug: "premium_light",
|
|
target_plan: premium_light,
|
|
stripe_subscription_active: true,
|
|
current_interval: "yearly"
|
|
)
|
|
expect(action[:kind]).to eq(:interval_switch)
|
|
expect(action[:intervals]).to eq(["monthly"])
|
|
end
|
|
|
|
it "propone upgrade con opzioni intervallo" do
|
|
action = helper.plan_billing_action(
|
|
current_slug: "premium_light",
|
|
target_plan: premium_full,
|
|
stripe_subscription_active: true,
|
|
current_interval: "yearly"
|
|
)
|
|
expect(action[:kind]).to eq(:change_options)
|
|
expect(action[:intervals].size).to eq(2)
|
|
end
|
|
|
|
it "stile annuale pieno e mensile outline" do
|
|
expect(helper.plan_interval_button_class("yearly")).to include("btn-primary")
|
|
expect(helper.plan_interval_button_class("yearly")).not_to include("btn-outline")
|
|
expect(helper.plan_interval_button_class("monthly")).to include("btn-outline")
|
|
expect(helper.plan_interval_button_class("monthly")).not_to include("btn-primary")
|
|
end
|
|
|
|
it "mostra prima il pulsante annuale" do
|
|
expect(helper.plan_intervals_for_display(%w[monthly yearly])).to eq(%w[yearly monthly])
|
|
end
|
|
|
|
it "sulla card Free non mostra testo se c'è abbonamento Stripe" do
|
|
action = helper.plan_billing_action(
|
|
current_slug: "premium_full",
|
|
target_plan: Plan["free"],
|
|
stripe_subscription_active: true
|
|
)
|
|
expect(action[:kind]).to eq(:none)
|
|
end
|
|
|
|
it "con prezzo concordato non pagato resta sul bonifico" do
|
|
quote = instance_double(Billing::ClubQuote, plan_slug: "premium_full", price_label: "€99/anno", billing_interval: "yearly")
|
|
club = instance_double(Club, active_billing_quote: quote)
|
|
subscription = instance_double(
|
|
Subscription,
|
|
active?: true,
|
|
premium?: false,
|
|
plan_change_pending?: false,
|
|
plan: Plan["free"]
|
|
)
|
|
|
|
action = helper.plan_billing_action(
|
|
current_slug: "free",
|
|
target_plan: premium_full,
|
|
stripe_subscription_active: false,
|
|
subscription: subscription,
|
|
club: club
|
|
)
|
|
expect(action[:kind]).to eq(:quoted)
|
|
expect(action[:quote]).to eq(quote)
|
|
end
|
|
|
|
it "con prezzo concordato già pagato mostra il piano attivo" do
|
|
quote = instance_double(Billing::ClubQuote, plan_slug: "premium_full", price_label: "€99/anno")
|
|
club = instance_double(Club, active_billing_quote: quote)
|
|
subscription = instance_double(
|
|
Subscription,
|
|
active?: true,
|
|
premium?: true,
|
|
plan_change_pending?: false,
|
|
plan: premium_full,
|
|
billing_interval: "yearly"
|
|
)
|
|
|
|
action = helper.plan_billing_action(
|
|
current_slug: "premium_full",
|
|
target_plan: premium_full,
|
|
stripe_subscription_active: false,
|
|
current_interval: "yearly",
|
|
subscription: subscription,
|
|
club: club
|
|
)
|
|
expect(action[:kind]).to eq(:current)
|
|
expect(action[:label]).to include("Piano attivo")
|
|
expect(action[:label]).to include("€99/anno")
|
|
end
|
|
|
|
it "con bonifico già attivo senza Stripe mostra il piano corrente" do
|
|
subscription = instance_double(
|
|
Subscription,
|
|
active?: true,
|
|
premium?: true,
|
|
plan_change_pending?: false,
|
|
plan: premium_full,
|
|
billing_interval: "yearly"
|
|
)
|
|
|
|
action = helper.plan_billing_action(
|
|
current_slug: "premium_full",
|
|
target_plan: premium_full,
|
|
stripe_subscription_active: false,
|
|
current_interval: "yearly",
|
|
subscription: subscription
|
|
)
|
|
expect(action[:kind]).to eq(:current)
|
|
expect(action[:label]).to include("Piano attivo")
|
|
end
|
|
end
|