-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathfedex_registration_spec.rb
More file actions
162 lines (140 loc) · 4.75 KB
/
fedex_registration_spec.rb
File metadata and controls
162 lines (140 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# frozen_string_literal: true
require 'spec_helper'
describe EasyPost::Services::FedexRegistration do
let(:client) { EasyPost::Client.new(api_key: ENV['EASYPOST_PROD_API_KEY']) }
describe '.register_address' do
it 'registers a billing address' do
fedex_account_number = '123456789'
address_validation = {
name: 'BILLING NAME',
street1: '1234 BILLING STREET',
city: 'BILLINGCITY',
state: 'ST',
postal_code: '12345',
country_code: 'US',
}
easypost_details = {
carrier_account_id: 'ca_123',
}
params = {
address_validation: address_validation,
easypost_details: easypost_details,
}
json_response = {
'email_address' => nil,
'options' => %w[SMS CALL INVOICE],
'phone_number' => '***-***-9721',
}
allow(client).to receive(:make_request).with(
:post,
"fedex_registrations/#{fedex_account_number}/address",
params,
).and_return(json_response)
response = client.fedex_registration.register_address(fedex_account_number, params)
expect(response).to be_an_instance_of(EasyPost::Models::EasyPostObject)
expect(response.email_address).to be_nil
expect(response.options).to include('SMS')
expect(response.options).to include('CALL')
expect(response.options).to include('INVOICE')
expect(response.phone_number).to eq('***-***-9721')
end
end
describe '.request_pin' do
it 'requests a pin' do
fedex_account_number = '123456789'
wrapped_params = {
pin_method: {
option: 'SMS',
},
}
json_response = {
'message' => 'sent secured Pin',
}
allow(client).to receive(:make_request).with(
:post,
"fedex_registrations/#{fedex_account_number}/pin",
wrapped_params,
).and_return(json_response)
response = client.fedex_registration.request_pin(fedex_account_number, 'SMS')
expect(response).to be_an_instance_of(EasyPost::Models::EasyPostObject)
expect(response.message).to eq('sent secured Pin')
end
end
describe '.validate_pin' do
it 'validates a pin' do
fedex_account_number = '123456789'
pin_validation = {
pin_code: '123456',
name: 'BILLING NAME',
}
easypost_details = {
carrier_account_id: 'ca_123',
}
params = {
pin_validation: pin_validation,
easypost_details: easypost_details,
}
json_response = {
'id' => 'ca_123',
'object' => 'CarrierAccount',
'type' => 'FedexAccount',
'credentials' => {
'account_number' => '123456789',
'mfa_key' => '123456789-XXXXX',
},
}
allow(client).to receive(:make_request).with(
:post,
"fedex_registrations/#{fedex_account_number}/pin/validate",
params,
).and_return(json_response)
response = client.fedex_registration.validate_pin(fedex_account_number, params)
expect(response).to be_an_instance_of(EasyPost::Models::EasyPostObject)
expect(response.id).to eq('ca_123')
expect(response.object).to eq('CarrierAccount')
expect(response.type).to eq('FedexAccount')
expect(response.credentials['account_number']).to eq('123456789')
expect(response.credentials['mfa_key']).to eq('123456789-XXXXX')
end
end
describe '.submit_invoice' do
it 'submits details about an invoice' do
fedex_account_number = '123456789'
invoice_validation = {
name: 'BILLING NAME',
invoice_number: 'INV-12345',
invoice_date: '2025-12-08',
invoice_amount: '100.00',
invoice_currency: 'USD',
}
easypost_details = {
carrier_account_id: 'ca_123',
}
params = {
invoice_validation: invoice_validation,
easypost_details: easypost_details,
}
json_response = {
'id' => 'ca_123',
'object' => 'CarrierAccount',
'type' => 'FedexAccount',
'credentials' => {
'account_number' => '123456789',
'mfa_key' => '123456789-XXXXX',
},
}
allow(client).to receive(:make_request).with(
:post,
"fedex_registrations/#{fedex_account_number}/invoice",
params,
).and_return(json_response)
response = client.fedex_registration.submit_invoice(fedex_account_number, params)
expect(response).to be_an_instance_of(EasyPost::Models::EasyPostObject)
expect(response.id).to eq('ca_123')
expect(response.object).to eq('CarrierAccount')
expect(response.type).to eq('FedexAccount')
expect(response.credentials['account_number']).to eq('123456789')
expect(response.credentials['mfa_key']).to eq('123456789-XXXXX')
end
end
end