# 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: {})
				<Response>
					<TelephoneNumberDetails>
						<City>Austin</City>
						<State>TX</State>
					</TelephoneNumberDetails>
				</Response>
			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: {})
				<Response>
					<TelephoneNumberDetails>
						<City>Austin</City>
						<State>TX</State>
					</TelephoneNumberDetails>
				</Response>
			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
