Add upgrade/downgrade options
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
require "test_helper"
|
||||
require "ostruct"
|
||||
|
||||
class Account::Subscriptions::DowngradesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in_as :kevin
|
||||
accounts(:"37s").subscription.update!(
|
||||
stripe_subscription_id: "sub_123",
|
||||
plan_key: Plan.paid_with_extra_storage.key
|
||||
)
|
||||
end
|
||||
|
||||
test "downgrade redirects to stripe billing portal" do
|
||||
stripe_subscription = OpenStruct.new(
|
||||
items: OpenStruct.new(data: [ OpenStruct.new(id: "si_123") ])
|
||||
)
|
||||
portal_session = OpenStruct.new(url: "https://billing.stripe.com/session/abc123")
|
||||
|
||||
Stripe::Subscription.stubs(:retrieve).with("sub_123").returns(stripe_subscription)
|
||||
Stripe::BillingPortal::Session.stubs(:create).returns(portal_session)
|
||||
|
||||
post account_subscription_downgrade_path
|
||||
|
||||
assert_redirected_to "https://billing.stripe.com/session/abc123"
|
||||
end
|
||||
|
||||
test "downgrade requires admin" do
|
||||
logout_and_sign_in_as :david
|
||||
|
||||
post account_subscription_downgrade_path
|
||||
assert_response :forbidden
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
require "test_helper"
|
||||
require "ostruct"
|
||||
|
||||
class Account::Subscriptions::UpgradesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in_as :kevin
|
||||
accounts(:"37s").subscription.update!(
|
||||
stripe_subscription_id: "sub_123",
|
||||
plan_key: Plan.paid.key
|
||||
)
|
||||
end
|
||||
|
||||
test "upgrade redirects to stripe billing portal" do
|
||||
stripe_subscription = OpenStruct.new(
|
||||
items: OpenStruct.new(data: [ OpenStruct.new(id: "si_123") ])
|
||||
)
|
||||
portal_session = OpenStruct.new(url: "https://billing.stripe.com/session/abc123")
|
||||
|
||||
Stripe::Subscription.stubs(:retrieve).with("sub_123").returns(stripe_subscription)
|
||||
Stripe::BillingPortal::Session.stubs(:create).returns(portal_session)
|
||||
|
||||
post account_subscription_upgrade_path
|
||||
|
||||
assert_redirected_to "https://billing.stripe.com/session/abc123"
|
||||
end
|
||||
|
||||
test "upgrade requires admin" do
|
||||
logout_and_sign_in_as :david
|
||||
|
||||
post account_subscription_upgrade_path
|
||||
assert_response :forbidden
|
||||
end
|
||||
end
|
||||
@@ -34,7 +34,7 @@ class Admin::AccountsControllerTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as :david
|
||||
|
||||
untenanted do
|
||||
patch saas.admin_account_path(accounts(:"37s").external_account_id), params: { account: { overridden_card_count: 500 } }
|
||||
patch saas.admin_account_path(accounts(:"37s").external_account_id), params: { account: { card_count: 500 } }
|
||||
assert_redirected_to saas.edit_admin_account_path(accounts(:"37s").external_account_id)
|
||||
end
|
||||
|
||||
|
||||
@@ -76,31 +76,31 @@ class Account::LimitedTest < ActiveSupport::TestCase
|
||||
|
||||
test "detect nearing storage limit" do
|
||||
# Paid plans have large storage limits
|
||||
accounts(:"37s").update_column(:bytes_used, 4.gigabytes)
|
||||
accounts(:"37s").stubs(:bytes_used).returns(4.gigabytes)
|
||||
assert_not accounts(:"37s").nearing_plan_storage_limit?
|
||||
|
||||
# Free plan not near limit
|
||||
accounts(:initech).update_column(:bytes_used, 400.megabytes)
|
||||
accounts(:initech).stubs(:bytes_used).returns(400.megabytes)
|
||||
assert_not accounts(:initech).nearing_plan_storage_limit?
|
||||
|
||||
# Free plan near limit
|
||||
accounts(:initech).update_column(:bytes_used, 600.megabytes)
|
||||
accounts(:initech).stubs(:bytes_used).returns(600.megabytes)
|
||||
assert accounts(:initech).nearing_plan_storage_limit?
|
||||
end
|
||||
|
||||
test "detect exceeding storage limit" do
|
||||
# Free plan under limit
|
||||
accounts(:initech).update_column(:bytes_used, 900.megabytes)
|
||||
accounts(:initech).stubs(:bytes_used).returns(900.megabytes)
|
||||
assert_not accounts(:initech).exceeding_storage_limit?
|
||||
|
||||
# Free plan over limit
|
||||
accounts(:initech).update_column(:bytes_used, 1.1.gigabytes)
|
||||
accounts(:initech).stubs(:bytes_used).returns(1.1.gigabytes)
|
||||
assert accounts(:initech).exceeding_storage_limit?
|
||||
end
|
||||
|
||||
test "override bytes_used limits" do
|
||||
account = accounts(:initech)
|
||||
account.update_column(:bytes_used, 1.1.gigabytes)
|
||||
account.stubs(:bytes_used).returns(1.1.gigabytes)
|
||||
|
||||
assert account.exceeding_storage_limit?
|
||||
assert_equal 1.1.gigabytes, account.billed_bytes_used
|
||||
|
||||
Reference in New Issue
Block a user