require 'helper' class TestPxpay < Test::Unit::TestCase context "valid gem" do should "provide a default pxpay url" do assert_match(Pxpay::Base.pxpay_request_url, "https://sec.paymentexpress.com/pxpay/pxaccess.aspx") end should "allow pxpay url to be overwritten" do Pxpay::Base.pxpay_request_url = "http://example.com" assert_match(Pxpay::Base.pxpay_request_url, "http://example.com") Pxpay::Base.pxpay_request_url = nil end end context "create a request object" do setup do @request = Pxpay::Request.new( 1, 12.34 ) end should "generate an xml request" do assert_match(/GenerateRequest/, @request.post ) end should "generate an xml request with username and id" do assert_match(/Test_Dev<\/PxPayUserId>\w{64}<\/PxPayKey>/, @request.post ) end should "generate an xml request with correct amount" do assert_match(/12.34<\/AmountInput>/, @request.post) end should "generate xml with provided endpoints" do request_with_url = Pxpay::Request.new( 1, 12.34, { :url_success => "http://example.com/success", :url_failure => "http://example.com/success" }) assert_match %r(http://example.com/successhttp://example.com/success), request_with_url.post assert_no_match /localhost/, request_with_url.post end # should "return a URL" do # assert_match(/https:\/\/sec2.paymentexpress.com\/pxpay\/pxpay.aspx\?userid=\w{64}&request=\S{270}/, @request.url) # end end context "create a response object" do setup do @response_text = "v5l4alYudyoKcCD1vSADyfiuWv4QqCKyJVdaXCuJR0_7jUyj9reTWi7Jdhe5-xtbDRlwLpPG56qO7AOKR-h65Awaa886kw9vjf5YglO1fz2wyyshMsaJT5XrEhGFBsNLycaqou0rxwRxF4Y0chcA_laRn8Ev1sOqpNNXafUwP2fDMQVQ7gla11Ibdv7K5v0TIvV28rPVLZgnbty5rtnK_AdR0W9XOXpo6w4NlNzh81KcFJeVc_5n_4QITRZ1zVYrrCGzg3T3S902ej1kgqBGGJf904IWEgNfbjc8teg3ereUWLYhDK-E3FrP-v3L06VxRwR96wZkkO2rucYUrxc2drOQfZipqijabZTRjyoLK37jFQkg5JfrQPOvXZaQeY6eby2Voh_XLAYtoUawPPvkupiEI3b5_TlANhnOLl0_fUS95ObLG1VIHenw==" @response = Pxpay::Response.new(:userid => 'Test_Dev', :result => @response_text ) end should "generate an xml request" do assert_match(/ProcessResponse/, @response.post ) end should "generate an xml request with username and id" do assert_match(/#{Pxpay::Base.pxpay_user_id}<\/PxPayUserId>#{Pxpay::Base.pxpay_key}<\/PxPayKey>/, @response.post ) end should "generate an xml request with the correct response text" do assert_match( %r(#{@response_text}