# frozen_string_literal: true require "test_helper" require "sip_account" class SipAccount attr_reader :password end class SipAccountTest < Minitest::Test def setup @sip = SipAccount.new( BandwidthIris::SipCredential.new( user_name: "12345", realm: "sip.example.com", http_voice_v2_app_id: "sipappid" ) ).with(password: "old password") end def test_with_random_password new_sip = @sip.with_random_password refute_equal @sip.password, new_sip.password refute_empty new_sip.password assert_kind_of String, new_sip.password end def test_form form = @sip.form assert_equal "12345", form.field("username").value assert_equal "old password", form.field("password").value assert_equal "sip.example.com", form.field("server").value end def test_put put = stub_request( :put, "https://dashboard.bandwidth.com/v1.0/accounts//sipcredentials/12345" ).with( body: { Hash1: "73b05bcaf9096438c978aecff5f7cc45", Hash1b: "2b7fe68f6337ef4db29e752684a18db4", Realm: "sip.example.com", HttpVoiceV2AppId: "sipappid" }.to_xml(indent: 0, root: "SipCredential"), headers: { "Authorization" => "Basic Og==" } ).to_return( status: 201, headers: { "Location" => "http://example.com/endpoint" } ) new_sip = @sip.put assert_equal "12345", new_sip.username assert_requested put end em :test_put def test_put_fail stub_request( :put, "https://dashboard.bandwidth.com/v1.0/accounts//sipcredentials/12345" ).to_return(status: 400) assert_raises(BandwidthIris::Errors::GenericError) { @sip.put } end em :test_put_fail class NewTest < Minitest::Test def setup @sip = SipAccount.new( BandwidthIris::SipCredential.new( user_name: "12345", realm: "sip.example.com", http_voice_v2_app_id: "sipappid" ) ).with(password: "old password") end def test_with_random_password new_sip = @sip.with_random_password refute_equal @sip.password, new_sip.password refute_empty new_sip.password assert_kind_of String, new_sip.password end def test_put post = stub_request( :put, "https://dashboard.bandwidth.com/v1.0/accounts//sipcredentials/12345" ).with( body: { Hash1: "73b05bcaf9096438c978aecff5f7cc45", Hash1b: "2b7fe68f6337ef4db29e752684a18db4", Realm: "sip.example.com", HttpVoiceV2AppId: "sipappid" }.to_xml(indent: 0, root: "SipCredential"), headers: { "Authorization" => "Basic Og==" } ).to_return(status: 201) new_sip = @sip.put assert_equal "12345", new_sip.username assert_requested post end em :test_put end end