spec/api_spec.rb in fingertips-adyen-0.3.7.20100917 vs spec/api_spec.rb in fingertips-adyen-0.3.8.20100924
- old
+ new
@@ -64,11 +64,11 @@
class PaymentService
public :authorise_payment_request_body, :authorise_recurring_payment_request_body
end
class RecurringService
- public :list_request_body
+ public :list_request_body, :disable_request_body
end
end
end
module APISpecHelper
@@ -236,10 +236,17 @@
payment = mock('PaymentService')
Adyen::API::PaymentService.should_receive(:new).with(:reference => 'order-id').and_return(payment)
payment.should_receive(:authorise_recurring_payment)
Adyen::API.authorise_recurring_payment(:reference => 'order-id')
end
+
+ it "performs a `disable recurring contract' request" do
+ recurring = mock('RecurringService')
+ Adyen::API::RecurringService.should_receive(:new).with(:shopper => { :reference => 'user-id' }).and_return(recurring)
+ recurring.should_receive(:disable)
+ Adyen::API.disable_recurring_contract(:shopper => { :reference => 'user-id' })
+ end
end
describe Adyen::API::PaymentService do
describe "for a normal payment request" do
before do
@@ -418,10 +425,16 @@
end
it "includes the type of contract, which is always `RECURRING'" do
text('./recurring:recurring/recurring:contract').should == 'RECURRING'
end
+
+ private
+
+ def node_for_current_method
+ super(@recurring).xpath('//recurring:listRecurringDetails/recurring:request')
+ end
end
describe "list" do
before do
stub_net_http(LIST_RESPONSE)
@@ -474,16 +487,62 @@
},
],
}
end
end
- end
- private
+ describe "disable_request_body" do
+ before :all do
+ @method = :disable_request_body
+ end
- def node_for_current_method
- super(@recurring).xpath('//recurring:listRecurringDetails/recurring:request')
+ it "includes the merchant account handle" do
+ text('./recurring:merchantAccount').should == 'SuperShopper'
+ end
+
+ it "includes the shopper’s reference" do
+ text('./recurring:shopperReference').should == 'user-id'
+ end
+
+ it "includes the shopper’s recurring detail reference if it is given" do
+ xpath('./recurring:recurringDetailReference').should be_empty
+ @recurring.params[:recurring_detail_reference] = 'RecurringDetailReference1'
+ text('./recurring:recurringDetailReference').should == 'RecurringDetailReference1'
+ end
+
+ private
+
+ def node_for_current_method
+ super(@recurring).xpath('//recurring:disable/recurring:request')
+ end
+ end
+
+ describe "disable" do
+ before do
+ stub_net_http(DISABLE_RESPONSE)
+ @recurring.disable
+ @request, @post = Net::HTTP.posted
+ end
+
+ after do
+ Net::HTTP.stubbing_enabled = false
+ end
+
+ it "posts the body generated for the given parameters" do
+ @post.body.should == @recurring.disable_request_body
+ end
+
+ it "posts to the correct SOAP action" do
+ @post.soap_action.should == 'disable'
+ end
+
+ for_each_xml_backend do
+ it "returns a hash with parsed response details" do
+ @recurring.disable.should == { :response => '[detail-successfully-disabled]' }
+ end
+ end
+ end
end
end
end
AUTHORISE_RESPONSE = <<EOS
@@ -555,8 +614,23 @@
</details>
<ns1:lastKnownShopperEmail>s.hopper@example.com</ns1:lastKnownShopperEmail>
<ns1:shopperReference>user-id</ns1:shopperReference>
</ns1:result>
</ns1:listRecurringDetailsResponse>
+ </soap:Body>
+</soap:Envelope>
+EOS
+
+DISABLE_RESPONSE = <<EOS
+<?xml version="1.0"?>
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <soap:Body>
+ <ns1:disableResponse xmlns:ns1="http://recurring.services.adyen.com">
+ <ns1:result>
+ <response xmlns="http://recurring.services.adyen.com">
+ [detail-successfully-disabled]
+ </response>
+ </ns1:result>
+ </ns1:disableResponse>
</soap:Body>
</soap:Envelope>
EOS