spec/veritrans_client_spec.rb in veritrans-2.0.4 vs spec/veritrans_client_spec.rb in veritrans-2.1.0

- old
+ new

@@ -1,6 +1,6 @@ -describe Veritrans do +describe Veritrans::Client do before do hide_const("Rails") Veritrans.logger = Logger.new("/dev/null") Veritrans.setup do @@ -19,15 +19,15 @@ {body: request.body} }) result = Veritrans.request_with_logging(:get, Veritrans.config.api_host + "/ping", {}) - api_request.headers["Host"].should == "api.sandbox.veritrans.co.id" + api_request.headers["Host"].should == "api.sandbox.veritrans.co.id:443" end it "should use Veritrans.http_options to attach hedaers", vcr: false do - Veritrans::Config.stub(:http_options) do + Veritrans.config.stub(:http_options) do { headers: { "X-Rspec" => "ok" } } end api_request = nil stub_request(:any, /.*/).to_return(lambda { |request| @@ -38,10 +38,51 @@ result = Veritrans.request_with_logging(:get, Veritrans.config.api_host + "/ping", {}) api_request.headers["X-Rspec"].should == "ok" end + it "should be able to create other instance of client" do + #Veritrans.logger = Logger.new(STDOUT) + + VCR.configure do |c| + c.allow_http_connections_when_no_cassette = true + end + + other_client = Veritrans.new( + server_key: "69b61a1b-b0b1-450b-a697-37109dbbecb0", + logger: Logger.new("/dev/null") + ) # M000937 + + result = Veritrans.charge( + payment_type: "mandiri_clickpay", + transaction_details: { + gross_amount: 10_000, + order_id: Time.now.to_s + }, + mandiri_clickpay: { + card_number: "4111 1111 1111 1111".gsub(/\s/, ''), + input3: "%05d" % (rand * 100000).to_i, + input2: 10000, + input1: "1" * 10, + token: "000000" + }, + ) + + #p result.request_options + + other_result = other_client.status(result.transaction_id) + + other_result.status_code.should == 404 + other_result.status_message.should == "The requested resource is not found" + + #p other_result.request_options + + VCR.configure do |c| + c.allow_http_connections_when_no_cassette = true + end + end + it "should send charge vt-web request" do VCR.use_cassette('charge_vtweb') do result = Veritrans.charge('vtweb', transaction: { order_id: Time.now.to_s, gross_amount: 100_000 } ) result.status_message.should == "OK, success do VTWeb transaction, please go to redirect_url" @@ -124,7 +165,20 @@ VCR.use_cassette('expire_failed', record: :once) do result = Veritrans.expire("not-exists") result.success?.should == false result.status_message.should == "The requested resource is not found" end + end + + it "should handle network exceptions", vcr: false do + Excon::Connection.any_instance.stub(:send) do + raise Excon::Errors::SocketError, Excon::Errors::Error.new("testing exception") + end + + result = Veritrans.expire("not-exists") + result.status.should == "500" + result.data.should == { + status_code: "500", + status_message: "Internal server error, no response from backend. Try again later" + } end end \ No newline at end of file