Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `beta_referral_customer.create_bank_account_client_secret`
- `referral_customer.add_credit_card_from_stripe`
- `referral_customer.add_bank_account_from_stripe`
- Routes `AmazonShippingAccount` to the proper create endpoint
- Fixes error parsing
- Allows for alternative format of `errors` field
- Corrects available properties of an `EasyPostError` and `ApiError` (`code` and `field` removed from `EasyPostError`, `message` unfurled and explicitly added to `ApiError`)
Expand Down
5 changes: 5 additions & 0 deletions lib/easypost/services/carrier_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class EasyPost::Services::CarrierAccount < EasyPost::Services::Service
CUSTOM_WORKFLOW_CARRIER_TYPES = %w[FedexAccount FedexSmartpostAccount].freeze
UPS_OAUTH_CARRIER_ACCOUNT_TYPES = %w[UpsAccount UpsMailInnovationsAccount UpsSurepostAccount].freeze
CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = %w[AmazonShippingAccount].freeze
MODEL_CLASS = EasyPost::Models::CarrierAccount # :nodoc:

# Create a carrier account
Expand All @@ -15,6 +16,8 @@ def create(params = {})
'carrier_accounts/register'
elsif UPS_OAUTH_CARRIER_ACCOUNT_TYPES.include?(carrier_account_type)
'ups_oauth_registrations'
elsif CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.include?(carrier_account_type)
'carrier_accounts/register_oauth'
else
'carrier_accounts'
end
Expand Down Expand Up @@ -63,6 +66,8 @@ def delete(id)
def select_top_layer_key(carrier_account_type)
if UPS_OAUTH_CARRIER_ACCOUNT_TYPES.include?(carrier_account_type)
'ups_oauth_registrations'
elsif CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.include?(carrier_account_type)
'carrier_account_oauth_registrations'
else
'carrier_account'
end
Expand Down
29 changes: 21 additions & 8 deletions spec/carrier_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
client.carrier_account.delete(carrier_account.id)
end

it 'creates an UPS account' do
it 'creates a UPS account' do
carrier_account = client.carrier_account.create({ type: 'UpsAccount', account_number: '123456789' })

expect(carrier_account).to be_an_instance_of(EasyPost::Models::CarrierAccount)
Expand All @@ -28,15 +28,28 @@
client.carrier_account.delete(carrier_account.id)
end

it 'sends FedexAccount to the correct endpoint' do
allow(client).to receive(:make_request).with(
:post, 'carrier_accounts/register',
{ carrier_account: { type: 'FedexAccount' } },
).and_return({ 'id' => 'ca_123' })
it 'creates a FedEx account' do
expect {
client.carrier_account.create({ type: 'FedexAccount', registration_data: {} })
}.to raise_error(EasyPost::Errors::ApiError) { |error|
expect(error.status_code).to eq(422)
expect(
error.errors.any? do |err|
err['field'] == 'account_number' && err['message'] == 'must be present and a string'
end,
).to be true
}
end

response = client.carrier_account.create(type: 'FedexAccount')
it 'creates an Amazon account' do
carrier_account = client.carrier_account.create({ type: 'AmazonShippingAccount', account_number: '123456789' })

expect(response['id']).to eq('ca_123')
expect(carrier_account).to be_an_instance_of(EasyPost::Models::CarrierAccount)
expect(carrier_account.id).to match('ca_')
expect(carrier_account.type).to eq('AmazonShippingAccount')

# Remove the carrier account once we have tested it so we don't pollute the account with test accounts
client.carrier_account.delete(carrier_account.id)
end
end

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.