From 1d01c7d53c8f85e052ec15f63fa58b8179e38382 Mon Sep 17 00:00:00 2001 From: playmakers Date: Fri, 13 Mar 2015 13:01:28 +0100 Subject: [PATCH] Add webmock and add full integration specs --- .gitignore | 3 +- dhl-intraship.gemspec | 1 + spec/dhl-intraship/create_shipment_dd_spec.rb | 88 +- spec/spec_helper.rb | 10 + spec/support/create_shipment_dd_request.xml | 86 ++ spec/support/create_shipment_dd_response.xml | 29 + .../geschaeftskundenversand-api-1.0.wsdl | 798 ++++++++++++++++++ 7 files changed, 972 insertions(+), 43 deletions(-) create mode 100644 spec/support/create_shipment_dd_request.xml create mode 100644 spec/support/create_shipment_dd_response.xml create mode 100644 spec/support/geschaeftskundenversand-api-1.0.wsdl diff --git a/.gitignore b/.gitignore index c25d6fd..90e44a4 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ test/version_tmp tmp atlassian-ide-plugin.xml .idea -test.rb \ No newline at end of file +test.rb +vendor/bundle diff --git a/dhl-intraship.gemspec b/dhl-intraship.gemspec index 057e7c3..8af629f 100644 --- a/dhl-intraship.gemspec +++ b/dhl-intraship.gemspec @@ -11,6 +11,7 @@ Gem::Specification.new do |gem| gem.add_dependency "savon", "~> 1.1.0" gem.add_development_dependency "rspec", "~> 2.11.0" gem.add_development_dependency "savon_spec", "~> 1.3.0" + gem.add_development_dependency "webmock" gem.files = `git ls-files`.split($\) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } diff --git a/spec/dhl-intraship/create_shipment_dd_spec.rb b/spec/dhl-intraship/create_shipment_dd_spec.rb index 28b17f0..5f2caf2 100644 --- a/spec/dhl-intraship/create_shipment_dd_spec.rb +++ b/spec/dhl-intraship/create_shipment_dd_spec.rb @@ -1,56 +1,57 @@ +# encoding: UTF-8 + require 'spec_helper' module Dhl module Intraship - CREATE_RESPONSE = < - - - - 1 - 0 - 11 - - - 0 - ok - - - 0 - ok - 1 - - 00340433836000191469 - - - - 00340433836000191469 - - - http://test-intraship.dhl.com:80/cartridge.55/WSPrint?code=2DF3501616A182E9328C91C83B00509C4A611A39324EAA66 - - - - -EOS - + CREATE_REQUEST = File.read('spec/support/create_shipment_dd_request.xml') + CREATE_RESPONSE = File.read('spec/support/create_shipment_dd_response.xml') describe API do + subject { @api.createShipmentDD(@shipment) } + before(:each) do savon.expects("de:CreateShipmentDDRequest").returns(code: 200, headers: {}, body: CREATE_RESPONSE) - config = { user: 'user', signature: 'signature', ekp: 'ekp12345', api_user: 'test', api_pwd: 'test' } options = { test: true } @api = API.new(config, options) - @shipment = Shipment.new(shipment_date: Date.today + 1, - sender_address: CompanyAddress.new, - receiver_address: PersonAddress.new, - shipment_items: ShipmentItem.new(weight: 2.5, length: 11, width: 13, height: 3)) + @shipment = Shipment.new({ + shipment_date: Date.parse('2015-03-13'), + + sender_address: CompanyAddress.new({ + company: 'Team Europe Ventures', + contact_person: 'John Smith', + street: 'Mohrenstraße', + house_number: '60', + zip: '10117', + city: 'Berlin', + country_code: 'DE', + email: 'info@teameurope.net', + }), + + receiver_address: PersonAddress.new({ + firstname: 'John', + lastname: 'Doe', + street: 'Mainstreet', + house_number: '10', + street_additional: 'Appartment 2a', + zip: '90210', + city: 'Springfield', + country_code: 'DE', + email: 'john.doe@example.com', + }), + + shipment_items: ShipmentItem.new(weight: 2.5, length: 11, width: 13, height: 3) + }) end it "should create an API call" do - @api.createShipmentDD(@shipment).should_not be_nil + savon.expects('de:CreateShipmentDDRequest').with do |request| + request.soap.to_xml.should == CREATE_REQUEST.gsub(/>\s+/,'>') + end.returns(code: 200, headers: {}, body: CREATE_RESPONSE) + + should_not be_nil end it "should not add multipack service with only one shipment item" do @@ -58,7 +59,7 @@ module Intraship request.soap.to_xml.should_not include('Multipack') end.returns(code: 200, headers: {}, body: CREATE_RESPONSE) - @api.createShipmentDD(@shipment).should_not be_nil + should_not be_nil end it "should add multipack service" do @@ -68,7 +69,8 @@ module Intraship request_xml.should include('') request_xml.should include('True') end.returns(code: 200, headers: {}, body: CREATE_RESPONSE) - @api.createShipmentDD(@shipment).should_not be_nil + + should_not be_nil end it "should add dhl express service with higher insurance server" do @@ -83,13 +85,15 @@ module Intraship request_xml.should include('') request_xml.should include('2500') end.returns(code: 200, headers: {}, body: CREATE_RESPONSE) - @api.createShipmentDD(@shipment).should_not be_nil + + should_not be_nil end it "should validate service dependencies" do dhl_express_service = DhlExpressService.new(DhlExpressService::DELIVERY_ON_TIME, '13:51') @shipment.add_service(dhl_express_service) - expect { @api.createShipmentDD(@shipment) }.to raise_error(RuntimeError, 'The DhlExpressService can only be add to DHL Domestic Express (EXP) shipments.') + + expect { subject }.to raise_error(RuntimeError, 'The DhlExpressService can only be add to DHL Domestic Express (EXP) shipments.') end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ea5b319..9b35abf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,20 @@ require 'savon/spec' +require "webmock/rspec" require "dhl-intraship" # Prevent warnings: http://stackoverflow.com/questions/5009838/httpi-tried-to-user-the-httpi-adapter-error-using-savon-soap-library HTTPI.log = false +Savon.configure do |config| + config.log = false +end + RSpec.configure do |config| config.include Savon::Spec::Macros + + config.before do + stub_request(:get, "https://test:test@cig.dhl.de/cig-wsdls/com/dpdhl/wsdl/geschaeftskundenversand-api/1.0/geschaeftskundenversand-api-1.0.wsdl"). + to_return(:body => File.read('spec/support/geschaeftskundenversand-api-1.0.wsdl')) + end end diff --git a/spec/support/create_shipment_dd_request.xml b/spec/support/create_shipment_dd_request.xml new file mode 100644 index 0000000..167d84a --- /dev/null +++ b/spec/support/create_shipment_dd_request.xml @@ -0,0 +1,86 @@ + + + + + user + signature + ekp12345|01|01 + 0 + + + + + + 1 + 0 + + + 1 + + + EPN + 2015-03-13 + ekp12345 + + 01 + + + 2.5 + 11 + 13 + 3 + PK + + + + + + Team Europe Ventures + + +
+ Mohrenstraße + 60 + + 10117 + + Berlin + + DE + +
+ + info@teameurope.net + John Smith + +
+ + + + + John + Doe + + +
+ Mainstreet + 10 + Appartment 2a + + 90210 + + Springfield + + DE + +
+ + john.doe@example.com + + +
+
+
+
+
+
diff --git a/spec/support/create_shipment_dd_response.xml b/spec/support/create_shipment_dd_response.xml new file mode 100644 index 0000000..e8b3ba3 --- /dev/null +++ b/spec/support/create_shipment_dd_response.xml @@ -0,0 +1,29 @@ + + + + + 1 + 0 + 11 + + + 0 + ok + + + 0 + ok + 1 + + 00340433836000191469 + + + + 00340433836000191469 + + + http://test-intraship.dhl.com:80/cartridge.55/WSPrint?code=2DF3501616A182E9328C91C83B00509C4A611A39324EAA66 + + + + diff --git a/spec/support/geschaeftskundenversand-api-1.0.wsdl b/spec/support/geschaeftskundenversand-api-1.0.wsdl new file mode 100644 index 0000000..4d753b7 --- /dev/null +++ b/spec/support/geschaeftskundenversand-api-1.0.wsdl @@ -0,0 +1,798 @@ + + + + + + + + + + + + + + The authentication data. + + + + + The shipmentdata for creating a TD shipment. + + + + + + The status of the createShipment operation and the identifier for the shipment. + + + + + + The shipmentdata for creating a DD shipment. + + + + + + The status of the createShipment operation and the identifier for the shipment. + + + + + + The identifier for the shipment which should be deleted. + + + + + + The status of the deletion operation. + + + + + + The identifier for the shipment which should be deleted. + + + + + + The status of the deletion operation. + + + + + + The identifier for the shipment which should be manifested. + + + + + + The status of the manifest operation. + + + + + + The identifier for the shipment which should be manifested. + + + + + + The status of the manifest operation. + + + + + + The identifier for the TD shipment for which the label url is requested. + + + + + + The status of the operation and the label url (if available). + + + + + + The identifier for the DD shipment for which the label url is requested. + + + + + + The status of the operation and the label url (if available). + + + + + + The data for a pickup order. + + + + + + The status of the book pickup operation and a confirmation number (if available). + + + + + + The confirmation number of the pickup order which should be canceled. + + + + + + The status of cancel pickup operation. + + + + + + The version of webservice implementation. + + + + + + The version of webservice implementation. + + + + + + The identifier for the TD shipment for which the label url is requested. + + + + + + The status of the operation and the label url (if available). + + + + + + The identifier for the DD shipment for which the label url is requested. + + + + + + The status of the operation and the label url (if available). + + + + + + Request a manifest of the given date / date range. + + + + + + The status of the operation and the manifest url (if available). + + + + + + Request a manifest of the given date / date range. + + + + + + The status of the operation and the manifest url (if available). + + + + + + + + Creates TD shipments. + + The shipment data. + + + The status of the createShipment operation and the identifier for the shipment. + + + + + Creates DD shipments. + + The shipment data. + + + The status of the createShipment operation and the identifier for the shipment. + + + + + Deletes the requested TD shipments. + + The identifier for the shipment which should be deleted. + + + The status of the deletion operation. + + + + + Deletes the requested DD shipments. + + The identifier for the shipment which should be deleted. + + + The status of the deletion operation. + + + + + Manifest the requested TD shipments. + + The identifier for the shipment which should be manifested. + + + The status of the manifest operation. + + + + + Manifest the requested DD shipments. + + The identifier for the shipment which should be manifested. + + + The status of the manifest operation. + + + + + Returns the request-url for getting a TD label. + + The identifier for the TD shipment for which the label url is requested. + + + The status of the operation and the label url (if available). + + + + + Returns the request-url for getting a DD label. + + The identifier for the DD shipment for which the label url is requested. + + + The status of the operation and the label url (if available). + + + + + Books a pickup order. + + The data for a pickup order. + + + The status of the book pickup operation and a confirmation number (if available). + + + + + Cancels a pickup order. + + The confirmation number of the pickup order which should be canceled. + + + The status of cancel pickup operation. + + + + + Returns the actual version of the implementation of the whole ISService webservice. + + + The version of webservice implementation. + + + + + Returns the request-url for getting a TD export document. + + The identifier for the TD shipment for which the export document url is requested. + + + The status of the operation and the export document url (if available). + + + + + Returns the request-url for getting a DD export document. + + The identifier for the DD shipment for which the export document url is requested. + + + The status of the operation and the export document url (if available). + + + + + Request the manifest. + + The request data. + + + The status of the getManifest operation and the manifest url. + + + + + Updates a DD shipment. + + The shipment data. + + + The status of the updateShipment operation and the identifier for the shipment. + + + + + + + + + + + Creates TD shipments. + + + The authentication data and the shipment data. + + + + + The status of the operation and the shipment identifier. + + + + + + Creates DD shipments. + + + The authentication data and the shipment data. + + + + + The status of the operation and the shipment identifier. + + + + + + Deletes the requested TD shipments. + + + The authentication data and the shipment identifier. + + + + + The status of the operation. + + + + + + Deletes the requested DD shipments. + + + The authentication data and the shipment identifier. + + + + + The status of the operation. + + + + + + Manifest the requested TD shipments. + + + The authentication data and the shipment identifier. + + + + + The status of the operation. + + + + + + Manifest the requested DD shipments. + + + The authentication data and the shipment identifier. + + + + + The status of the operation. + + + + + + Returns the request-url for getting a TD label. + + + The authentication data and the shipment identifier. + + + + + The status of the operation and the url for requesting the label. + + + + + + Returns the request-url for getting a DD label. + + + The authentication data and the shipment identifier. + + + + + The status of the operation and the url for requesting the label. + + + + + + Books a pickup order. + + + The authentication data and the order data for the pickup + + + + + The status of the operation and the confirmation number (if available). + + + + + + Cancels a pickup order. + + + The authentication data and the confirmation number of the pickuporder, which should be canceled + + + + + The status of the operation. + + + + + + + Returns the actual version of the implementation of the whole ISService webservice. + + + + + + The version of the implementation. + + + + + + Returns the request-url for getting a TD export document. + + + The authentication data and the shipment identifier. + + + + + The status of the operation and the url for requesting the export document. + + + + + + Returns the request-url for getting a DD export document. + + + The authentication data and the shipment identifier. + + + + + The status of the operation and the url for requesting the export document. + + + + + + Requests the manifest. + + + The authentication data and the shipment data. + + + + + The status of the operation and the manifest url. + + + + + + Updates a DD shipment. + + + The authentication data and the shipment data. + + + + + The status of the operation + + + + + + + + + Creates TD shipments. + + + The authentication data and the shipment data. + + + + + The status of the operation and the shipment identifier. + + + + + + Creates DD shipments. + + + The authentication data and the shipment data. + + + + + The status of the operation and the shipment identifier. + + + + + + Deletes the requested TD shipments. + + + The authentication data and the shipment identifier. + + + + + + + + + + Deletes the requested DD shipments. + + + The authentication data and the shipment identifier. + + + + + + + + + + Manifest the requested TD shipments. + + + The authentication data and the shipment identifier. + + + + + + + + + + Manifest the requested DD shipments. + + + The authentication data and the shipment identifier. + + + + + + + + + + Returns the request-url for getting a TD label. + + + The authentication data and the shipment identifier. + + + + + The status of the operation and the url for requesting the label. + + + + + + Returns the request-url for getting a DD label. + + + The authentication data and the shipment identifier. + + + + + The status of the operation and the url for requesting the label. + + + + + + Books a pickup order. + + + The authentication data and the order data for the pickup + + + + + The status of the operation and the confirmation number (if available). + + + + + + Cancels a pickup order. + + + The authentication data and the confirmation number of the pickuporder, which should be canceled + + + + + The status of the operation. + + + + + + Returns the actual version of the implementation of the whole ISService webservice. + + + + + + The version of the implementation. + + + + + + Returns the request-url for getting a TD export document. + + + The authentication data and the shipment identifier. + + + + + The status of the operation and the url for requesting the export document. + + + + + + Returns the request-url for getting a DD export document. + + + The authentication data and the shipment identifier. + + + + + The status of the operation and the url for requesting the export document. + + + + + + Returns the request-url for getting a DD manifest document. + + + The authentication data and the manifest data. + + + + + The status of the operation and the url for requesting the manifest document. + + + + + + Updates a DD shipment. + + + The authentication data and the shipment data. + + + + + The status of the operation. + + + + + + + + + + + + + + + + + \ No newline at end of file