diff --git a/lib/transaction.rb b/lib/transaction.rb index 9ba47fce64776cf6e60d4e3b5539f609b1bb6f26..27172052e32e04865fdf7c20e1763c3ef12ac07b 100644 --- a/lib/transaction.rb +++ b/lib/transaction.rb @@ -8,8 +8,10 @@ class Transaction value_semantics do customer_id String transaction_id String - created_at Time, coerce: ->(x) { Time.parse(x.to_s) } - settled_after Time, coerce: ->(x) { Time.parse(x.to_s) } + created_at Time, coerce: ->(x) { Time.parse(x.to_s) }, + default_generator: -> { Time.now } + settled_after Time, coerce: ->(x) { Time.parse(x.to_s) }, + default_generator: -> { Time.now } amount BigDecimal, coerce: ->(x) { BigDecimal(x, 4) } note String bonus_eligible? Bool(), default: true diff --git a/test/test_registration.rb b/test/test_registration.rb index 33651e4d13db524141363397b4a0ec66badfef35..29323813da1c9907959c7590f5f24fe5d304281b 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -770,13 +770,14 @@ class RegistrationTest < Minitest::Test Registration::Finish::DB = Minitest::Mock.new Bwmsgsv2Repo::REDIS = Minitest::Mock.new Registration::FinishOnboarding::DB = FakeDB.new + Transaction::DB = Minitest::Mock.new def setup @sgx = Minitest::Mock.new(TrivialBackendSgxRepo.new.get("test")) iq = Blather::Stanza::Iq::Command.new iq.from = "test\\40example.com@cheogram.com" @finish = Registration::Finish.new( - customer(sgx: @sgx), + customer(sgx: @sgx, plan_name: "test_usd"), "+15555550000" ) end @@ -885,6 +886,130 @@ class RegistrationTest < Minitest::Test end em :test_write + def test_write_with_pending_code + create_order = stub_request( + :post, + "https://dashboard.bandwidth.com/v1.0/accounts//orders" + ).to_return(status: 201, body: <<~RESPONSE) + + + test_order + + + RESPONSE + stub_request( + :get, + "https://dashboard.bandwidth.com/v1.0/accounts//orders/test_order" + ).to_return(status: 201, body: <<~RESPONSE) + + COMPLETE + + + 5555550000 + + + + RESPONSE + stub_request( + :post, + "https://dashboard.bandwidth.com/v1.0/accounts//sites//sippeers//movetns" + ) + Registration::Finish::REDIS.expect( + :del, + nil, + ["pending_tel_for-test@example.net"] + ) + Registration::Finish::REDIS.expect( + :get, + EMPromise.resolve("123"), + ["jmp_customer_pending_invite-test"] + ) + Registration::Finish::REDIS.expect( + :del, + nil, + ["jmp_customer_pending_invite-test"] + ) + Registration::Finish::REDIS.expect( + :hget, + EMPromise.resolve("test-inviter"), + ["jmp_group_codes", "123"] + ) + Registration::Finish::DB.expect( + :exec, + EMPromise.resolve(nil), + [String, ["test-inviter", "test"]] + ) + Transaction::DB.expect(:transaction, nil) do |&blk| + blk.call + true + end + Transaction::DB.expect( + :exec, + nil, + [String, Matching.new { |params| + assert_equal "test", params[0] + assert params[1].start_with?("referral_") + assert_equal 1, params[4] + assert_equal "Referral Bonus", params[5] + }] + ) + Bwmsgsv2Repo::REDIS.expect( + :set, + nil, + [ + "catapult_fwd-+15555550000", + "xmpp:test@example.net" + ] + ) + Bwmsgsv2Repo::REDIS.expect( + :set, + nil, + ["catapult_fwd_timeout-customer_test@component", 25] + ) + Customer::BLATHER.expect( + :<<, + nil, + [Matching.new do |m| + assert_equal :chat, m.type + assert m.body =~ /^Welcome to JMP/ + end] + ) + blather = Minitest::Mock.new + blather.expect( + :<<, + nil, + [Matching.new do |reply| + assert_equal :completed, reply.status + assert_equal :info, reply.note_type + assert_equal( + "Your JMP account has been activated as +15555550000", + reply.note.content + ) + end] + ) + execute_command(blather: blather) do + @sgx.expect( + :register!, + EMPromise.resolve(@sgx.with( + registered?: Blather::Stanza::Iq::IBR.new.tap do |ibr| + ibr.phone = "+15555550000" + end + )), + ["+15555550000"] + ) + + @finish.write + end + assert_requested create_order + assert_mock @sgx + assert_mock Registration::Finish::REDIS + assert_mock Bwmsgsv2Repo::REDIS + assert_mock Customer::BLATHER + assert_mock blather + assert_mock Transaction::DB + end + em :test_write_with_pending_code + def test_write_onboarding create_order = stub_request( :post,