forked from waldher/dhl-intraship
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add webmock and add full integration specs
playmakers
committed
Mar 13, 2015
1 parent
2fd65fe
commit 1d01c7d
Showing
7 changed files
with
972 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ test/version_tmp | |
tmp | ||
atlassian-ide-plugin.xml | ||
.idea | ||
test.rb | ||
test.rb | ||
vendor/bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,65 @@ | ||
# encoding: UTF-8 | ||
|
||
require 'spec_helper' | ||
|
||
module Dhl | ||
module Intraship | ||
|
||
CREATE_RESPONSE = <<EOS | ||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> | ||
<soapenv:Body> | ||
<ns2:CreateShipmentResponse xmlns:ns2="http://de.ws.intraship"> | ||
<Version xmlns="http://dhl.de/webservice/cisbase"> | ||
<majorRelease>1</majorRelease> | ||
<minorRelease>0</minorRelease> | ||
<build>11</build> | ||
</Version> | ||
<status> | ||
<StatusCode>0</StatusCode> | ||
<StatusMessage>ok</StatusMessage> | ||
</status> | ||
<CreationState> | ||
<StatusCode>0</StatusCode> | ||
<StatusMessage>ok</StatusMessage> | ||
<SequenceNumber>1</SequenceNumber> | ||
<ShipmentNumber> | ||
<ns1:shipmentNumber xmlns:ns1="http://dhl.de/webservice/cisbase">00340433836000191469</ns1:shipmentNumber> | ||
</ShipmentNumber> | ||
<PieceInformation> | ||
<PieceNumber> | ||
<ns1:licensePlate xmlns:ns1="http://dhl.de/webservice/cisbase">00340433836000191469</ns1:licensePlate> | ||
</PieceNumber> | ||
</PieceInformation> | ||
<Labelurl>http://test-intraship.dhl.com:80/cartridge.55/WSPrint?code=2DF3501616A182E9328C91C83B00509C4A611A39324EAA66</Labelurl> | ||
</CreationState> | ||
</ns2:CreateShipmentResponse> | ||
</soapenv:Body> | ||
</soapenv:Envelope> | ||
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: '[email protected]', | ||
}), | ||
|
||
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: '[email protected]', | ||
}), | ||
|
||
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 | ||
savon.expects('de:CreateShipmentDDRequest').with do |request| | ||
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('<ServiceGroupDHLPaket>') | ||
request_xml.should include('<Multipack>True</Multipack>') | ||
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('<HigherInsurance>') | ||
request_xml.should include('<InsuranceAmount>2500</InsuranceAmount>') | ||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:[email protected]/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:de="http://de.ws.intraship" xmlns:is="http://dhl.de/webservice/is_base_de" xmlns:cis="http://dhl.de/webservice/cisbase"> | ||
<soapenv:Header> | ||
<cis:Authentification> | ||
<cis:user>user</cis:user> | ||
<cis:signature>signature</cis:signature> | ||
<cis:accountNumber>ekp12345|01|01</cis:accountNumber> | ||
<cis:type>0</cis:type> | ||
</cis:Authentification> | ||
</soapenv:Header> | ||
<soapenv:Body> | ||
<de:CreateShipmentDDRequest> | ||
<cis:Version> | ||
<cis:majorRelease>1</cis:majorRelease> | ||
<cis:minorRelease>0</cis:minorRelease> | ||
</cis:Version> | ||
<ShipmentOrder> | ||
<SequenceNumber>1</SequenceNumber> | ||
<Shipment> | ||
<ShipmentDetails> | ||
<ProductCode>EPN</ProductCode> | ||
<ShipmentDate>2015-03-13</ShipmentDate> | ||
<cis:EKP>ekp12345</cis:EKP> | ||
<Attendance> | ||
<cis:partnerID>01</cis:partnerID> | ||
</Attendance> | ||
<ShipmentItem> | ||
<WeightInKG>2.5</WeightInKG> | ||
<LengthInCM>11</LengthInCM> | ||
<WidthInCM>13</WidthInCM> | ||
<HeightInCM>3</HeightInCM> | ||
<PackageType>PK</PackageType> | ||
</ShipmentItem> | ||
</ShipmentDetails> | ||
<Shipper> | ||
<Company> | ||
<cis:Company> | ||
<cis:name1>Team Europe Ventures</cis:name1> | ||
</cis:Company> | ||
</Company> | ||
<Address> | ||
<cis:streetName>Mohrenstraße</cis:streetName> | ||
<cis:streetNumber>60</cis:streetNumber> | ||
<cis:Zip> | ||
<cis:germany>10117</cis:germany> | ||
</cis:Zip> | ||
<cis:city>Berlin</cis:city> | ||
<cis:Origin> | ||
<cis:countryISOCode>DE</cis:countryISOCode> | ||
</cis:Origin> | ||
</Address> | ||
<Communication> | ||
<cis:email>[email protected]</cis:email> | ||
<cis:contactPerson>John Smith</cis:contactPerson> | ||
</Communication> | ||
</Shipper> | ||
<Receiver> | ||
<Company> | ||
<cis:Person> | ||
<cis:salutation/> | ||
<cis:firstname>John</cis:firstname> | ||
<cis:lastname>Doe</cis:lastname> | ||
</cis:Person> | ||
</Company> | ||
<Address> | ||
<cis:streetName>Mainstreet</cis:streetName> | ||
<cis:streetNumber>10</cis:streetNumber> | ||
<cis:careOfName>Appartment 2a</cis:careOfName> | ||
<cis:Zip> | ||
<cis:germany>90210</cis:germany> | ||
</cis:Zip> | ||
<cis:city>Springfield</cis:city> | ||
<cis:Origin> | ||
<cis:countryISOCode>DE</cis:countryISOCode> | ||
</cis:Origin> | ||
</Address> | ||
<Communication> | ||
<cis:email>[email protected]</cis:email> | ||
<cis:contactPerson></cis:contactPerson> | ||
</Communication> | ||
</Receiver> | ||
</Shipment> | ||
</ShipmentOrder> | ||
</de:CreateShipmentDDRequest> | ||
</soapenv:Body> | ||
</soapenv:Envelope> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> | ||
<soapenv:Body> | ||
<ns2:CreateShipmentResponse xmlns:ns2="http://de.ws.intraship"> | ||
<Version xmlns="http://dhl.de/webservice/cisbase"> | ||
<majorRelease>1</majorRelease> | ||
<minorRelease>0</minorRelease> | ||
<build>11</build> | ||
</Version> | ||
<status> | ||
<StatusCode>0</StatusCode> | ||
<StatusMessage>ok</StatusMessage> | ||
</status> | ||
<CreationState> | ||
<StatusCode>0</StatusCode> | ||
<StatusMessage>ok</StatusMessage> | ||
<SequenceNumber>1</SequenceNumber> | ||
<ShipmentNumber> | ||
<ns1:shipmentNumber xmlns:ns1="http://dhl.de/webservice/cisbase">00340433836000191469</ns1:shipmentNumber> | ||
</ShipmentNumber> | ||
<PieceInformation> | ||
<PieceNumber> | ||
<ns1:licensePlate xmlns:ns1="http://dhl.de/webservice/cisbase">00340433836000191469</ns1:licensePlate> | ||
</PieceNumber> | ||
</PieceInformation> | ||
<Labelurl>http://test-intraship.dhl.com:80/cartridge.55/WSPrint?code=2DF3501616A182E9328C91C83B00509C4A611A39324EAA66</Labelurl> | ||
</CreationState> | ||
</ns2:CreateShipmentResponse> | ||
</soapenv:Body> | ||
</soapenv:Envelope> |
Large diffs are not rendered by default.
Oops, something went wrong.