Merge pull request #2775 from basecamp/queenbee-account-callbacks

Implement Queenbee account callbacks
This commit is contained in:
Donal McBreen
2026-04-01 08:09:25 +01:00
committed by GitHub
5 changed files with 129 additions and 7 deletions
@@ -4,9 +4,6 @@
<ul>
<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>
</ul>
@@ -3,9 +3,6 @@ Your Fizzy account "<%= @account.name %>" was cancelled.
WHAT HAPPENS NOW?
- 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) %>
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
+1 -1
View File
@@ -133,7 +133,7 @@ module Fizzy
end
config.to_prepare do
::Account.include Account::StorageLimited
::Account.include Account::QueenbeeIntegration, Account::StorageLimited
::Identity.include Authorization::Identity, Identity::Devices
::Session.include Session::Devices
::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