Skip to content

Commit

Permalink
Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanahman committed Jun 17, 2016
1 parent fa40be6 commit 2a5f8d4
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/postnord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion lib/postnord/business_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Postnord

# Classes

class BusinessLocation
class BusinessLocation < Base
def self.service
'businesslocation'
end
Expand Down
41 changes: 41 additions & 0 deletions spec/postnord/base_spec.rb
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions spec/postnord/business_location_spec.rb
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions spec/postnord/shipment_spec.rb
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions spec/postnord/transport_spec.rb
Original file line number Diff line number Diff line change
@@ -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
46 changes: 44 additions & 2 deletions spec/postnord_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2a5f8d4

Please sign in to comment.