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,76 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::Container do
4
- describe '#create' do
5
- it 'creates a container object' do
6
- container = EasyPost::Container.create(
7
- name: "Spec Box 1",
8
- length: 6.2,
9
- width: 12.8,
10
- height: 13.5,
11
- max_weight: 40.55,
12
- reference: "SPECBOX",
13
- )
14
- expect(container).to be_an_instance_of(EasyPost::Container)
15
- expect(container.max_weight).to eq(40.55)
16
- end
17
-
18
- it 'fails to create a container object' do
19
- expect { EasyPost::Container.create(
20
- name: "Missing dimension",
21
- length: 6,
22
- width: 12,
23
- max_weight: 40
24
- ) }.to raise_exception(EasyPost::Error, /Invalid request, if one dimension is provided all three are required./)
25
- end
26
-
27
- it 'creates a container object with default values' do
28
- container = EasyPost::Container.create(name: "Defaults Box")
29
- expect(container).to be_an_instance_of(EasyPost::Container)
30
- expect(container.id).to be
31
- expect(container.name).to eq("Defaults Box")
32
- expect(container.length).to eq(0.0)
33
- expect(container.width).to eq(0.0)
34
- expect(container.height).to eq(0.0)
35
- expect(container.max_weight).to eq(0.0)
36
- expect(container.type).to eq("BOX")
37
- end
38
- end
39
-
40
- describe '#retrieve' do
41
- it 'retrieves a user created container by public_id' do
42
- container_1 = EasyPost::Container.create(
43
- name: "My Box",
44
- length: 6.2,
45
- width: 12.8,
46
- height: 13.5,
47
- max_weight: 40.55,
48
- reference: "SPECBOX",
49
- type: "BAG",
50
- )
51
- container_2 = EasyPost::Container.retrieve(container_1.id)
52
-
53
- expect(container_1).to be_an_instance_of(EasyPost::Container)
54
- expect(container_2).to be_an_instance_of(EasyPost::Container)
55
- expect(container_2.id).to eq(container_1.id)
56
- expect(container_1.type).to eq("BAG")
57
- end
58
-
59
- it 'retrieves a user created container by reference' do
60
- container_1 = EasyPost::Container.create(
61
- name: "Spec Box 2",
62
- length: 6.2,
63
- width: 12.8,
64
- height: 133.94,
65
- max_weight: 40.55,
66
- reference: "SPECBOX4",
67
- )
68
- container_2 = EasyPost::Container.retrieve("SPECBOX4")
69
-
70
- expect(container_1).to be_an_instance_of(EasyPost::Container)
71
- expect(container_2).to be_an_instance_of(EasyPost::Container)
72
- expect(container_2.height).to eq(container_1.height)
73
- expect(container_1.type).to eq("BOX")
74
- end
75
- end
76
- end
@@ -1,69 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::Insurance do
4
- let(:tracking_code) { 'EZ2000000002' }
5
- let(:carrier) { 'usps' }
6
- let(:amount) { 101.00 }
7
-
8
- describe '#create' do
9
- it 'creates an insurance object' do
10
- insurance = EasyPost::Insurance.create(
11
- to_address: ADDRESS[:california],
12
- from_address: ADDRESS[:missouri],
13
- amount: amount,
14
- tracking_code: tracking_code,
15
- carrier: carrier
16
- )
17
-
18
- expect(insurance).to be_a(EasyPost::Insurance)
19
- expect(insurance.id).not_to be_nil
20
- expect(insurance.amount).to eq("101.00000")
21
- expect(insurance.tracking_code).to eq(tracking_code)
22
- expect(insurance.tracker).to be_a(EasyPost::Tracker)
23
- end
24
- end
25
-
26
- describe '#retrieve' do
27
- it 'creates an insurance object' do
28
- id = EasyPost::Insurance.create(
29
- to_address: ADDRESS[:california],
30
- from_address: ADDRESS[:missouri],
31
- amount: amount,
32
- tracking_code: tracking_code,
33
- carrier: carrier
34
- ).id
35
-
36
- insurance = EasyPost::Insurance.retrieve(id)
37
-
38
- expect(insurance).to be_a(EasyPost::Insurance)
39
- expect(insurance.id).to eq(id)
40
- expect(insurance.amount).to eq("101.00000")
41
- expect(insurance.tracking_code).to eq(tracking_code)
42
- expect(insurance.tracker).to be_a(EasyPost::Tracker)
43
- end
44
- end
45
-
46
-
47
- describe '#index' do
48
- it 'retrieves a full page of insurances' do
49
- insurances = EasyPost::Insurance.all(page_size: 5)
50
-
51
- expect(insurances["insurances"].count).to eq(5)
52
- expect(insurances["has_more"]).to eq(true)
53
- end
54
-
55
- it 'retrieves all insurances with given tracking code, up to a page' do
56
- insurances = EasyPost::Insurance.all(tracking_code: tracking_code, page_size: 5)
57
-
58
- expect(insurances["insurances"].count).to eq(5)
59
- expect(insurances["has_more"]).to eq(true)
60
- end
61
-
62
- it 'retrieves all insurances with given tracking code and carrier, up to a page' do
63
- insurances = EasyPost::Insurance.all(tracking_code: tracking_code, carrier: carrier, page_size: 5)
64
-
65
- expect(insurances["insurances"].count).to eq(5)
66
- expect(insurances["has_more"]).to eq(true)
67
- end
68
- end
69
- end
@@ -1,105 +0,0 @@
1
- # TODO: fix this
2
- #
3
- #require 'spec_helper'
4
- #
5
- #describe EasyPost::Item do
6
- #
7
- # describe '#create' do
8
- # it 'creates an item object', focus: true do
9
- # item = EasyPost::Item.create(
10
- # name: "Spec Item",
11
- # description: "Spec item description",
12
- # harmonized_code: "66.77.90.10",
13
- # country_of_origin: "US",
14
- # length: 6.0,
15
- # width: 11.8,
16
- # height: 12.5,
17
- # weight: 10.55,
18
- # warehouse_location: "SECTION A",
19
- # value: 96.00,
20
- # sku: "V4C3D5R2Z6",
21
- # upc: "UPCYEAHYOUKNOWME"
22
- # )
23
- # expect(item).to be_an_instance_of(EasyPost::Item)
24
- # expect(item.weight).to eq(10.55)
25
- # expect(item.harmonized_code).to eq("66.77.90.10")
26
- # expect(item.sku).to eq("V4C3D5R2Z6")
27
- # end
28
- #
29
- # it 'fails to create an item object' do
30
- # expect { EasyPost::Item.create(
31
- # length: 6,
32
- # width: 12,
33
- # height: 13,
34
- # weight: 40
35
- # ) }.to raise_exception(EasyPost::Error, /Invalid request, 'name' is required./)
36
- # end
37
- #
38
- # it 'creates an item object with default values' do
39
- # item = EasyPost::Item.create(
40
- # name: "Default Item",
41
- # length: 6.0,
42
- # width: 8.0,
43
- # height: 10,
44
- # weight: 13,
45
- # value: 19.99
46
- # )
47
- # expect(item.description).to be_nil
48
- # end
49
- # end
50
- #
51
- # describe '#retrieve' do
52
- # it 'retrieves an item by id' do
53
- # item = EasyPost::Item.create(
54
- # name: "Test Item",
55
- # sku: "28374662838",
56
- # length: 6.0,
57
- # width: 8.0,
58
- # height: 10,
59
- # weight: 13,
60
- # value: 13.00
61
- # )
62
- # id = item.id
63
- # item = nil
64
- # item = EasyPost::Item.retrieve(id)
65
- #
66
- # expect(item).to be_an_instance_of(EasyPost::Item)
67
- # expect(item.value).to eq("13.00")
68
- # expect(item.sku).to eq("28374662838")
69
- # end
70
- #
71
- # it 'retrieves an item by reference' do
72
- # item_1 = EasyPost::Item.create(
73
- # name: "Test Item",
74
- # reference: "81993736515",
75
- # length: 6.0,
76
- # width: 8.0,
77
- # height: 10,
78
- # weight: 13,
79
- # value: 13.00
80
- # )
81
- # item_2 = EasyPost::Item.retrieve(item_1.reference)
82
- #
83
- # expect(item_2).to be_an_instance_of(EasyPost::Item)
84
- # expect(item_2.reference).to eq(item_1.reference)
85
- # end
86
- #
87
- # it 'retrieves an item by custom reference' do
88
- # item_1 = EasyPost::Item.create(
89
- # name: "Test Item",
90
- # sku: "928273646",
91
- # length: 6.0,
92
- # width: 8.0,
93
- # height: 10,
94
- # weight: 13,
95
- # value: 17.38
96
- # )
97
- # item_2 = EasyPost::Item.retrieve_reference(sku: "928273646")
98
- #
99
- # expect(item_2).to be_an_instance_of(EasyPost::Item)
100
- # expect(item_2.value).to eq("17.38")
101
- # end
102
- # end
103
- #
104
- #end
105
-
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::Order do
4
- describe '#get_rates' do
5
- it 'refreshes rates' do
6
- order = EasyPost::Order.create(
7
- to_address: ADDRESS[:california],
8
- from_address: ADDRESS[:missouri],
9
- shipments: [{
10
- parcel: {length: 8, width: 6, height: 4, weight: 12}
11
- }]
12
- )
13
-
14
- expect(order).to be_an_instance_of(EasyPost::Order)
15
- expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
16
-
17
- rate_id = order.shipments.first.rates.first.id
18
- expect(rate_id).not_to be_nil
19
-
20
- order.get_rates
21
-
22
- new_rate_id = order.shipments.first.rates.first.id
23
- expect(new_rate_id).not_to be_nil
24
- expect(new_rate_id).not_to eq(rate_id)
25
- end
26
- end
27
-
28
- describe '#create' do
29
- it 'creates an order out of a single shipment' do
30
- order = EasyPost::Order.create(
31
- to_address: ADDRESS[:california],
32
- from_address: ADDRESS[:missouri],
33
- shipments: [{
34
- parcel: {length: 8, width: 6, height: 4, weight: 12}
35
- }]
36
- )
37
-
38
- expect(order).to be_an_instance_of(EasyPost::Order)
39
- expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
40
- end
41
-
42
- it 'creates an order out of two shipments' do
43
- order = EasyPost::Order.create(
44
- to_address: ADDRESS[:california],
45
- from_address: ADDRESS[:missouri],
46
- carrier_accounts: [{id: "ca_12345678"}],
47
- shipments: [{
48
- parcel: {length: 8, width: 6, height: 4, weight: 12}
49
- },{
50
- parcel: {length: 8, width: 6, height: 4, weight: 12}
51
- }]
52
- )
53
-
54
- expect(order).to be_an_instance_of(EasyPost::Order)
55
- expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
56
- end
57
- end
58
- end
@@ -1,83 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::Pickup do
4
- before { EasyPost.api_key = "cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi" }
5
-
6
- let(:shipment) do
7
- shipment = EasyPost::Shipment.create(
8
- to_address: ADDRESS[:california],
9
- from_address: ADDRESS[:missouri],
10
- parcel: PARCEL[:dimensions]
11
- )
12
- end
13
-
14
- describe '#create' do
15
- it 'creates a pickup and returns rates' do
16
- shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
17
- pickup = EasyPost::Pickup.create(
18
- address: ADDRESS[:missouri],
19
- reference: "12345678",
20
- min_datetime: DateTime.now(),
21
- max_datetime: DateTime.now() + 14400,
22
- is_account_address: false,
23
- instructions: "",
24
- shipment: shipment
25
- )
26
-
27
- expect(pickup).to be_an_instance_of(EasyPost::Pickup)
28
- expect(pickup.pickup_rates.first).to be_an_instance_of(EasyPost::PickupRate)
29
- end
30
-
31
- it 'fails to create a pickup' do
32
- shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
33
- expect { pickup = EasyPost::Pickup.create(
34
- address: ADDRESS[:california],
35
- reference: "12345678",
36
- max_datetime: DateTime.now() + 14400,
37
- is_account_address: false,
38
- instructions: "",
39
- shipment: shipment
40
- ) }.to raise_exception(EasyPost::Error, /Invalid request, 'min_datetime' is required./)
41
- end
42
- end
43
-
44
- describe '#buy' do
45
- it 'buys a pickup rate' do
46
- shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
47
- pickup = EasyPost::Pickup.create(
48
- address: ADDRESS[:california],
49
- reference: "buy12345678",
50
- min_datetime: DateTime.now(),
51
- max_datetime: DateTime.now() + 14400,
52
- is_account_address: false,
53
- instructions: "",
54
- shipment: shipment
55
- )
56
- pickup.buy(pickup.pickup_rates.first)
57
-
58
- expect(pickup.confirmation).not_to be_empty
59
- end
60
- end
61
-
62
- describe '#cancel' do
63
- it 'cancels a pickup' do
64
- shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
65
- pickup = EasyPost::Pickup.create(
66
- address: ADDRESS[:california],
67
- reference: "buy12345678",
68
- min_datetime: DateTime.now(),
69
- max_datetime: DateTime.now() + 14400,
70
- is_account_address: false,
71
- instructions: "",
72
- shipment: shipment
73
- )
74
- pickup.buy(pickup.pickup_rates.first)
75
-
76
- expect(pickup.status).to eq("scheduled")
77
-
78
- pickup.cancel
79
-
80
- expect(pickup.status).to eq("canceled")
81
- end
82
- end
83
- end
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EasyPost::Report do
4
- TYPE = 'shipment'
5
- describe '#create' do
6
- it 'creates a report object' do
7
- report = EasyPost::Report.create(
8
- start_date: Date.today - 30,
9
- end_date: Date.today,
10
- type: TYPE
11
- )
12
- expect(report.object).to eq 'ShipmentReport'
13
- expect(['available', 'new']).to include(report.status)
14
- end
15
- end
16
-
17
- describe '#retrieve' do
18
- it 'retrieves a user created report by public_id as a hash' do
19
- report_1 = EasyPost::Report.create(
20
- start_date: Date.today - 30,
21
- end_date: Date.today,
22
- type: TYPE
23
- )
24
- report_2 = EasyPost::Report.retrieve(id: report_1.id)
25
-
26
- expect(report_2.id).to eq(report_1.id)
27
- end
28
-
29
- it 'retrieves a user created report by public_id as a string' do
30
- report_1 = EasyPost::Report.create(
31
- start_date: Date.today - 30,
32
- end_date: Date.today,
33
- type: TYPE
34
- )
35
- report_2 = EasyPost::Report.retrieve(report_1.id)
36
-
37
- expect(report_2.id).to eq(report_1.id)
38
- end
39
- end
40
-
41
- describe '#all' do
42
- it 'retrieves all user created reports' do
43
- report_1 = EasyPost::Report.create(
44
- start_date: Date.today - 25,
45
- end_date: Date.today,
46
- type: TYPE
47
- )
48
-
49
- report_2 = EasyPost::Report.create(
50
- start_date: Date.today - 29,
51
- end_date: Date.today,
52
- type: TYPE
53
- )
54
- reports = EasyPost::Report.all(type: TYPE)
55
-
56
- expect(reports.count).to eq 2
57
- end
58
- end
59
- end