test_bandwidth_tn_repo.rb

 1# frozen_string_literal: true
 2
 3require "test_helper"
 4require "bandwidth_tn_repo"
 5
 6BandwidthTnRepo::DB = Minitest::Mock.new
 7
 8class BandwidthTnRepoTest < Minitest::Test
 9	def test_local_inventory_recycled_with_price
10		stub_request(
11			:get,
12			"https://dashboard.bandwidth.com/v1.0/tns/5565555555/tndetails"
13		)
14			.with(
15				headers: {
16					"Accept" => "application/xml",
17					"Accept-Encoding" => "gzip, compressed",
18					"Authorization" => "Basic dGVzdF9id191c2VyOnRlc3RfYndfcGFzc3dvcmQ=",
19					"User-Agent" => "Ruby-Bandwidth-Iris"
20				}
21			).to_return(status: 200, body: <<~XML, headers: {})
22				<Response>
23					<TelephoneNumberDetails>
24						<City>Austin</City>
25						<State>TX</State>
26					</TelephoneNumberDetails>
27				</Response>
28			XML
29
30		tel = "+15565555555"
31
32		BandwidthTnRepo::DB.expect(
33			:exec,
34			nil,
35			[
36				BandwidthTnRepo::STASH_QUERY,
37				[tel, "TX", "Austin", "test_bw_account", 10]
38			]
39		)
40
41		BandwidthTnRepo.new.disconnect(tel, "test")
42
43		assert_mock BandwidthTnRepo::DB
44	end
45	em :test_local_inventory_recycled_with_price
46
47	def test_local_inventory_recycled_no_price
48		stub_request(
49			:get,
50			"https://dashboard.bandwidth.com/v1.0/tns/5575555555/tndetails"
51		)
52			.with(
53				headers: {
54					"Accept" => "application/xml",
55					"Accept-Encoding" => "gzip, compressed",
56					"Authorization" => "Basic dGVzdF9id191c2VyOnRlc3RfYndfcGFzc3dvcmQ=",
57					"User-Agent" => "Ruby-Bandwidth-Iris"
58				}
59			).to_return(status: 200, body: <<~XML, headers: {})
60				<Response>
61					<TelephoneNumberDetails>
62						<City>Austin</City>
63						<State>TX</State>
64					</TelephoneNumberDetails>
65				</Response>
66			XML
67
68		tel = "+15575555555"
69
70		BandwidthTnRepo::DB.expect(
71			:exec,
72			nil,
73			[
74				BandwidthTnRepo::STASH_QUERY,
75				[tel, "TX", "Austin", "test_bw_account", 0]
76			]
77		)
78
79		BandwidthTnRepo.new.disconnect(tel, "test")
80
81		assert_mock BandwidthTnRepo::DB
82	end
83	em :test_local_inventory_recycled_no_price
84end