From 0d6a65f3be176842fd1377139e92f8327896a28a Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Fri, 23 Jun 2023 19:00:30 -0500 Subject: [PATCH] Go to BillPlan after setting parent, not to Finish --- lib/registration.rb | 10 +++---- test/test_registration.rb | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/lib/registration.rb b/lib/registration.rb index 6061395a3234562160bea245064fabb8d41f2b8d..d41686b88f6a143e680497e29bf3d134eeba4ef1 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -470,9 +470,9 @@ class Registration def parse(iq) return Activation.for(@customer, nil, @tel).then(&:write) if iq.prev? - verify(iq.form.field("code")&.value&.to_s).then { - Finish.new(@customer, @tel) - }.catch_only(InvitesRepo::Invalid, &method(:invalid_code)).then(&:write) + verify(iq.form.field("code")&.value&.to_s) + .catch_only(InvitesRepo::Invalid, &method(:invalid_code)) + .then(&:write) end protected @@ -490,9 +490,9 @@ class Registration if parent_customer_id set_parent(parent_customer_id) else - InvitesRepo.new(DB, REDIS).claim_code(customer_id, code) do + InvitesRepo.new(DB, REDIS).claim_code(customer_id, code) { @customer.activate_plan_starting_now - end + }.then { Finish.new(@customer, @tel) } end end end diff --git a/test/test_registration.rb b/test/test_registration.rb index 09013e2288b96893c6652de3a0c8972c15ab29d9..7d1a3962e2df347f58dce42213d3979e757291d5 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -732,6 +732,9 @@ class RegistrationTest < Minitest::Test Command::COMMAND_MANAGER = Minitest::Mock.new Registration::Payment::InviteCode::Finish = Minitest::Mock.new + Registration::Payment::InviteCode::BillPlan = + Minitest::Mock.new + def test_write customer = customer(plan_name: "test_usd") Registration::Payment::InviteCode::DB.expect(:transaction, true, []) @@ -779,6 +782,58 @@ class RegistrationTest < Minitest::Test end em :test_write + def test_write_parent_code + customer = customer(plan_name: "test_usd") + Registration::Payment::InviteCode::BillPlan.expect( + :new, + OpenStruct.new(write: nil) + ) { |*| true } + execute_command do + Registration::Payment::InviteCode::REDIS.expect( + :hget, + EMPromise.resolve("parent_customer"), + ["jmp_parent_codes", "pabc"] + ) + CustomerPlan::DB.expect( + :query, + [{ "plan_name" => "test_usd" }], + [String, ["parent_customer"]] + ) + CustomerPlan::DB.expect( + :exec_defer, + EMPromise.resolve(nil), + [String, ["test", "test_usd", "parent_customer"]] + ) + Command.execution.customer_repo.expect( + :find, + customer.with_balance(10000), + ["test"] + ) + Command::COMMAND_MANAGER.expect( + :write, + EMPromise.resolve( + Blather::Stanza::Iq::Command.new.tap { |iq| + iq.form.fields = [{ var: "code", value: "pabc" }] + } + ), + [Matching.new do |reply| + assert_equal :form, reply.form.type + assert_nil reply.form.instructions + end] + ) + + Registration::Payment::InviteCode.new( + customer, + "+15555550000" + ).write + end + assert_mock Command::COMMAND_MANAGER + assert_mock Registration::Payment::InviteCode::DB + assert_mock Registration::Payment::InviteCode::REDIS + assert_mock Registration::Payment::InviteCode::BillPlan + end + em :test_write_parent_code + def test_write_bad_code result = execute_command do customer = customer(plan_name: "test_usd")