diff --git a/config-schema.dhall b/config-schema.dhall
index d2e21e0d896d454adae905ce29a8a800a7d850a3..27bcb68a08211cf8f3b303b2754739490199dfef 100644
--- a/config-schema.dhall
+++ b/config-schema.dhall
@@ -38,7 +38,7 @@
forall (currency : Text) ->
Text
, interac : Text
-, keep_area_codes : List Text
+, keep_area_codes : List { area_code: Text, premium_price : Optional Natural }
, keep_area_codes_in : { account : Text, sip_peer_id : Text, site_id : Text }
, keepgo : Optional { access_token : Text, api_key : Text }
, notify_admin : Text
diff --git a/config.dhall.sample b/config.dhall.sample
index 0a1f573af331f828f50cf486fc75c661fa43ea70..01047c72a341ba57504dcdd8a0e5e9e6ff69050f 100644
--- a/config.dhall.sample
+++ b/config.dhall.sample
@@ -102,7 +102,7 @@ in
direct_sources = toMap {
`support@example.com` = "+15551234567"
},
- keep_area_codes = ["555"],
+ keep_area_codes = [{ area_code = "555", premium_price = Some 10 }],
keep_area_codes_in = { account = "", site_id = "", sip_peer_id = "" },
snikket_hosting_api = "",
onboarding_domain = "",
diff --git a/lib/bandwidth_tn_repo.rb b/lib/bandwidth_tn_repo.rb
index 8deeb0d451416e7a524a6ac11d6427b0deac4093..b8f8d6bc1b01727babc3ed6ea911b5afdd565570 100644
--- a/lib/bandwidth_tn_repo.rb
+++ b/lib/bandwidth_tn_repo.rb
@@ -9,13 +9,15 @@ class BandwidthTnRepo
region,
locality,
source,
- available_after
+ available_after,
+ premium_price
) VALUES (
$1,
$2,
$3,
$4,
- LOCALTIMESTAMP + '1 MONTH'
+ LOCALTIMESTAMP + '1 MONTH',
+ $5
)
SQL
@@ -46,20 +48,26 @@ class BandwidthTnRepo
raise "Could not set CNAM, please contact support"
end
- def stash_for_later(tel, btn)
+ # @param [String] tel
+ # @param [BandwidthIris::Tn] btn
+ # @param [Numeric] premium_price
+ def stash_for_later(tel, btn, premium_price)
LOG.info "stash_for_later #{tel}\n#{caller}"
details = btn.get_details
region = details[:state]
locality = details[:city]
- params = [tel, region, locality, CONFIG[:creds][:account]]
+ params = [tel, region, locality, CONFIG[:creds][:account], premium_price]
DB.exec(STASH_QUERY, params)
end
def disconnect(tel, order_name)
tn = tel.sub(/\A\+1/, "")
btn = BandwidthIris::Tn.new({ telephone_number: tn }, @move_client)
- if CONFIG[:keep_area_codes].find { |area| tn.start_with?(area) }
- stash_for_later(tel, btn)
+ code_and_price = CONFIG[:keep_area_codes].find { |keep|
+ tn.start_with?(keep[:area_code])
+ }
+ if code_and_price
+ stash_for_later(tel, btn, code_and_price[:premium_price] || 0)
else
BandwidthIris::Disconnect.create(order_name, tn)
end
diff --git a/test/test_admin_command.rb b/test/test_admin_command.rb
index 5dcd629b9602c5abfb0f75ef87ff0aa8abf40c3e..7534c5c5b4c07c3d2f9d869ad76e0b7b99125c0b 100644
--- a/test/test_admin_command.rb
+++ b/test/test_admin_command.rb
@@ -342,7 +342,7 @@ class AdminCommandTest < Minitest::Test
def test_action_cancel_account_keep_number
details_response = {
- "TelephoneNumberDetails": {
+ TelephoneNumberDetails: {
State: "NY",
City: "MANHATTEN"
}
@@ -382,7 +382,7 @@ class AdminCommandTest < Minitest::Test
sgx, admin = admin_command("+15566667777")
- sql_params = ["+15566667777", "NY", "MANHATTEN", "test_bw_account"]
+ sql_params = ["+15566667777", "NY", "MANHATTEN", "test_bw_account", 10]
BandwidthTnRepo::DB.expect(
:exec,
diff --git a/test/test_bandwidth_tn_repo.rb b/test/test_bandwidth_tn_repo.rb
new file mode 100644
index 0000000000000000000000000000000000000000..a90b4fd38bb000ac55c726eb50aa11d4513e6b9b
--- /dev/null
+++ b/test/test_bandwidth_tn_repo.rb
@@ -0,0 +1,84 @@
+# frozen_string_literal: true
+
+require "test_helper"
+require "bandwidth_tn_repo"
+
+BandwidthTnRepo::DB = Minitest::Mock.new
+
+class BandwidthTnRepoTest < Minitest::Test
+ def test_local_inventory_recycled_with_price
+ stub_request(
+ :get,
+ "https://dashboard.bandwidth.com/v1.0/tns/5565555555/tndetails"
+ )
+ .with(
+ headers: {
+ "Accept" => "application/xml",
+ "Accept-Encoding" => "gzip, compressed",
+ "Authorization" => "Basic dGVzdF9id191c2VyOnRlc3RfYndfcGFzc3dvcmQ=",
+ "User-Agent" => "Ruby-Bandwidth-Iris"
+ }
+ ).to_return(status: 200, body: <<~XML, headers: {})
+
+
+ Austin
+ TX
+
+
+ XML
+
+ tel = "+15565555555"
+
+ BandwidthTnRepo::DB.expect(
+ :exec,
+ nil,
+ [
+ BandwidthTnRepo::STASH_QUERY,
+ [tel, "TX", "Austin", "test_bw_account", 10]
+ ]
+ )
+
+ BandwidthTnRepo.new.disconnect(tel, "test")
+
+ assert_mock BandwidthTnRepo::DB
+ end
+ em :test_local_inventory_recycled_with_price
+
+ def test_local_inventory_recycled_no_price
+ stub_request(
+ :get,
+ "https://dashboard.bandwidth.com/v1.0/tns/5575555555/tndetails"
+ )
+ .with(
+ headers: {
+ "Accept" => "application/xml",
+ "Accept-Encoding" => "gzip, compressed",
+ "Authorization" => "Basic dGVzdF9id191c2VyOnRlc3RfYndfcGFzc3dvcmQ=",
+ "User-Agent" => "Ruby-Bandwidth-Iris"
+ }
+ ).to_return(status: 200, body: <<~XML, headers: {})
+
+
+ Austin
+ TX
+
+
+ XML
+
+ tel = "+15575555555"
+
+ BandwidthTnRepo::DB.expect(
+ :exec,
+ nil,
+ [
+ BandwidthTnRepo::STASH_QUERY,
+ [tel, "TX", "Austin", "test_bw_account", 0]
+ ]
+ )
+
+ BandwidthTnRepo.new.disconnect(tel, "test")
+
+ assert_mock BandwidthTnRepo::DB
+ end
+ em :test_local_inventory_recycled_no_price
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 3539f9ba0fcdf798dd1da593a5d294e67922fb07..a424f07f0b047ccea604e08e5af55f0f71b86978 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -157,7 +157,10 @@ CONFIG = {
CAD: { price: 400, plan: "500MB" }
}
},
- keep_area_codes: ["556"],
+ keep_area_codes: [
+ { area_code: "556", premium_price: 10 },
+ { area_code: "557", premium_price: nil }
+ ],
keep_area_codes_in: {
account: "moveto",
site_id: "movetosite",