diff --git a/lib/postnord.rb b/lib/postnord.rb index e5f25fb..85eea2f 100644 --- a/lib/postnord.rb +++ b/lib/postnord.rb @@ -3,11 +3,11 @@ require 'net/https' require 'json' require 'openssl' -require 'byebug' require 'postnord/client' require 'postnord/response' require 'postnord/base' +require 'postnord/business_location' require 'postnord/shipment' require 'postnord/transport' require 'postnord/version' diff --git a/lib/postnord/business_location.rb b/lib/postnord/business_location.rb index da372a4..6760853 100644 --- a/lib/postnord/business_location.rb +++ b/lib/postnord/business_location.rb @@ -2,7 +2,7 @@ module Postnord # Classes - class BusinessLocation + class BusinessLocation < Base def self.service 'businesslocation' end diff --git a/spec/postnord/base_spec.rb b/spec/postnord/base_spec.rb new file mode 100644 index 0000000..e66f453 --- /dev/null +++ b/spec/postnord/base_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +RSpec.describe Postnord::Base do + describe '.mandatory_params' do + it 'raises not implemented error' do + expect { + described_class.send(:mandatory_params) + }.to raise_error(NotImplementedError, 'mandatory_params') + end + end + + describe '.endpoint' do + it 'raises not implemented error' do + expect { + described_class.send(:endpoint) + }.to raise_error(NotImplementedError, 'endpoint') + end + end + + describe '.validate_params' do + before do + expect(described_class).to receive(:mandatory_params).and_return(['param1', 'param2']) + end + + context 'with missing param' do + it 'raises missing mandatory parameters error' do + expect { + described_class.send(:validate_params, { param1: 'test' }) + }.to raise_error(Postnord::Base::MissingMandatoryParameters, /param2/) + end + end + + context 'without missing param' do + it 'does not raise any error' do + expect { + described_class.send(:validate_params, { param1: 'test', param2: 'test' }) + }.not_to raise_error(Postnord::Base::MissingMandatoryParameters) + end + end + end +end diff --git a/spec/postnord/business_location_spec.rb b/spec/postnord/business_location_spec.rb new file mode 100644 index 0000000..182a41f --- /dev/null +++ b/spec/postnord/business_location_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +RSpec.describe Postnord::BusinessLocation do + describe '.service' do + it 'uses correct service' do + expect(described_class.service).to eq 'businesslocation' + end + end +end + +RSpec.describe Postnord::FindNearestByCoordinates do + describe '.endpoint' do + it 'calls correct endpoint' do + expect(described_class.endpoint).to eq 'servicepoint/findNearestByCoordinates' + end + end +end + +RSpec.describe Postnord::FindByPostalCode do + describe '.endpoint' do + it 'calls correct endpoint' do + expect(described_class.endpoint).to eq 'servicepoint/findByPostalCode' + end + end +end + +RSpec.describe Postnord::FindNearestByAddress do + describe '.endpoint' do + it 'calls correct endpoint' do + expect(described_class.endpoint).to eq 'servicepoint/findNearestByAddress' + end + end +end + +RSpec.describe Postnord::GetServicePointInformation do + describe '.endpoint' do + it 'calls correct endpoint' do + expect(described_class.endpoint).to eq 'servicepoint/getServicePointInformation' + end + end +end diff --git a/spec/postnord/shipment_spec.rb b/spec/postnord/shipment_spec.rb new file mode 100644 index 0000000..7671ea8 --- /dev/null +++ b/spec/postnord/shipment_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +RSpec.describe Postnord::Shipment do + describe '.service' do + it 'uses correct service' do + expect(described_class.service).to eq 'shipment' + end + end +end + +RSpec.describe Postnord::FindByIdentifier do + describe '.endpoint' do + it 'calls correct endpoint' do + expect(described_class.endpoint).to eq 'trackandtrace/findByIdentifier' + end + end +end + +RSpec.describe Postnord::FindByNotificationCode do + describe '.endpoint' do + it 'calls correct endpoint' do + expect(described_class.endpoint).to eq 'trackandtrace/findByNotificationCode' + end + end +end + +RSpec.describe Postnord::FindByReference do + describe '.endpoint' do + it 'calls correct endpoint' do + expect(described_class.endpoint).to eq 'trackandtrace/findByReference' + end + end +end diff --git a/spec/postnord/transport_spec.rb b/spec/postnord/transport_spec.rb new file mode 100644 index 0000000..5e2889c --- /dev/null +++ b/spec/postnord/transport_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +RSpec.describe Postnord::Transport do + describe '.service' do + it 'uses correct service' do + expect(described_class.service).to eq 'transport' + end + end +end + +RSpec.describe Postnord::GetTransitTimeInformation do + describe '.endpoint' do + it 'calls endpoint' do + expect(described_class.endpoint).to eq 'transittime/getTransitTimeInformation' + end + end +end diff --git a/spec/postnord_spec.rb b/spec/postnord_spec.rb index 5195758..de9695a 100644 --- a/spec/postnord_spec.rb +++ b/spec/postnord_spec.rb @@ -5,7 +5,49 @@ expect(Postnord::VERSION).not_to be nil end - it 'does something useful' do - expect(false).to eq(true) + describe '.find_by_identifier' do + let(:id) { '123' } + + before do + expect(Postnord::FindByIdentifier).to receive(:call).with({ + id: id, + }) + end + + it 'calls FindByIdentifier with correct params' do + described_class.find_by_identifier(id) + end + end + + describe '.find_by_notification_code' do + let(:phone_number) { '0701112233' } + let(:notification_code) { '123' } + + before do + expect(Postnord::FindByNotificationCode).to receive(:call).with({ + notificationPhoneNumber: phone_number, + notificationCode: notification_code, + }) + end + + it 'calls FindByNotificationCode with correct params' do + described_class.find_by_notification_code(phone_number, notification_code) + end + end + + describe '.find_by_reference' do + let(:customer_number) { '123' } + let(:reference_value) { '456' } + + before do + expect(Postnord::FindByReference).to receive(:call).with({ + customerNumber: customer_number, + referenceValue: reference_value, + }) + end + + it 'calls FindByReference with correct params' do + described_class.find_by_reference(customer_number, reference_value) + end end end