pass price from LocalInventory to Option#option

Phillip Davis created

Change summary

lib/tel_selections.rb       | 11 +++++++++--
test/test_tel_selections.rb | 15 +++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)

Detailed changes

lib/tel_selections.rb 🔗

@@ -249,8 +249,11 @@ class TelSelections
 					@region = state
 				end
 
-				def option
-					op = Blather::Stanza::X::Field::Option.new(value: tel, label: to_s)
+				def option(label: nil)
+					op = Blather::Stanza::X::Field::Option.new(
+						value: tel,
+						label: label || to_s
+					)
 					op << reference
 					op
 				end
@@ -301,6 +304,10 @@ class TelSelections
 					@price = price || 0
 				end
 
+				def option
+					super(label: to_s)
+				end
+
 				# Creates and inserts transaction charging the customer
 				# for the phone number. If price <= 0 this is a noop.
 				# This method never checks customer balance.

test/test_tel_selections.rb 🔗

@@ -168,6 +168,11 @@ class TelSelectionsTest < Minitest::Test
 				state: "ON",
 				garbage: "stuff"
 			)
+			@local_tel = TelSelections::ChooseTel::Tn::LocalInventory.new(
+				@tn,
+				"test_account",
+				price: 10.0
+			)
 		end
 
 		def test_to_s
@@ -188,6 +193,16 @@ class TelSelectionsTest < Minitest::Test
 			)
 		end
 
+		def test_option_positive_price
+			assert_equal(
+				Blather::Stanza::X::Field::Option.new(
+					label: "(555) 123-4567 (Toronto, ON) +$10.00",
+					value: "+15551234567"
+				),
+				@local_tel.option
+			)
+		end
+
 		def test_option_reference
 			ref = @tn.option.find("ns:reference", ns: "urn:xmpp:reference:0").first
 			assert_equal(