Skip to content

Commit b192291

Browse files
Justintime50claude
andcommitted
refactor: use mocked tests instead of cassettes for FedEx registration
- Remove VCR cassettes for FedEx registration tests - Use RSpec mocking to stub client.make_request calls - Return EasyPostObject for all FedEx registration responses - Matches Java PR approach of mocking request/response instead of recording cassettes Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 10268f5 commit b192291

6 files changed

Lines changed: 64 additions & 129 deletions

lib/easypost/services/fedex_registration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def register_address(fedex_account_number, params = {})
1010

1111
response = @client.make_request(:post, endpoint, wrapped_params)
1212

13-
EasyPost::InternalUtilities::Json.convert_json_to_object(response, EasyPost::Models::FedExAccountValidationResponse)
13+
EasyPost::InternalUtilities::Json.convert_json_to_object(response, EasyPost::Models::EasyPostObject)
1414
end
1515

1616
# Request a PIN for FedEx account verification.

spec/cassettes/fedex_registration/EasyPost_Services_FedexRegistration_register_address_registers_a_billing_address.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

spec/cassettes/fedex_registration/EasyPost_Services_FedexRegistration_request_pin_requests_a_pin.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

spec/cassettes/fedex_registration/EasyPost_Services_FedexRegistration_submit_invoice_submits_details_about_an_invoice.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

spec/cassettes/fedex_registration/EasyPost_Services_FedexRegistration_validate_pin_validates_a_pin.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

spec/fedex_registration_spec.rb

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,21 @@
2424
easypost_details: easypost_details,
2525
}
2626

27+
json_response = {
28+
'email_address' => nil,
29+
'options' => %w[SMS CALL INVOICE],
30+
'phone_number' => '***-***-9721',
31+
}
32+
33+
allow(client).to receive(:make_request).with(
34+
:post,
35+
"fedex_registrations/#{fedex_account_number}/address",
36+
params,
37+
).and_return(json_response)
38+
2739
response = client.fedex_registration.register_address(fedex_account_number, params)
2840

29-
expect(response).to be_an_instance_of(EasyPost::Models::FedExAccountValidationResponse)
41+
expect(response).to be_an_instance_of(EasyPost::Models::EasyPostObject)
3042
expect(response.email_address).to be_nil
3143
expect(response.options).to include('SMS')
3244
expect(response.options).to include('CALL')
@@ -38,10 +50,25 @@
3850
describe '.request_pin' do
3951
it 'requests a pin' do
4052
fedex_account_number = '123456789'
53+
wrapped_params = {
54+
pin_method: {
55+
option: 'SMS',
56+
},
57+
}
58+
59+
json_response = {
60+
'message' => 'sent secured Pin',
61+
}
62+
63+
allow(client).to receive(:make_request).with(
64+
:post,
65+
"fedex_registrations/#{fedex_account_number}/pin",
66+
wrapped_params,
67+
).and_return(json_response)
4168

4269
response = client.fedex_registration.request_pin(fedex_account_number, 'SMS')
4370

44-
expect(response).to be_an_instance_of(EasyPost::Models::FedExRequestPinResponse)
71+
expect(response).to be_an_instance_of(EasyPost::Models::EasyPostObject)
4572
expect(response.message).to eq('sent secured Pin')
4673
end
4774
end
@@ -61,9 +88,25 @@
6188
easypost_details: easypost_details,
6289
}
6390

91+
json_response = {
92+
'id' => 'ca_123',
93+
'object' => 'CarrierAccount',
94+
'type' => 'FedexAccount',
95+
'credentials' => {
96+
'account_number' => '123456789',
97+
'mfa_key' => '123456789-XXXXX',
98+
},
99+
}
100+
101+
allow(client).to receive(:make_request).with(
102+
:post,
103+
"fedex_registrations/#{fedex_account_number}/pin/validate",
104+
params,
105+
).and_return(json_response)
106+
64107
response = client.fedex_registration.validate_pin(fedex_account_number, params)
65108

66-
expect(response).to be_an_instance_of(EasyPost::Models::FedExAccountValidationResponse)
109+
expect(response).to be_an_instance_of(EasyPost::Models::EasyPostObject)
67110
expect(response.id).to eq('ca_123')
68111
expect(response.object).to eq('CarrierAccount')
69112
expect(response.type).to eq('FedexAccount')
@@ -90,9 +133,25 @@
90133
easypost_details: easypost_details,
91134
}
92135

136+
json_response = {
137+
'id' => 'ca_123',
138+
'object' => 'CarrierAccount',
139+
'type' => 'FedexAccount',
140+
'credentials' => {
141+
'account_number' => '123456789',
142+
'mfa_key' => '123456789-XXXXX',
143+
},
144+
}
145+
146+
allow(client).to receive(:make_request).with(
147+
:post,
148+
"fedex_registrations/#{fedex_account_number}/invoice",
149+
params,
150+
).and_return(json_response)
151+
93152
response = client.fedex_registration.submit_invoice(fedex_account_number, params)
94153

95-
expect(response).to be_an_instance_of(EasyPost::Models::FedExAccountValidationResponse)
154+
expect(response).to be_an_instance_of(EasyPost::Models::EasyPostObject)
96155
expect(response.id).to eq('ca_123')
97156
expect(response.object).to eq('CarrierAccount')
98157
expect(response.type).to eq('FedexAccount')

0 commit comments

Comments
 (0)