Implement Queenbee account callbacks
Add Account::QueenbeeIntegration concern (SaaS-only) that bridges Fizzy's external_account_id to Queenbee's find_by_queenbee_id lookup, and adapts the bang lifecycle methods to Fizzy's Cancellable module. Remove dead billing conditional from cancellation mailer — Fizzy is free-only, there's no charge to stop.
This commit is contained in:
@@ -4,9 +4,6 @@
|
|||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>No one can access the account anymore</li>
|
<li>No one can access the account anymore</li>
|
||||||
<% if @account.try(:subscription) %>
|
|
||||||
<li>We won't charge you anymore</li>
|
|
||||||
<% end %>
|
|
||||||
<li>Everything in the account will be deleted in <%= distance_of_time_in_words_to_now(Account::Incineratable::INCINERATION_GRACE_PERIOD.from_now) %></li>
|
<li>Everything in the account will be deleted in <%= distance_of_time_in_words_to_now(Account::Incineratable::INCINERATION_GRACE_PERIOD.from_now) %></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ Your Fizzy account "<%= @account.name %>" was cancelled.
|
|||||||
WHAT HAPPENS NOW?
|
WHAT HAPPENS NOW?
|
||||||
|
|
||||||
- No one can access the account anymore
|
- No one can access the account anymore
|
||||||
<% if @account.try(:subscription) %>
|
|
||||||
- We won't charge you anymore
|
|
||||||
<% end %>
|
|
||||||
- Everything in the account will be deleted in <%= distance_of_time_in_words_to_now(Account::Incineratable::INCINERATION_GRACE_PERIOD.from_now) %>
|
- Everything in the account will be deleted in <%= distance_of_time_in_words_to_now(Account::Incineratable::INCINERATION_GRACE_PERIOD.from_now) %>
|
||||||
|
|
||||||
CHANGED YOUR MIND?
|
CHANGED YOUR MIND?
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
module Account::QueenbeeIntegration
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
include Queenbee::Client
|
||||||
|
|
||||||
|
class_methods do
|
||||||
|
def find_by_queenbee_id(id)
|
||||||
|
find_by(external_account_id: id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def queenbee_id
|
||||||
|
external_account_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def cancel!
|
||||||
|
cancel(initiated_by: system_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def uncancel!
|
||||||
|
reactivate
|
||||||
|
end
|
||||||
|
|
||||||
|
def deactivate!
|
||||||
|
cancel!
|
||||||
|
end
|
||||||
|
|
||||||
|
def reactivate!
|
||||||
|
reactivate
|
||||||
|
end
|
||||||
|
|
||||||
|
def canceled?
|
||||||
|
cancelled?
|
||||||
|
end
|
||||||
|
|
||||||
|
def owner_name
|
||||||
|
users.owner.first&.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def owner_email
|
||||||
|
users.owner.first&.identity&.email_address
|
||||||
|
end
|
||||||
|
|
||||||
|
def transferred_ownership!
|
||||||
|
raise NotImplementedError, "Fizzy does not support Queenbee-initiated ownership transfers"
|
||||||
|
end
|
||||||
|
|
||||||
|
def plan
|
||||||
|
"FreeV1"
|
||||||
|
end
|
||||||
|
|
||||||
|
def comped?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def comped=(value)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -133,7 +133,7 @@ module Fizzy
|
|||||||
end
|
end
|
||||||
|
|
||||||
config.to_prepare do
|
config.to_prepare do
|
||||||
::Account.include Account::StorageLimited
|
::Account.include Account::QueenbeeIntegration, Account::StorageLimited
|
||||||
::Identity.include Authorization::Identity, Identity::Devices
|
::Identity.include Authorization::Identity, Identity::Devices
|
||||||
::Session.include Session::Devices
|
::Session.include Session::Devices
|
||||||
::Signup.prepend Signup
|
::Signup.prepend Signup
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
require "test_helper"
|
||||||
|
require "queenbee/testing/client"
|
||||||
|
|
||||||
|
class Account::QueenbeeIntegrationTest < ActiveSupport::TestCase
|
||||||
|
include Queenbee::Testing::Client
|
||||||
|
|
||||||
|
# Fizzy creates accounts via its own Signup flow (Fizzy → Queenbee),
|
||||||
|
# not via Queenbee pushing to Fizzy, so create_with_dependents is N/A.
|
||||||
|
undef_method :test_client_class_should_respond_to_create_with_dependents
|
||||||
|
|
||||||
|
setup do
|
||||||
|
@account = accounts(:"37s")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "find_by_queenbee_id looks up by external_account_id" do
|
||||||
|
assert_equal @account, Account.find_by_queenbee_id(@account.external_account_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "queenbee_id returns external_account_id" do
|
||||||
|
assert_equal @account.external_account_id, @account.queenbee_id
|
||||||
|
end
|
||||||
|
|
||||||
|
test "cancel! creates cancellation attributed to system user" do
|
||||||
|
@account.cancel!
|
||||||
|
|
||||||
|
assert @account.cancelled?
|
||||||
|
assert_equal @account.system_user, @account.cancellation.initiated_by
|
||||||
|
end
|
||||||
|
|
||||||
|
test "cancel! is idempotent" do
|
||||||
|
@account.cancel!
|
||||||
|
assert_no_difference -> { Account::Cancellation.count } do
|
||||||
|
@account.cancel!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "cancel and reactivate round-trips" do
|
||||||
|
@account.cancel!
|
||||||
|
assert_not @account.active?
|
||||||
|
|
||||||
|
@account.reactivate!
|
||||||
|
@account.reload
|
||||||
|
assert @account.active?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "deactivate! cancels the account" do
|
||||||
|
@account.deactivate!
|
||||||
|
assert @account.cancelled?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "owner_name and owner_email from account owner" do
|
||||||
|
assert_equal users(:jason).name, @account.owner_name
|
||||||
|
assert_equal "jason@37signals.com", @account.owner_email
|
||||||
|
end
|
||||||
|
|
||||||
|
test "comped= is a no-op" do
|
||||||
|
@account.comped = true
|
||||||
|
assert_not @account.comped?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "transferred_ownership! raises NotImplementedError" do
|
||||||
|
assert_raises(NotImplementedError) { @account.transferred_ownership! }
|
||||||
|
end
|
||||||
|
|
||||||
|
test "qb_serializable_hash includes queenbee_id and subscription" do
|
||||||
|
hash = @account.qb_serializable_hash
|
||||||
|
assert_equal @account.external_account_id, hash[:id]
|
||||||
|
assert_equal({ quantity: 1 }, hash[:subscription])
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user