Add tests for subscription-related messaging
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
require "test_helper"
|
||||
|
||||
class Account::Subscriptions::CardCreationTest < ActionDispatch::IntegrationTest
|
||||
# Nearing limits - shown in card creation footer
|
||||
|
||||
test "admin sees nearing card limit notice" do
|
||||
sign_in_as :mike
|
||||
|
||||
accounts(:initech).update_column(:cards_count, 950)
|
||||
|
||||
get card_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
|
||||
|
||||
assert_response :success
|
||||
assert_match /upgrade to unlimited/i, response.body
|
||||
end
|
||||
|
||||
test "admin sees nearing storage limit notice" do
|
||||
sign_in_as :mike
|
||||
|
||||
Account.any_instance.stubs(:bytes_used).returns(600.megabytes)
|
||||
|
||||
get card_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
|
||||
|
||||
assert_response :success
|
||||
assert_match /upgrade for more/i, response.body
|
||||
end
|
||||
|
||||
# Exceeding limits - shown instead of create buttons
|
||||
|
||||
test "admin sees exceeding card limit notice" do
|
||||
sign_in_as :mike
|
||||
|
||||
accounts(:initech).update_column(:cards_count, 1001)
|
||||
|
||||
get card_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
|
||||
|
||||
assert_response :success
|
||||
assert_match /you've used your.*free cards/i, response.body
|
||||
end
|
||||
|
||||
test "admin sees exceeding storage limit notice" do
|
||||
sign_in_as :mike
|
||||
|
||||
Account.any_instance.stubs(:bytes_used).returns(1.1.gigabytes)
|
||||
|
||||
get card_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
|
||||
|
||||
assert_response :success
|
||||
assert_match /you've used your.*free storage/i, response.body
|
||||
end
|
||||
|
||||
# Paid accounts under limits - no notices
|
||||
|
||||
test "paid account under limits sees no notices" do
|
||||
sign_in_as :kevin
|
||||
|
||||
accounts(:"37s").subscription.update!(plan: Plan.paid, status: :active)
|
||||
|
||||
get card_path(cards(:layout), script_name: accounts(:"37s").slug)
|
||||
|
||||
assert_response :success
|
||||
assert_no_match /upgrade/i, response.body
|
||||
assert_no_match /you've used your/i, response.body
|
||||
end
|
||||
|
||||
# Comped accounts under limits - no notices
|
||||
|
||||
test "comped account under limits sees no notices" do
|
||||
sign_in_as :mike
|
||||
|
||||
accounts(:initech).comp
|
||||
|
||||
get card_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
|
||||
|
||||
assert_response :success
|
||||
assert_no_match /upgrade/i, response.body
|
||||
assert_no_match /you've used your/i, response.body
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,63 @@
|
||||
require "test_helper"
|
||||
|
||||
class Account::Subscriptions::SettingsTest < ActionDispatch::IntegrationTest
|
||||
test "free users see current usage" do
|
||||
sign_in_as :mike
|
||||
|
||||
accounts(:initech).update_column(:cards_count, 3)
|
||||
|
||||
get account_settings_path(script_name: accounts(:initech).slug)
|
||||
|
||||
assert_response :success
|
||||
assert_select "h3", text: /You've used 3 free cards out of 1000/
|
||||
end
|
||||
|
||||
test "paid users see thank you message" do
|
||||
sign_in_as :kevin
|
||||
|
||||
accounts(:"37s").subscription.update!(plan: Plan.paid, status: :active)
|
||||
|
||||
get account_settings_path(script_name: accounts(:"37s").slug)
|
||||
|
||||
assert_response :success
|
||||
assert_select "h3", text: "Thank you for buying Fizzy"
|
||||
end
|
||||
|
||||
test "regular plan users see upgrade option" do
|
||||
sign_in_as :kevin
|
||||
|
||||
accounts(:"37s").subscription.update!(plan: Plan.paid, status: :active)
|
||||
|
||||
get account_settings_path(script_name: accounts(:"37s").slug)
|
||||
|
||||
assert_response :success
|
||||
assert_select "button", text: /upgrade/i
|
||||
assert_select "button", text: /downgrade/i, count: 0
|
||||
end
|
||||
|
||||
test "extra storage plan users see downgrade option" do
|
||||
sign_in_as :kevin
|
||||
|
||||
accounts(:"37s").subscription.update!(plan: Plan.paid_with_extra_storage, status: :active)
|
||||
|
||||
get account_settings_path(script_name: accounts(:"37s").slug)
|
||||
|
||||
assert_response :success
|
||||
assert_select "button", text: /downgrade/i
|
||||
assert_select "button", text: /upgrade/i, count: 0
|
||||
end
|
||||
|
||||
test "comped accounts see no subscription panel" do
|
||||
sign_in_as :mike
|
||||
|
||||
accounts(:initech).comp
|
||||
|
||||
get account_settings_path(script_name: accounts(:initech).slug)
|
||||
|
||||
assert_response :success
|
||||
assert_no_match /thank you for buying/i, response.body
|
||||
assert_no_match /free cards out of/i, response.body
|
||||
assert_no_match /upgrade/i, response.body
|
||||
assert_no_match /downgrade/i, response.body
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user