From 6f019455a26cea485babd446f078142f4364803b Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 14 Sep 2022 10:31:32 -0500 Subject: [PATCH] Include customer id as CustomerOrderId when ordering number So we can tell who ordered a number in case of issues --- lib/bandwidth_tn_order.rb | 4 ++-- lib/registration.rb | 5 ++++- test/test_bandwidth_tn_order.rb | 22 ++++++++++++++++++++++ test/test_helper.rb | 4 +++- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/bandwidth_tn_order.rb b/lib/bandwidth_tn_order.rb index bf2093f..2acbd61 100644 --- a/lib/bandwidth_tn_order.rb +++ b/lib/bandwidth_tn_order.rb @@ -15,10 +15,10 @@ class BandwidthTNOrder end end - def self.create(tel, name: "sgx-jmp order #{tel}") + def self.create(tel, name: "sgx-jmp order #{tel}", **kwargs) EMPromise.resolve(nil).then do Received.new(BandwidthIris::Order.create( - name: name, + name: name, **kwargs, site_id: CONFIG[:bandwidth_site], peer_id: CONFIG[:bandwidth_peer], existing_telephone_number_order_type: { diff --git a/lib/registration.rb b/lib/registration.rb index 3c78924..4d13f71 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -461,7 +461,10 @@ class Registration end def write - BandwidthTNOrder.create(@tel).then(&:poll).then( + BandwidthTNOrder.create( + @tel, + customer_order_id: @customer.customer_id + ).then(&:poll).then( ->(_) { customer_active_tel_purchased }, ->(_) { number_purchase_error } ) diff --git a/test/test_bandwidth_tn_order.rb b/test/test_bandwidth_tn_order.rb index da03a3b..ffa2bef 100644 --- a/test/test_bandwidth_tn_order.rb +++ b/test/test_bandwidth_tn_order.rb @@ -4,6 +4,28 @@ require "test_helper" require "bandwidth_tn_order" class BandwidthTNOrderTest < Minitest::Test + def test_create + req = stub_request( + :post, + "https://dashboard.bandwidth.com/v1.0/accounts//orders" + ).with( + body: { + Name: "sgx-jmp order +15551234567", + CustomerOrderId: "test", + SiteId: "test_site", + PeerId: "test_peer", + ExistingTelephoneNumberOrderType: { + TelephoneNumberList: { + TelephoneNumber: "5551234567" + } + } + }.to_xml(indent: 0, root: "Order") + ).to_return(status: 200) + BandwidthTNOrder.create("+15551234567", customer_order_id: "test").sync + assert_requested req + end + em :test_create + def test_for_received order = BandwidthTNOrder.for(BandwidthIris::Order.new( order_status: "RECEIVED" diff --git a/test/test_helper.rb b/test/test_helper.rb index c774145..5ba9e94 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -108,7 +108,9 @@ CONFIG = { approved_domains: { "approved.example.com": nil, "refer.example.com": "refer_to" - } + }, + bandwidth_site: "test_site", + bandwidth_peer: "test_peer" }.freeze def panic(e) -- 2.34.7