From 934772529eecfb46e4a879824cec6e43e4872fce Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 11 Aug 2021 12:23:05 -0500 Subject: [PATCH] Customer always has a JID --- lib/customer.rb | 33 +++++++------------ lib/customer_plan.rb | 10 ++++++ lib/customer_repo.rb | 39 +++++++++++++++++------ lib/registration.rb | 6 ++-- lib/sip_account.rb | 1 + sgx_jmp.rb | 8 ++--- test/test_add_bitcoin_address.rb | 16 +++++----- test/test_alt_top_up_form.rb | 18 +++++------ test/test_buy_account_credit_form.rb | 2 +- test/test_customer.rb | 42 +++++++------------------ test/test_customer_repo.rb | 8 ++++- test/test_helper.rb | 15 +++++++++ test/test_low_balance.rb | 8 ++--- test/test_registration.rb | 47 +++++++++++++--------------- test/test_transaction.rb | 4 +-- 15 files changed, 139 insertions(+), 118 deletions(-) diff --git a/lib/customer.rb b/lib/customer.rb index 2fc587be87d8db0429eb2e655bde17af62f16506..0ac64dbdac38e0818b6e40d6b5f254adf68b26b3 100644 --- a/lib/customer.rb +++ b/lib/customer.rb @@ -14,7 +14,7 @@ require_relative "./sip_account" class Customer extend Forwardable - attr_reader :customer_id, :balance + attr_reader :customer_id, :balance, :jid def_delegators :@plan, :active?, :activate_plan_starting_now, :bill_plan, :currency, :merchant_account, :plan_name, :auto_top_up_amount def_delegators :@sgx, :register!, :registered?, :fwd_timeout= @@ -22,17 +22,15 @@ class Customer def initialize( customer_id, - plan_name: nil, - expires_at: Time.now, + jid, + plan: CustomerPlan.new(customer_id), balance: BigDecimal.new(0), sgx: BackendSgx.new(customer_id) ) - @plan = CustomerPlan.new( - customer_id, - plan: plan_name && Plan.for(plan_name), expires_at: expires_at - ) + @plan = plan @usage = CustomerUsage.new(customer_id) @customer_id = customer_id + @jid = jid @balance = balance @sgx = sgx end @@ -40,9 +38,10 @@ class Customer def with_plan(plan_name) self.class.new( @customer_id, + @jid, + plan: @plan.with_plan_name(plan_name), balance: @balance, - expires_at: expires_at, - plan_name: plan_name + sgx: @sgx ) end @@ -54,19 +53,11 @@ class Customer .then(PaymentMethods.method(:for_braintree_customer)) end - def jid - @jid ||= REDIS.get("jmp_customer_jid-#{customer_id}").then do |sjid| - Blather::JID.new(sjid) - end - end - def stanza_to(stanza) - jid.then do |jid| - stanza = stanza.dup - stanza.to = jid.with(resource: stanza.to&.resource) - stanza.from = stanza.from.with(domain: CONFIG[:component][:jid]) - BLATHER << stanza - end + stanza = stanza.dup + stanza.to = jid.with(resource: stanza.to&.resource) + stanza.from = stanza.from.with(domain: CONFIG[:component][:jid]) + BLATHER << stanza end def stanza_from(stanza) diff --git a/lib/customer_plan.rb b/lib/customer_plan.rb index 057706cf65964513a649773e936476af5b820039..1854dffaecb519418017ed9bd1e94f8916ffcc5a 100644 --- a/lib/customer_plan.rb +++ b/lib/customer_plan.rb @@ -2,6 +2,8 @@ require "forwardable" +require_relative "em" + class CustomerPlan extend Forwardable @@ -19,6 +21,14 @@ class CustomerPlan plan_name && @expires_at > Time.now end + def with_plan_name(plan_name) + self.class.new( + @customer_id, + plan: Plan.for(plan_name), + expires_at: @expires_at + ) + end + def auto_top_up_amount REDIS.get("jmp_customer_auto_top_up_amount-#{@customer_id}").then(&:to_i) end diff --git a/lib/customer_repo.rb b/lib/customer_repo.rb index 66af4effdcf90f0dc27829bef06618fd0ecfbc19..0f57904a9cae0f59a63bf270ad9f082773eaa5ac 100644 --- a/lib/customer_repo.rb +++ b/lib/customer_repo.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative "customer" +require_relative "polyfill" class CustomerRepo def initialize(redis: REDIS, db: DB, braintree: BRAINTREE) @@ -10,20 +11,16 @@ class CustomerRepo end def find(customer_id) - result = @db.query_defer(<<~SQL, [customer_id]) - SELECT COALESCE(balance,0) AS balance, plan_name, expires_at - FROM customer_plans LEFT JOIN balances USING (customer_id) - WHERE customer_id=$1 LIMIT 1 - SQL - result.then do |rows| - Customer.new(customer_id, **rows.first&.transform_keys(&:to_sym) || {}) + @redis.get("jmp_customer_jid-#{customer_id}").then do |jid| + raise "No jid" unless jid + find_inner(customer_id, jid) end end def find_by_jid(jid) @redis.get("jmp_customer_id-#{jid}").then do |customer_id| raise "No customer id" unless customer_id - find(customer_id) + find_inner(customer_id, jid) end end @@ -35,8 +32,32 @@ class CustomerRepo "jmp_customer_id-#{jid}", cid, "jmp_customer_jid-#{cid}", jid ).then do |redis_result| raise "Saving new customer to redis failed" unless redis_result == 1 - Customer.new(cid) + Customer.new(cid, Blather::JID.new(jid)) end end end + +protected + + def hydrate_plan(customer_id, raw_customer) + raw_customer.dup.tap do |data| + data[:plan] = CustomerPlan.new( + customer_id, + plan: data.delete(:plan_name)&.then(&Plan.method(:for)), + expires_at: data.delete(:expires_at) + ) + end + end + + def find_inner(customer_id, jid) + result = @db.query_defer(<<~SQL, [customer_id]) + SELECT COALESCE(balance,0) AS balance, plan_name, expires_at + FROM customer_plans LEFT JOIN balances USING (customer_id) + WHERE customer_id=$1 LIMIT 1 + SQL + result.then do |rows| + data = hydrate_plan(customer_id, rows.first&.transform_keys(&:to_sym) || {}) + Customer.new(customer_id, Blather::JID.new(jid), **data) + end + end end diff --git a/lib/registration.rb b/lib/registration.rb index 4c7425e77366f866038b951be1af15457fe1da66..fe02828419c7f51a7976a7cf3fe8ed2c45eb2206 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -13,12 +13,11 @@ require_relative "./web_register_manager" class Registration def self.for(customer, web_register_manager) - jid = Command.execution.iq.from.stripped customer.registered?.then do |registered| if registered Registered.new(registered.phone) else - web_register_manager[jid].choose_tel.then do |tel| + web_register_manager[customer.jid].choose_tel.then do |tel| Activation.for(customer, tel) end end @@ -444,8 +443,7 @@ class Registration protected def cheogram_sip_addr - jid = Command.execution.iq.from.stripped - "sip:#{ERB::Util.url_encode(jid)}@sip.cheogram.com" + "sip:#{ERB::Util.url_encode(@customer.jid)}@sip.cheogram.com" end def raise_setup_error(e) diff --git a/lib/sip_account.rb b/lib/sip_account.rb index 7f82f625f99be84e3547fc77926b86f1f6f37f6c..1ba311343993b95896ecabba8dd79b5061e8caeb 100644 --- a/lib/sip_account.rb +++ b/lib/sip_account.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "em-synchrony/em-http" # For aget vs get require "securerandom" require "value_semantics/monkey_patched" diff --git a/sgx_jmp.rb b/sgx_jmp.rb index 56ffe070f1d8b4f122d8fd3180c1d9eb2b900890..5c65377cfd53f721b3905518b2d39a17e38f5d76 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -241,10 +241,10 @@ message( CustomerRepo.new.find( Blather::JID.new(address["jid"].to_s).node.delete_prefix("customer_") - ).then(&:jid).then { |customer_jid| + ).then { |customer| m.from = m.from.with(domain: CONFIG[:component][:jid]) - m.to = m.to.with(domain: customer_jid.domain) - address["jid"] = customer_jid.to_s + m.to = m.to.with(domain: customer.jid.domain) + address["jid"] = customer.jid.to_s BLATHER << m }.catch { |e| panic(e, sentry_hub) } end @@ -416,7 +416,7 @@ Command.new( ) { Command.customer.then do |customer| url = CONFIG[:credit_card_url].call( - reply.to.stripped.to_s.gsub("\\", "%5C"), + customer.jid.to_s.gsub("\\", "%5C"), customer.customer_id ) desc = "Manage credits cards and settings" diff --git a/test/test_add_bitcoin_address.rb b/test/test_add_bitcoin_address.rb index c26b19b69f04ea6340553893e99dbeba1cbdda90..9576cb64a04923c44b1347db807d52c3159e8797 100644 --- a/test/test_add_bitcoin_address.rb +++ b/test/test_add_bitcoin_address.rb @@ -7,23 +7,23 @@ require "add_bitcoin_address" class AddBitcoinAddressTest < Minitest::Test def test_for iq = Blather::Stanza::Iq::Command.new - customer = Customer.new("test") - AddBitcoinAddress.for(iq, AltTopUpForm.new(customer), customer) + cust = customer + AddBitcoinAddress.for(iq, AltTopUpForm.new(cust), cust) end def test_for_add_bitcoin iq = Blather::Stanza::Iq::Command.new iq.form.fields = [{ var: "add_btc_address", value: "true" }] - customer = Customer.new("test") - AddBitcoinAddress.for(iq, AltTopUpForm.new(customer), customer) + cust = customer + AddBitcoinAddress.for(iq, AltTopUpForm.new(cust), cust) end def test_write - customer = Minitest::Mock.new - customer.expect(:add_btc_address, EMPromise.resolve("newaddress")) + cust = Minitest::Mock.new + cust.expect(:add_btc_address, EMPromise.resolve("newaddress")) iq = Blather::Stanza::Iq::Command.new - AddBitcoinAddress.new(iq, customer).write.sync - assert_mock customer + AddBitcoinAddress.new(iq, cust).write.sync + assert_mock cust end em :test_write diff --git a/test/test_alt_top_up_form.rb b/test/test_alt_top_up_form.rb index 1bfbaddaaf3e5b4aec2162756a93cde71644b05a..264c099e31ed8af8a2533cc29ac38f54b2d3603d 100644 --- a/test/test_alt_top_up_form.rb +++ b/test/test_alt_top_up_form.rb @@ -13,7 +13,7 @@ class AltTopUpFormTest < Minitest::Test ) assert_kind_of( AltTopUpForm, - AltTopUpForm.for(Customer.new("test")).sync + AltTopUpForm.for(customer).sync ) end em :test_for @@ -26,7 +26,7 @@ class AltTopUpFormTest < Minitest::Test ) assert_kind_of( AltTopUpForm, - AltTopUpForm.for(Customer.new("test")).sync + AltTopUpForm.for(customer).sync ) end em :test_for_addresses @@ -39,7 +39,7 @@ class AltTopUpFormTest < Minitest::Test ) assert_kind_of( AltTopUpForm, - AltTopUpForm.for(Customer.new("test", plan_name: "test_cad")).sync + AltTopUpForm.for(customer(plan_name: "test_cad")).sync ) end em :test_for_cad @@ -48,7 +48,7 @@ class AltTopUpFormTest < Minitest::Test assert_kind_of( Blather::Stanza::X, AltTopUpForm.new( - Customer.new("test"), + customer, AltTopUpForm::AddBtcAddressField.new ).form ) @@ -58,7 +58,7 @@ class AltTopUpFormTest < Minitest::Test assert_kind_of( Blather::Stanza::X, AltTopUpForm.new( - Customer.new("test"), + customer, AltTopUpForm::AddBtcAddressField::AddNewBtcAddressField.new ).form ) @@ -69,7 +69,7 @@ class AltTopUpFormTest < Minitest::Test iq_form.fields = [ { var: "add_btc_address", value: "true" } ] - assert AltTopUpForm.new(Customer.new("t")).parse(iq_form)[:add_btc_address] + assert AltTopUpForm.new(customer).parse(iq_form)[:add_btc_address] end def test_parse_1 @@ -77,7 +77,7 @@ class AltTopUpFormTest < Minitest::Test iq_form.fields = [ { var: "add_btc_address", value: "1" } ] - assert AltTopUpForm.new(Customer.new("t")).parse(iq_form)[:add_btc_address] + assert AltTopUpForm.new(customer).parse(iq_form)[:add_btc_address] end def test_parse_false @@ -85,11 +85,11 @@ class AltTopUpFormTest < Minitest::Test iq_form.fields = [ { var: "add_btc_address", value: "false" } ] - refute AltTopUpForm.new(Customer.new("t")).parse(iq_form)[:add_btc_address] + refute AltTopUpForm.new(customer).parse(iq_form)[:add_btc_address] end def test_parse_not_presend iq_form = Blather::Stanza::X.new - refute AltTopUpForm.new(Customer.new("t")).parse(iq_form)[:add_btc_address] + refute AltTopUpForm.new(customer).parse(iq_form)[:add_btc_address] end end diff --git a/test/test_buy_account_credit_form.rb b/test/test_buy_account_credit_form.rb index b81854d21e7d0e5a7b26c550e46e5adac67f5a19..0ca1bfad2665ac76cd85027a262a611aebef7704 100644 --- a/test/test_buy_account_credit_form.rb +++ b/test/test_buy_account_credit_form.rb @@ -24,7 +24,7 @@ class BuyAccountCreditFormTest < Minitest::Test assert_kind_of( BuyAccountCreditForm, - BuyAccountCreditForm.for(Customer.new("test")).sync + BuyAccountCreditForm.for(customer).sync ) end em :test_for diff --git a/test/test_customer.rb b/test/test_customer.rb index 395abf2ed7e1f85e02e5f524f30cb179eb6d2ca8..c72f0afa1f1134377e32e71ea16a0cec6c4896fd 100644 --- a/test/test_customer.rb +++ b/test/test_customer.rb @@ -43,7 +43,7 @@ class CustomerTest < Minitest::Test OpenStruct.new(cmd_tuples: 1), [String, ["test", "test_usd"]] ) - Customer.new("test", plan_name: "test_usd").bill_plan.sync + customer(plan_name: "test_usd").bill_plan.sync CustomerPlan::DB.verify end em :test_bill_plan_activate @@ -71,43 +71,25 @@ class CustomerTest < Minitest::Test [String, ["test", "test_usd"]] ) CustomerPlan::DB.expect(:exec, nil, [String, ["test"]]) - Customer.new("test", plan_name: "test_usd").bill_plan.sync + customer(plan_name: "test_usd").bill_plan.sync CustomerPlan::DB.verify end em :test_bill_plan_update - def test_jid - Customer::REDIS.expect( - :get, - EMPromise.resolve("test@example.com"), - ["jmp_customer_jid-test"] - ) - jid = Customer.new("test").jid.sync - assert_kind_of Blather::JID, jid - assert_equal "test@example.com", jid.to_s - Customer::REDIS.verify - end - em :test_jid - def test_stanza_to - Customer::REDIS.expect( - :get, - EMPromise.resolve("test@example.com"), - ["jmp_customer_jid-test"] - ) Customer::BLATHER.expect( :<<, nil, [Matching.new do |stanza| assert_equal "+15555550000@component/a", stanza.from.to_s - assert_equal "test@example.com/b", stanza.to.to_s + assert_equal "test@example.net/b", stanza.to.to_s end] ) m = Blather::Stanza::Message.new m.from = "+15555550000@sgx/a" m.to = "customer_test@component/b" - Customer.new("test").stanza_to(m).sync - Customer::BLATHER.verify + customer.stanza_to(m) + assert_mock Customer::BLATHER end em :test_stanza_to @@ -123,7 +105,7 @@ class CustomerTest < Minitest::Test m = Blather::Stanza::Message.new m.from = "test@example.com/a" m.to = "+15555550000@component/b" - Customer.new("test").stanza_from(m) + customer.stanza_from(m) Customer::BLATHER.verify end @@ -149,7 +131,7 @@ class CustomerTest < Minitest::Test }, Date.today => 123 ), - Customer.new("test").usage_report(report_for).sync + customer.usage_report(report_for).sync ) end em :test_customer_usage_report @@ -164,7 +146,7 @@ class CustomerTest < Minitest::Test "Authorization" => "Basic Y2F0YXB1bHRfdG9rZW46Y2F0YXB1bHRfc2VjcmV0" } ).to_return(status: 404) - sip = Customer.new("test").sip_account.sync + sip = customer.sip_account.sync assert_kind_of SipAccount::New, sip assert_equal "test", sip.username assert_requested req @@ -196,7 +178,7 @@ class CustomerTest < Minitest::Test { name: "test", domainId: "domain", id: "endpoint" } ].to_json) - sip = Customer.new("test").sip_account.sync + sip = customer.sip_account.sync assert_kind_of SipAccount, sip assert_equal "test", sip.username assert_equal( @@ -218,7 +200,7 @@ class CustomerTest < Minitest::Test ).to_return(status: 400) assert_raises(RuntimeError) do - Customer.new("test").sip_account.sync + customer.sip_account.sync end end em :test_sip_account_error @@ -229,7 +211,7 @@ class CustomerTest < Minitest::Test EMPromise.resolve(["testaddr"]), ["jmp_customer_btc_addresses-test"] ) - assert_equal ["testaddr"], Customer.new("test").btc_addresses.sync + assert_equal ["testaddr"], customer.btc_addresses.sync assert_mock Customer::REDIS end em :test_btc_addresses @@ -245,7 +227,7 @@ class CustomerTest < Minitest::Test EMPromise.resolve(nil), ["testaddr", "http://notify.example.com"] ) - assert_equal "testaddr", Customer.new("test").add_btc_address.sync + assert_equal "testaddr", customer.add_btc_address.sync assert_mock Customer::REDIS assert_mock Customer::ELECTRUM end diff --git a/test/test_customer_repo.rb b/test/test_customer_repo.rb index e92c3c7b99cda2a30080679b449c3231a1d2d4c4..38232002fe140f2fa0ce9dc5eba969dbb8206528 100644 --- a/test/test_customer_repo.rb +++ b/test/test_customer_repo.rb @@ -52,7 +52,13 @@ class CustomerRepoTest < Minitest::Test def test_find_db_empty db = Minitest::Mock.new - repo = mkrepo(db: db) + redis = Minitest::Mock.new + redis.expect( + :get, + EMPromise.resolve("test@example.net"), + ["jmp_customer_jid-7357"] + ) + repo = mkrepo(db: db, redis: redis) db.expect( :query_defer, EMPromise.resolve([]), diff --git a/test/test_helper.rb b/test/test_helper.rb index 5ebaf57cf522fb8115eeedb737c7ce56cefb39c7..c60e5470965ac33512f6534adc4f3476bce830e2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -38,6 +38,21 @@ require "backend_sgx" $VERBOSE = nil Sentry.init +def customer(customer_id="test", plan_name: nil, **kwargs) + jid = Blather::JID.new("#{customer_id}@example.net") + if plan_name + expires_at = kwargs.delete(:expires_at) || Time.now + plan = CustomerPlan.new( + customer_id, + plan: Plan.for(plan_name), + expires_at: expires_at + ) + Customer.new(customer_id, jid, plan: plan, **kwargs) + else + Customer.new(customer_id, jid, **kwargs) + end +end + CONFIG = { sgx: "sgx", component: { diff --git a/test/test_low_balance.rb b/test/test_low_balance.rb index 92291edabacbd0a63421f6267709090ad8a4fdad..e023f202926ab427243a6b97dcde8ed0ad299dcd 100644 --- a/test/test_low_balance.rb +++ b/test/test_low_balance.rb @@ -14,7 +14,7 @@ class LowBalanceTest < Minitest::Test EMPromise.resolve(1), ["jmp_low_balance_notify-test"] ) - assert_kind_of LowBalance::Locked, LowBalance.for(Customer.new("test")).sync + assert_kind_of LowBalance::Locked, LowBalance.for(customer).sync end em :test_for_locked @@ -41,7 +41,7 @@ class LowBalanceTest < Minitest::Test ) assert_kind_of( LowBalance, - LowBalance.for(Customer.new("test")).sync + LowBalance.for(customer).sync ) assert_mock ExpiringLock::REDIS end @@ -65,7 +65,7 @@ class LowBalanceTest < Minitest::Test ) assert_kind_of( LowBalance::AutoTopUp, - LowBalance.for(Customer.new("test")).sync + LowBalance.for(customer).sync ) assert_mock ExpiringLock::REDIS end @@ -75,7 +75,7 @@ class LowBalanceTest < Minitest::Test LowBalance::AutoTopUp::Transaction = Minitest::Mock.new def setup - @customer = Customer.new("test") + @customer = customer @auto_top_up = LowBalance::AutoTopUp.new(@customer, 100) end diff --git a/test/test_registration.rb b/test/test_registration.rb index 8743692bc6016a8293ef39788caf944300acad47..96f16d26ed93c6aab8290a8d868f2b41ecedaaf5 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -26,7 +26,7 @@ class RegistrationTest < Minitest::Test iq.from = "test@example.com" result = execute_command(iq) do Registration.for( - Customer.new("test", sgx: sgx), + customer(sgx: sgx), Minitest::Mock.new ) end @@ -35,15 +35,12 @@ class RegistrationTest < Minitest::Test em :test_for_registered def test_for_activated - sgx = OpenStruct.new(registered?: EMPromise.resolve(nil)) web_manager = WebRegisterManager.new - web_manager["test@example.com"] = "+15555550000" - iq = Blather::Stanza::Iq::Command.new - iq.from = "test@example.com" - result = execute_command(iq) do + web_manager["test@example.net"] = "+15555550000" + result = execute_command do + sgx = OpenStruct.new(registered?: EMPromise.resolve(nil)) Registration.for( - Customer.new( - "test", + customer( plan_name: "test_usd", expires_at: Time.now + 999, sgx: sgx @@ -58,12 +55,12 @@ class RegistrationTest < Minitest::Test def test_for_not_activated_with_customer_id sgx = OpenStruct.new(registered?: EMPromise.resolve(nil)) web_manager = WebRegisterManager.new - web_manager["test@example.com"] = "+15555550000" + web_manager["test@example.net"] = "+15555550000" iq = Blather::Stanza::Iq::Command.new iq.from = "test@example.com" result = execute_command(iq) do Registration.for( - Customer.new("test", sgx: sgx), + customer(sgx: sgx), web_manager ) end @@ -121,8 +118,8 @@ class RegistrationTest < Minitest::Test Customer::BRAINTREE = Minitest::Mock.new def test_for_bitcoin - customer = Minitest::Mock.new(Customer.new("test")) - customer.expect( + cust = Minitest::Mock.new(customer) + cust.expect( :add_btc_address, EMPromise.resolve("testaddr") ) @@ -131,7 +128,7 @@ class RegistrationTest < Minitest::Test { var: "activation_method", value: "bitcoin" }, { var: "plan_name", value: "test_usd" } ] - result = Registration::Payment.for(iq, customer, "+15555550000") + result = Registration::Payment.for(iq, cust, "+15555550000") assert_kind_of Registration::Payment::Bitcoin, result end @@ -154,7 +151,7 @@ class RegistrationTest < Minitest::Test ] result = Registration::Payment.for( iq, - Customer.new("test"), + customer, "+15555550000" ).sync assert_kind_of Registration::Payment::CreditCard, result @@ -169,7 +166,7 @@ class RegistrationTest < Minitest::Test ] result = Registration::Payment.for( iq, - Customer.new("test"), + customer, "+15555550000" ) assert_kind_of Registration::Payment::InviteCode, result @@ -181,7 +178,7 @@ class RegistrationTest < Minitest::Test def setup @customer = Minitest::Mock.new( - Customer.new("test", plan_name: "test_usd") + customer(plan_name: "test_usd") ) @customer.expect( :add_btc_address, @@ -233,13 +230,13 @@ class RegistrationTest < Minitest::Test class CreditCardTest < Minitest::Test def setup @credit_card = Registration::Payment::CreditCard.new( - Customer.new("test"), + customer, "+15555550000" ) end def test_for - customer = Minitest::Mock.new(Customer.new("test")) + customer = Minitest::Mock.new(customer) customer.expect( :payment_methods, EMPromise.resolve(OpenStruct.new(default_payment_method: :test)) @@ -291,7 +288,7 @@ class RegistrationTest < Minitest::Test EMPromise.resolve(nil) ) customer = Minitest::Mock.new( - Customer.new("test", plan_name: "test_usd") + customer(plan_name: "test_usd") ) Registration::Payment::CreditCard::Activate::Transaction.expect( :sale, @@ -323,7 +320,7 @@ class RegistrationTest < Minitest::Test def test_write_declines customer = Minitest::Mock.new( - Customer.new("test", plan_name: "test_usd") + customer(plan_name: "test_usd") ) iq = Blather::Stanza::Iq::Command.new iq.from = "test@example.com" @@ -370,7 +367,7 @@ class RegistrationTest < Minitest::Test Registration::Payment::InviteCode::Finish = Minitest::Mock.new def test_write - customer = Customer.new("test", plan_name: "test_usd") + customer = customer(plan_name: "test_usd") Registration::Payment::InviteCode::DB.expect(:transaction, true, []) Registration::Payment::InviteCode::Finish.expect( :new, @@ -413,7 +410,7 @@ class RegistrationTest < Minitest::Test def test_write_bad_code result = execute_command do - customer = Customer.new("test", plan_name: "test_usd") + customer = customer(plan_name: "test_usd") Registration::Payment::InviteCode::REDIS.expect( :get, EMPromise.resolve(0), @@ -467,7 +464,7 @@ class RegistrationTest < Minitest::Test def test_write_bad_code_over_limit result = execute_command do - customer = Customer.new("test", plan_name: "test_usd") + customer = customer(plan_name: "test_usd") Registration::Payment::InviteCode::REDIS.expect( :get, EMPromise.resolve(11), @@ -525,7 +522,7 @@ class RegistrationTest < Minitest::Test iq = Blather::Stanza::Iq::Command.new iq.from = "test\\40example.com@cheogram.com" @finish = Registration::Finish.new( - Customer.new("test", sgx: @sgx), + customer(sgx: @sgx), "+15555550000" ) end @@ -569,7 +566,7 @@ class RegistrationTest < Minitest::Test nil, [ "catapult_fwd-+15555550000", - "sip:test%40example.com@sip.cheogram.com" + "sip:test%40example.net@sip.cheogram.com" ] ) BackendSgx::REDIS.expect( diff --git a/test/test_transaction.rb b/test/test_transaction.rb index 443541196b3776f3ab007325aa9d29a32db25ca5..d87b7bd13e3785b5442f61271ab711d571b95777 100644 --- a/test/test_transaction.rb +++ b/test/test_transaction.rb @@ -44,7 +44,7 @@ class TransactionTest < Minitest::Test ) assert_raises("declined") do Transaction.sale( - Customer.new("test", plan_name: "test_usd"), + customer(plan_name: "test_usd"), amount: 123, payment_method: OpenStruct.new(token: "token") ).sync @@ -76,7 +76,7 @@ class TransactionTest < Minitest::Test }] ) result = Transaction.sale( - Customer.new("test", plan_name: "test_usd"), + customer(plan_name: "test_usd"), amount: 123, payment_method: OpenStruct.new(token: "token") ).sync