From 6be8cf86e823c6f191b13606feca1d19083de000 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 26 Jan 2026 11:40:56 -0500 Subject: [PATCH] Actually use altsgx when activating something with that source --- lib/registration.rb | 12 ++--- lib/tel_selections.rb | 6 +-- test/test_registration.rb | 109 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 9 deletions(-) diff --git a/lib/registration.rb b/lib/registration.rb index 5e9565081cfe7924ee55e3cf52399847dca3df1d..4529c556a1ad49ed7f50fec8701d981f33c89c02 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -734,7 +734,7 @@ class Registration return buy_number if @customer.balance < @tel.price @tel.order(DB, @customer).then( - ->(_) { customer_active_tel_purchased }, + method(:customer_active_tel_purchased), method(:number_purchase_error) ) end @@ -793,16 +793,16 @@ class Registration end end - def customer_active_tel_purchased - @customer.register!(@tel.tel).catch(&method(:raise_setup_error)).then { + def customer_active_tel_purchased(customer) + customer.register!(@tel.tel).catch(&method(:raise_setup_error)).then { EMPromise.all([ - TEL_SELECTIONS.delete(@customer.jid), + TEL_SELECTIONS.delete(customer.jid), put_default_fwd, use_referral_code, - @tel.charge(@customer) + @tel.charge(customer) ]) }.then do - FinishOnboarding.for(@customer, @tel).then(&:write) + FinishOnboarding.for(customer, @tel).then(&:write) end end end diff --git a/lib/tel_selections.rb b/lib/tel_selections.rb index 3f29eb6d74419911317209114a479505e17fe42a..2ded1fc7c2f2ec3fcf9e20201c71666b90aa7207 100644 --- a/lib/tel_selections.rb +++ b/lib/tel_selections.rb @@ -321,13 +321,13 @@ class TelSelections end def order(_, customer) - BandwidthTnReservationRepo.new.get(customer, tel).then do |rid| + BandwidthTnReservationRepo.new.get(customer, tel).then { |rid| BandwidthTNOrder.create( tel, customer_order_id: customer.customer_id, reservation_id: rid ).then(&:poll) - end + }.then { customer } end end @@ -390,7 +390,7 @@ class TelSelections "LocalInventory/#{tel}/#{@source}/#{price}" end - def order(db, _customer) + def order(db, customer) # Move always moves to wrong account, oops # Also probably can't move from/to same account # BandwidthTnRepo.new.move( diff --git a/test/test_registration.rb b/test/test_registration.rb index 7c6bea6bfe4ed9dc075fd496c0182bec602cd180..fca4eeb1c673c7e06feb801713ad60fd6ff32535 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -1794,6 +1794,115 @@ class RegistrationTest < Minitest::Test end em :test_write_local_inventory_must_pay + def test_write_local_inventory_alt_sgx + Registration::Finish::REDIS.expect( + :get, + nil, + ["jmp_customer_pending_invite-test"] + ) + Registration::Finish::REDIS.expect( + :del, + nil, + ["jmp_customer_pending_invite-test"] + ) + Registration::Finish::REDIS.expect( + :hget, + nil, + ["jmp_group_codes", nil] + ) + Registration::Finish::DB.expect( + :exec_defer, + EMPromise.resolve(OpenStruct.new(cmd_tuples: 1)), + [String, ["+15555550000"]] + ) + Bwmsgsv2Repo::REDIS.expect( + :get, + EMPromise.resolve(nil), + ["jmp_customer_backend_sgx-test"] + ) + TrivialBackendSgxRepo::REDIS.expect( + :get, + EMPromise.resolve(nil), + ["jmp_customer_backend_sgx-test"] + ) + TrivialBackendSgxRepo::REDIS.expect( + :set, + EMPromise.resolve(nil), + ["jmp_customer_backend_sgx-test", "route_value"] + ) + TrivialBackendSgxRepo::REDIS.expect( + :get, + EMPromise.resolve("route_value"), + ["jmp_customer_backend_sgx-test"] + ) + BackendSgx::REDIS.expect( + :set, + EMPromise.resolve(nil), + ["catapult_jid-+15555550000", "customer_test@component"] + ) + Bwmsgsv2Repo::REDIS.expect( + :set, + nil, + [ + "catapult_fwd-+15555550000", + "xmpp:test\\40onboarding.example.com@proxy" + ] + ) + Bwmsgsv2Repo::REDIS.expect( + :set, + nil, + ["catapult_fwd_timeout-customer_test@component", 25] + ) + result = execute_command do + Command::COMMAND_MANAGER.expect( + :write, + EMPromise.reject(:test_result), + [Matching.new do |iq| + assert_equal :form, iq.form.type + assert iq.form.field("subdomain") + end] + ) + + BackendSgx::IQ_MANAGER.expect( + :write, + EMPromise.resolve(nil), + [Matching.new do |iq| + assert_equal "sgx", iq.to.to_s + assert iq.remove? + end] + ) + + BackendSgx::IQ_MANAGER.expect( + :write, + EMPromise.resolve(nil), + [Matching.new do |iq| + assert_equal "route_value", iq.to.to_s + assert_equal "+15555550000", iq.phone + end] + ) + + Registration::Finish.new( + customer( + sgx: @sgx, + jid: Blather::JID.new("test\\40onboarding.example.com@proxy") + ), + TelSelections::ChooseTel::Tn::LocalInventory.new( + TelSelections::ChooseTel::Tn.new("+15555550000"), + "xmpp:route_value" + ) + ).write.catch { |e| e } + end + assert_equal :test_result, result + assert_mock @sgx + assert_mock Registration::Finish::REDIS + assert_mock Bwmsgsv2Repo::REDIS + assert_mock TrivialBackendSgxRepo::REDIS + assert_mock BackendSgx::REDIS + assert_mock BackendSgx::IQ_MANAGER + assert_mock Command::COMMAND_MANAGER + end + em :test_write_local_inventory_alt_sgx + def test_write_tn_fail create_order = stub_request( :post,