easypost 2.7.1 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::ScanForm do
4
- let(:shipment) do
5
- shipment = EasyPost::Shipment.create(
6
- to_address: ADDRESS[:canada],
7
- from_address: ADDRESS[:california],
8
- parcel: PARCEL[:dimensions],
9
- customs_info: CUSTOMS_INFO[:shirt]
10
- )
11
-
12
- shipment.buy(
13
- rate: shipment.lowest_rate("usps")
14
- )
15
- end
16
-
17
- describe '#create' do
18
- it 'purchases postage for an international shipment' do
19
- scan_form = EasyPost::ScanForm.create(shipments: [shipment])
20
-
21
- expect(scan_form.id).not_to be_nil
22
- expect(scan_form.tracking_codes.first).to eq(shipment.tracking_code)
23
- end
24
- end
25
-
26
- describe '#retrieve' do
27
- let(:scan_form) { EasyPost::ScanForm.create(shipments: [shipment]) }
28
-
29
- it 'retrieves the same scan_form' do
30
- scan_form2 = EasyPost::ScanForm.retrieve(scan_form.id)
31
-
32
- expect(scan_form2.id).to eq(scan_form.id)
33
- end
34
- end
35
-
36
- describe '#all' do
37
- let!(:scan_form) { EasyPost::ScanForm.create(shipments: [shipment]) }
38
-
39
- it 'indexes the scan_forms' do
40
- params = {page_size: 2}
41
- scan_forms = EasyPost::ScanForm.all(params)
42
-
43
- expect(scan_forms["scan_forms"].first.id).to eq(scan_form.id)
44
- end
45
- end
46
- end
@@ -1,169 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::Shipment do
4
- describe '#create' do
5
- it 'creates a shipment object' do
6
-
7
- shipment = EasyPost::Shipment.create(
8
- to_address: ADDRESS[:california],
9
- from_address: EasyPost::Address.create(ADDRESS[:missouri]),
10
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
11
- )
12
- expect(shipment).to be_an_instance_of(EasyPost::Shipment)
13
- expect(shipment.from_address).to be_an_instance_of(EasyPost::Address)
14
-
15
- end
16
- end
17
-
18
- describe '#buy' do
19
- it 'purchases postage for an international shipment' do
20
-
21
- shipment = EasyPost::Shipment.create(
22
- to_address: EasyPost::Address.create(ADDRESS[:canada]),
23
- from_address: ADDRESS[:california],
24
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
25
- customs_info: EasyPost::CustomsInfo.create(CUSTOMS_INFO[:shirt])
26
- )
27
- expect(shipment).to be_an_instance_of(EasyPost::Shipment)
28
-
29
- shipment.buy(
30
- rate: shipment.lowest_rate("usps")
31
- )
32
- expect(shipment.postage_label.label_url.length).to be > 0
33
- end
34
-
35
- it 'purchases postage for a domestic shipment' do
36
- shipment = EasyPost::Shipment.create(
37
- to_address: EasyPost::Address.create(ADDRESS[:missouri]),
38
- from_address: ADDRESS[:california],
39
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
40
- )
41
- expect(shipment).to be_an_instance_of(EasyPost::Shipment)
42
-
43
- shipment.buy(
44
- rate: shipment.lowest_rate("usps")
45
- )
46
- expect(shipment.postage_label.label_url.length).to be > 0
47
- end
48
-
49
- it 'creates and returns a tracker with shipment purchase' do
50
- shipment = EasyPost::Shipment.create(
51
- :to_address => ADDRESS[:missouri],
52
- :from_address => ADDRESS[:california],
53
- :parcel => PARCEL[:dimensions]
54
- )
55
- expect(shipment).to be_an_instance_of(EasyPost::Shipment)
56
-
57
- shipment.buy(
58
- :rate => shipment.lowest_rate("usps")
59
- )
60
-
61
- tracker = shipment.tracker
62
- expect(tracker.shipment_id).to eq(shipment.id)
63
- end
64
-
65
- it 'purchases postage when only a rate id is provided' do
66
- shipment = EasyPost::Shipment.create(
67
- :to_address => ADDRESS[:missouri],
68
- :from_address => ADDRESS[:california],
69
- :parcel => PARCEL[:dimensions]
70
- )
71
- expect(shipment).to be_an_instance_of(EasyPost::Shipment)
72
-
73
- rate = shipment.rates.first
74
- rate_hash = {id: rate.id}
75
-
76
- shipment.buy(
77
- :rate => rate_hash
78
- )
79
-
80
- expect(shipment.postage_label.label_url.length).to be > 0
81
- tracker = shipment.tracker
82
- expect(tracker.shipment_id).to eq(shipment.id)
83
- end
84
- end
85
-
86
- describe '#insure' do
87
- it 'buys and insures a shipments' do
88
- shipment = EasyPost::Shipment.create(
89
- :to_address => ADDRESS[:missouri],
90
- :from_address => ADDRESS[:california],
91
- :parcel => PARCEL[:dimensions]
92
- )
93
- expect(shipment).to be_an_instance_of(EasyPost::Shipment)
94
-
95
- shipment.buy(
96
- :rate => shipment.lowest_rate("usps")
97
- )
98
-
99
- shipment.insure(amount: 100)
100
-
101
- expect(shipment.insurance).to eq("100.00")
102
- end
103
- end
104
-
105
- describe '#stamp' do
106
- it 'returns a stamp for a domestic shipment' do
107
- shipment = EasyPost::Shipment.create(
108
- to_address: EasyPost::Address.create(ADDRESS[:missouri]),
109
- from_address: ADDRESS[:california],
110
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
111
- )
112
- expect(shipment).to be_an_instance_of(EasyPost::Shipment)
113
-
114
- shipment.buy(
115
- rate: shipment.lowest_rate(['USPS', 'UPS'], 'priority, express')
116
- )
117
-
118
- stamp_url = shipment.stamp
119
-
120
- expect(stamp_url.length).to be > 0
121
- end
122
- end
123
-
124
- describe '#barcode' do
125
- it 'returns a barcode for a domestic shipment' do
126
- shipment = EasyPost::Shipment.create(
127
- to_address: EasyPost::Address.create(ADDRESS[:missouri]),
128
- from_address: ADDRESS[:california],
129
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
130
- )
131
- expect(shipment).to be_an_instance_of(EasyPost::Shipment)
132
-
133
- shipment.buy(
134
- rate: shipment.lowest_rate('usps', ['Priority'])
135
- )
136
-
137
- barcode_url = shipment.barcode
138
-
139
- expect(barcode_url.length).to be > 0
140
- end
141
- end
142
-
143
- describe '#lowest_rate' do
144
- context 'domestic shipment' do
145
- before :all do
146
- @shipment = EasyPost::Shipment.create(
147
- to_address: EasyPost::Address.create(ADDRESS[:missouri]),
148
- from_address: ADDRESS[:california],
149
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
150
- )
151
- end
152
-
153
- it 'filters negative services' do
154
- rate = @shipment.lowest_rate('USPS', '!MediaMail, !LibraryMail')
155
-
156
- expect(rate.service).to eql('ParcelSelect')
157
- end
158
- end
159
- end
160
-
161
- describe '#retrieve' do
162
- it 'retrieves shipment by tracking_code and correctly sets ID field (this was a bug in python)' do
163
- tracking_code = "LN123456789US"
164
- shipment = EasyPost::Shipment.retrieve(tracking_code)
165
-
166
- expect(shipment.id).not_to eq(tracking_code)
167
- end
168
- end
169
- end
@@ -1,10 +0,0 @@
1
- require 'open-uri'
2
- require 'easypost'
3
-
4
- Dir["./spec/support/**/*.rb"].each { |f| require f }
5
-
6
- RSpec.configure do |config|
7
- config.before(:each) do
8
- EasyPost.api_key = 'cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi'
9
- end
10
- end
@@ -1,97 +0,0 @@
1
- ADDRESS = {
2
- california: {
3
- company: 'EasyPost',
4
- street1: '164 Townsend Street',
5
- street2: 'Unit 1',
6
- city: 'San Francisco',
7
- state: 'CA',
8
- zip: '94107',
9
- phone: '415-123-4567'
10
- },
11
- california_no_phone: {
12
- company: 'EasyPost',
13
- street1: '164 Townsend Street',
14
- street2: 'Unit 1',
15
- city: 'San Francisco',
16
- state: 'CA',
17
- zip: '94107'
18
- },
19
- missouri: {
20
- company: 'Airport Shipping',
21
- street1: '601 Brasilia Avenue',
22
- city: 'Kansas City',
23
- state: 'MO',
24
- zip: '64153',
25
- phone: '314-924-0383',
26
- email: 'kansas_shipping@example.com'
27
- },
28
- canada: {
29
- name: 'Sawyer Bateman',
30
- street1: '58 Larkspur Cres.',
31
- city: 'St. Albert',
32
- state: 'AB',
33
- zip: 'T8N2M4',
34
- country: 'CA',
35
- phone: '780-123-4567'
36
- },
37
- canada_no_phone: {
38
- name: 'Sawyer Bateman',
39
- street1: '58 Larkspur Cres.',
40
- city: 'St. Albert',
41
- state: 'AB',
42
- zip: 't8n2m4',
43
- country: 'CA',
44
- phone: '780-273-8374'
45
- }
46
- }
47
-
48
- PARCEL = {
49
- dimensions: {
50
- width: 12,
51
- length: 16.5,
52
- height: 9.5,
53
- weight: 40.1
54
- },
55
- dimensions_light: {
56
- width: 15.2,
57
- length: 18,
58
- height: 9.5,
59
- weight: 3
60
- },
61
- predefined_medium_flat_rate_box: {
62
- predefined_package: 'MediumFlatRateBox',
63
- weight: 17
64
- }
65
- }
66
-
67
- CUSTOMS_INFO = {
68
- shirt: {
69
- integrated_form_type: 'form_2976',
70
- customs_certify: true,
71
- customs_signer: 'Dr. Pepper',
72
- contents_type: 'gift',
73
- contents_explanation: '', # only required when contents_type: 'other'
74
- eel_pfc: 'NOEEI 30.37(a)',
75
- non_delivery_option: 'abandon',
76
- restriction_type: 'none',
77
- restriction_comments: '',
78
- customs_items: [{
79
- description: 'EasyPost T-shirts',
80
- quantity: 2,
81
- value: 23.56,
82
- weight: 20,
83
- origin_country: 'us',
84
- hs_tariff_number: 123456
85
- }]
86
- },
87
- merchandise: {
88
- customs_certify: true,
89
- customs_signer: 'Dr. Pepper',
90
- contents_type: 'merchandise',
91
- contents_explanation: '', # only required when contents_type: 'other'
92
- eel_pfc: 'NOEEI 30.37(a)',
93
- non_delivery_option: 'abandon',
94
- restriction_type: 'none',
95
- restriction_comments: ''
96
- }
97
- }
@@ -1,94 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::Tracker do
4
- let(:tracking_code) { 'EZ2000000002' }
5
- let(:carrier) { 'usps' }
6
-
7
- describe '#create' do
8
- it 'tracks' do
9
- tracker = EasyPost::Tracker.create({
10
- tracking_code: tracking_code,
11
- carrier: carrier
12
- })
13
-
14
- expect(tracker.carrier).to eq(carrier.upcase)
15
- expect(tracker.tracking_code).to eq(tracking_code)
16
- expect(tracker.status).to eq("in_transit")
17
- expect(tracker.tracking_details.length).to be > 0
18
- end
19
- end
20
-
21
- describe '#index' do
22
- it 'retrieves a full page of trackers' do
23
- trackers = EasyPost::Tracker.all
24
-
25
- expect(trackers["trackers"].count).to eq(30)
26
- expect(trackers["has_more"]).to eq(true)
27
- end
28
-
29
- it 'retrieves all trackers with given tracking code, up to a page' do
30
- trackers = EasyPost::Tracker.all(tracking_code: tracking_code)
31
-
32
- expect(trackers["trackers"].count).to eq(30)
33
- expect(trackers["has_more"]).to eq(true)
34
- end
35
-
36
- it 'retrieves all trackers with given tracking code and carrier, up to a page' do
37
- trackers = EasyPost::Tracker.all(tracking_code: tracking_code, carrier: carrier)
38
-
39
- expect(trackers["trackers"].count).to eq(30)
40
- expect(trackers["has_more"]).to eq(true)
41
- end
42
-
43
- it 'retrieves trackers correctly based on datetime' do
44
- datetime = Time.now.utc
45
-
46
- tracker = EasyPost::Tracker.create({
47
- tracking_code: tracking_code,
48
- carrier: carrier
49
- })
50
-
51
- trackers = EasyPost::Tracker.all(start_datetime: datetime, tracking_code: tracking_code)
52
-
53
- expect(trackers["trackers"].count).to eq(1)
54
- expect(trackers["trackers"].first.id).to eq(tracker.id)
55
- expect(trackers["has_more"]).to eq(false)
56
-
57
- trackers = EasyPost::Tracker.all(end_datetime: datetime, tracking_code: tracking_code)
58
-
59
- expect(trackers["trackers"].count).to eq(30)
60
- trackers["trackers"].each do |trk|
61
- expect(trk.id).not_to eq(tracker.id)
62
- end
63
- expect(trackers["has_more"]).to eq(true)
64
- end
65
-
66
- it 'retrieves trackers correctly based on id' do
67
- tracker = EasyPost::Tracker.create({
68
- tracking_code: tracking_code,
69
- carrier: carrier
70
- })
71
-
72
- tracker2 = EasyPost::Tracker.create({
73
- tracking_code: tracking_code,
74
- carrier: carrier
75
- })
76
-
77
- trackers = EasyPost::Tracker.all(after_id: tracker.id, tracking_code: tracking_code)
78
-
79
- expect(trackers["trackers"].count).to eq(1)
80
- expect(trackers["trackers"].first.id).to eq(tracker2.id)
81
- expect(trackers["trackers"].first.id).not_to eq(tracker.id)
82
- expect(trackers["has_more"]).to eq(false)
83
-
84
- trackers = EasyPost::Tracker.all(before_id: tracker.id, tracking_code: tracking_code)
85
-
86
- expect(trackers["trackers"].count).to eq(30)
87
- trackers["trackers"].each do |trk|
88
- expect(trk.id).not_to eq(tracker.id)
89
- expect(trk.id).not_to eq(tracker2.id)
90
- end
91
- expect(trackers["has_more"]).to eq(true)
92
- end
93
- end
94
- end
@@ -1,88 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::User do
4
- before do
5
- EasyPost.api_key = "PRODUCTION API KEY"
6
- end
7
-
8
- # This test requires APIKEY to be nil
9
- # it 'creates a new user' do
10
- # EasyPost.api_key = nil
11
-
12
- # user = EasyPost::User.create({
13
- # name: "Chad Vader",
14
- # email: 'c.vader3@example.com',
15
- # password: "4theempire",
16
- # password_confirmation: "4theempire",
17
- # phone_number: '555-123-4321'
18
- # })
19
-
20
- # expect(user.id).not_to be_nil
21
- # end
22
-
23
-
24
- # Uncomment these tests to test CRUD operations on the User model
25
- # Note: You must provide a Production Api Key in order to run these tests
26
-
27
- # it 'performs all basic CRUD actions on a User' do
28
- # me = EasyPost::User.retrieve_me
29
- # original_children_count = me.children.count
30
-
31
- # name = 'Ruby All-Things-Testing'
32
-
33
- # sub_user = EasyPost::User.create(
34
- # name: name,
35
- # password: 'password1',
36
- # password_confirmation: 'password1',
37
- # phone_number: '7778675309'
38
- # )
39
-
40
- # id = sub_user.id
41
- # email = sub_user.email
42
-
43
- # retrieved_user = EasyPost::User.retrieve(id)
44
- # expect(retrieved_user.id).to eq(id)
45
- # expect(retrieved_user.email).to eq(email)
46
- # expect(retrieved_user.name).to eq(name)
47
-
48
- # new_me = EasyPost::User.retrieve_me
49
- # interm_children_count = new_me.children.count
50
- # expect(interm_children_count).to eq(original_children_count + 1)
51
-
52
- # new_name = 'Ruby All-Things-Tested'
53
- # retrieved_user.name = new_name
54
- # retrieved_user.save
55
-
56
- # updated_user = EasyPost::User.retrieve(id)
57
- # expect(updated_user.id).to eq(id)
58
- # expect(updated_user.email).to eq(email)
59
- # expect(updated_user.name).to eq(new_name)
60
- # end
61
-
62
- # describe '#all_api_keys' do
63
- # it 'returns the correct set of api_keys' do
64
- # api_keys = EasyPost::User.all_api_keys
65
-
66
- # my_keys = api_keys.keys
67
- # expect(my_keys.first.mode).to eq("test")
68
- # expect(my_keys.last.mode).to eq("production")
69
-
70
- # me = EasyPost::User.retrieve_me
71
- # children_count = me.children.count
72
-
73
- # expect(api_keys.children.count).to eq(children_count)
74
- # end
75
- # end
76
-
77
- # describe '#api_keys' do
78
- # it 'returns different keys for the parent and child users' do
79
- # me = EasyPost::User.retrieve_me
80
- # my_keys = me.api_keys
81
-
82
- # child = me.children.first
83
- # child_keys = child.api_keys
84
-
85
- # expect(my_keys).not_to eq(child_keys)
86
- # end
87
- # end
88
- end