diff --git a/bin/sim_job b/bin/sim_job index d1a5e5806321a27f00617667eaca160e44987b38..4579b882e4d60d6964de8caae0c9d9ce85ffa480 100755 --- a/bin/sim_job +++ b/bin/sim_job @@ -147,7 +147,7 @@ class SimTopUp def low_balance LowBalance.for(customer, refill_price).then(&:notify!).then do |result| - @customer = customer.with_balance(customer.balance + result) + @customer = customer.with(balance: customer.balance + result) next call if result.positive? LOG.info "Low balance #{customer.customer_id} #{iccid}" diff --git a/lib/bill_plan_command.rb b/lib/bill_plan_command.rb index c4b41390bdc51a0478524c2b7d0a7741a9fc6c16..82babee38b64f3a84e3213203038baa55eed6143 100644 --- a/lib/bill_plan_command.rb +++ b/lib/bill_plan_command.rb @@ -77,7 +77,7 @@ protected def command_for(amount) BillPlanCommand.for( - @customer.with_balance(@customer.balance + amount) + @customer.with(balance: @customer.balance + amount) ) end end diff --git a/lib/call_attempt.rb b/lib/call_attempt.rb index c7dc0d01bd5e71849e3669b800b77a2e9793d314..7d7d6f08cc4ecdc3ae80d13097892440e40a6ebc 100644 --- a/lib/call_attempt.rb +++ b/lib/call_attempt.rb @@ -149,7 +149,7 @@ class CallAttempt low_balance.for(customer).then(&:notify!).then do |amount| if amount&.positive? CallAttempt.for( - customer: customer.with_balance(customer.balance + amount), + customer: customer.with(balance: customer.balance + amount), **kwargs.merge(direction: direction) ) else diff --git a/lib/customer.rb b/lib/customer.rb index 9201672b0fc612e52669f533557097e7f54d1fa6..1f77b50bed18c675ee5c1269a1d9a55377bc59fe 100644 --- a/lib/customer.rb +++ b/lib/customer.rb @@ -71,11 +71,11 @@ class Customer @sgx = sgx end - def with_balance(balance) + def with(balance: @balance, sgx: @sgx) self.class.new( @customer_id, @jid, plan: @plan, balance: balance, - tndetails: @tndetails, sgx: @sgx + tndetails: @tndetails, sgx: sgx, feature_flags: @feature_flags ) end diff --git a/lib/registration.rb b/lib/registration.rb index 7f35893661dd512c52eb6fddb5ff0743336b38a4..5e9565081cfe7924ee55e3cf52399847dca3df1d 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -679,7 +679,7 @@ class Registration def write @customer.bill_plan(note: "Bill #{@tel} for first month").then do updated_customer = - @customer.with_balance(@customer.balance - @customer.monthly_price) + @customer.with(balance: @customer.balance - @customer.monthly_price) @finish.new(updated_customer, @tel).write end end diff --git a/lib/tel_selections.rb b/lib/tel_selections.rb index 8eaa8f65b590672b7941333bc8a576218e83e03e..3f29eb6d74419911317209114a479505e17fe42a 100644 --- a/lib/tel_selections.rb +++ b/lib/tel_selections.rb @@ -398,6 +398,16 @@ class TelSelections # ) db.exec_defer("DELETE FROM tel_inventory WHERE tel = $1", [tel]) .then { |r| raise unless r.cmd_tuples.positive? } + .then { + next unless @source.start_with?("xmpp:") + + TrivialBackendSgxRepo.new + .put(customer.customer_id, @source.sub(/\Axmpp:/, "")) + }.then { |sgx| + next customer unless sgx + + customer.with(sgx: sgx) + } end end end diff --git a/test/test_registration.rb b/test/test_registration.rb index e028c5f997396dd2f3adf43214f4e7c5b94d7b56..7c6bea6bfe4ed9dc075fd496c0182bec602cd180 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -997,7 +997,7 @@ class RegistrationTest < Minitest::Test ) Command.execution.customer_repo.expect( :find, - customer.with_balance(10000), + customer.with(balance: 10000), ["test"] ) Command::COMMAND_MANAGER.expect( @@ -1668,11 +1668,11 @@ class RegistrationTest < Minitest::Test low_cust = customer( sgx: @sgx, jid: Blather::JID.new("test\\40onboarding.example.com@proxy") - ).with_balance(5.0) + ).with(balance: 5.0) high_cust = customer( sgx: @sgx, jid: Blather::JID.new("test\\40onboarding.example.com@proxy") - ).with_balance(100.0) + ).with(balance: 100.0) stub_request( :post, @@ -2252,14 +2252,14 @@ class RegistrationTest < Minitest::Test class RegistrationTypeTest < Minitest::Test def test_for_with_sim_kind - cust = customer(plan_name: "test_usd").with_balance(1000) + cust = customer(plan_name: "test_usd").with(balance: 1000) sim_kind = SIMKind.new("sim") result = Registration::RegistrationType.for(cust, nil, sim_kind) assert_kind_of Registration::DataOnly, result end def test_for_with_esim_kind - cust = customer(plan_name: "test_usd").with_balance(1000) + cust = customer(plan_name: "test_usd").with(balance: 1000) sim_kind = SIMKind.new("esim") result = Registration::RegistrationType.for(cust, nil, sim_kind) assert_kind_of Registration::DataOnly, result @@ -2279,12 +2279,12 @@ class RegistrationTest < Minitest::Test class DataOnlyTest < Minitest::Test def setup - @customer = customer(plan_name: "test_usd").with_balance(5) + @customer = customer(plan_name: "test_usd").with(balance: 5) @sim_kind = SIMKind.new("sim") end def test_for_returns_pay_for_sim_when_balance_insufficient - low_balance_customer = @customer.with_balance(0.50) + low_balance_customer = @customer.with(balance: 0.50) result = Registration::DataOnly.for(low_balance_customer, @sim_kind) assert_kind_of Registration::PayForSim, result end @@ -2430,7 +2430,7 @@ class RegistrationTest < Minitest::Test { var: "activation_method", value: "credit_card" } ] - reloaded_customer = @customer.with_balance(4).with_plan("test_usd") + reloaded_customer = @customer.with(balance: 4).with_plan("test_usd") result = execute_command do |exe| payment = Minitest::Mock.new