easypost 2.1.0 → 2.2.0
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.
- checksums.yaml +5 -13
- data/.gitignore +2 -1
- data/CHANGELOG +83 -0
- data/README.md +19 -12
- data/VERSION +1 -1
- data/easypost.gemspec +2 -2
- data/lib/easypost/address.rb +27 -7
- data/lib/easypost/carrier_account.rb +8 -0
- data/lib/easypost/error.rb +18 -8
- data/lib/easypost/insurance.rb +4 -0
- data/lib/easypost/object.rb +36 -7
- data/lib/easypost/pickup.rb +6 -0
- data/lib/easypost/print_job.rb +6 -0
- data/lib/easypost/printer.rb +28 -0
- data/lib/easypost/resource.rb +11 -1
- data/lib/easypost/shipment.rb +7 -0
- data/lib/easypost/tracker.rb +10 -0
- data/lib/easypost/user.rb +49 -0
- data/lib/easypost/util.rb +21 -7
- data/lib/easypost/version.rb +1 -1
- data/lib/easypost.rb +11 -3
- data/spec/address_spec.rb +32 -20
- data/spec/batch_spec.rb +20 -33
- data/spec/carrier_account_spec.rb +121 -0
- data/spec/container_spec.rb +0 -11
- data/spec/insurance_spec.rb +69 -0
- data/spec/item_spec.rb +104 -101
- data/spec/order_spec.rb +1 -87
- data/spec/pickup_spec.rb +33 -19
- data/spec/shipment_spec.rb +63 -21
- data/spec/spec_helper.rb +6 -92
- data/spec/support/constant.rb +97 -0
- data/spec/tracker_spec.rb +94 -0
- data/spec/user_spec.rb +88 -0
- metadata +26 -31
- data/spec/fedex/domestic_spec.rb +0 -180
- data/spec/fedex/international_spec.rb +0 -64
- data/spec/ups/domestic_spec.rb +0 -79
- data/spec/ups/international_spec.rb +0 -64
- data/spec/usps/domestic_spec.rb +0 -66
- data/spec/usps/electronic_merchandise_returns.rb +0 -94
- data/spec/usps/merchant_returns.rb +0 -0
data/spec/address_spec.rb
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe EasyPost::Address do
|
|
4
|
+
describe ".create_and_verify" do
|
|
5
|
+
context "for a successful response without an address" do
|
|
6
|
+
it "should raise an error" do
|
|
7
|
+
expect(EasyPost).to receive(:request).and_return([{}, ""])
|
|
8
|
+
expect {
|
|
9
|
+
EasyPost::Address.create_and_verify(ADDRESS[:california])
|
|
10
|
+
}.to raise_error EasyPost::Error, /Unable to verify addres/
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
4
15
|
describe '#create' do
|
|
5
16
|
it 'creates an address object' do
|
|
6
17
|
address = EasyPost::Address.create(ADDRESS[:california])
|
|
@@ -11,20 +22,21 @@ describe EasyPost::Address do
|
|
|
11
22
|
end
|
|
12
23
|
|
|
13
24
|
describe '#verify' do
|
|
14
|
-
it 'verifies an address with
|
|
15
|
-
address = EasyPost::Address.create(
|
|
25
|
+
it 'verifies an address with an error' do
|
|
26
|
+
address = EasyPost::Address.create(
|
|
27
|
+
ADDRESS[:california].reject {|k,v| k == :street1 || k == :company}
|
|
28
|
+
)
|
|
16
29
|
|
|
17
|
-
expect(address.
|
|
18
|
-
expect(address.
|
|
30
|
+
expect(address.street1).to be_nil
|
|
31
|
+
expect(address.street2).to eq('Unit 1')
|
|
19
32
|
expect(address.city).to eq('San Francisco')
|
|
20
33
|
expect(address.state).to eq('CA')
|
|
21
34
|
expect(address.zip).to eq('94107')
|
|
22
35
|
expect(address.country).to eq('US')
|
|
23
|
-
expect(address.street2).to be_nil
|
|
24
36
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
expect {
|
|
38
|
+
address.verify()
|
|
39
|
+
}.to raise_error EasyPost::Error, /Unable to verify addres/
|
|
28
40
|
end
|
|
29
41
|
|
|
30
42
|
it 'verifies an address without message' do
|
|
@@ -37,8 +49,8 @@ describe EasyPost::Address do
|
|
|
37
49
|
expect(verified_address[:message]).to be_nil
|
|
38
50
|
end
|
|
39
51
|
|
|
40
|
-
it 'verifies an address using
|
|
41
|
-
address = EasyPost::Address.create(ADDRESS[:california]
|
|
52
|
+
it 'verifies an address using a carrier' do
|
|
53
|
+
address = EasyPost::Address.create(ADDRESS[:california])
|
|
42
54
|
|
|
43
55
|
expect(address.company).to eq('EasyPost')
|
|
44
56
|
expect(address.street1).to eq('164 Townsend Street')
|
|
@@ -46,24 +58,24 @@ describe EasyPost::Address do
|
|
|
46
58
|
expect(address.state).to eq('CA')
|
|
47
59
|
expect(address.zip).to eq('94107')
|
|
48
60
|
expect(address.country).to eq('US')
|
|
49
|
-
expect(address.street2).to be_nil
|
|
50
61
|
|
|
51
|
-
verified_address = address.verify(carrier: :
|
|
62
|
+
verified_address = address.verify(carrier: :usps)
|
|
52
63
|
expect(verified_address).to be_an_instance_of(EasyPost::Address)
|
|
53
|
-
expect(verified_address[:message].length).to be > 0
|
|
54
64
|
end
|
|
55
65
|
|
|
56
66
|
it 'is not able to verify address' do
|
|
57
67
|
address = EasyPost::Address.create(
|
|
58
|
-
:
|
|
59
|
-
:
|
|
60
|
-
:
|
|
61
|
-
:
|
|
62
|
-
:
|
|
63
|
-
:
|
|
68
|
+
company: 'Simpler Postage Inc',
|
|
69
|
+
street1: '388 Junk Teerts',
|
|
70
|
+
street2: 'Apt 20',
|
|
71
|
+
city: 'San Francisco',
|
|
72
|
+
state: 'CA',
|
|
73
|
+
zip: '941abc07'
|
|
64
74
|
)
|
|
65
75
|
|
|
66
|
-
expect {
|
|
76
|
+
expect {
|
|
77
|
+
address.verify()
|
|
78
|
+
}.to raise_error(EasyPost::Error, /Unable to verify addres/)
|
|
67
79
|
end
|
|
68
80
|
end
|
|
69
81
|
end
|
data/spec/batch_spec.rb
CHANGED
|
@@ -1,61 +1,48 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe EasyPost::Batch do
|
|
4
|
-
|
|
5
4
|
describe '#create' do
|
|
6
5
|
it 'creates a batch object' do
|
|
7
6
|
batch = EasyPost::Batch.create({
|
|
8
|
-
:
|
|
9
|
-
:
|
|
10
|
-
:
|
|
11
|
-
:
|
|
7
|
+
shipment: [{
|
|
8
|
+
from_address: ADDRESS[:california],
|
|
9
|
+
to_address: EasyPost::Address.create(ADDRESS[:missouri]),
|
|
10
|
+
parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
|
|
12
11
|
}, {
|
|
13
|
-
:
|
|
14
|
-
:
|
|
15
|
-
:
|
|
12
|
+
from_address: ADDRESS[:california],
|
|
13
|
+
to_address: EasyPost::Address.create(ADDRESS[:canada]),
|
|
14
|
+
parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
|
|
16
15
|
}],
|
|
17
|
-
:
|
|
16
|
+
reference: "batch123456789"
|
|
18
17
|
})
|
|
19
18
|
expect(batch).to be_an_instance_of(EasyPost::Batch)
|
|
20
19
|
expect(batch.num_shipments).to eq(2)
|
|
21
20
|
expect(batch.reference).to eq("batch123456789")
|
|
22
21
|
expect(batch.state).to eq("creating")
|
|
23
|
-
|
|
24
|
-
# sleeps_left = 10
|
|
25
|
-
# while (batch.state == "creating" && sleeps_left > 0) do
|
|
26
|
-
# sleep(3)
|
|
27
|
-
# batch.refresh
|
|
28
|
-
# sleeps_left -= 1
|
|
29
|
-
# end
|
|
30
|
-
|
|
31
|
-
# expect(batch.state).to equal("created")
|
|
32
|
-
# expect(batch.status[:created]).to equal(2)
|
|
33
|
-
|
|
34
22
|
end
|
|
35
23
|
end
|
|
36
24
|
|
|
37
25
|
describe '#create_and_buy' do
|
|
38
26
|
it 'creates a batch object and delayed jobs for purchasing the postage_labels' do
|
|
39
27
|
batch = EasyPost::Batch.create({
|
|
40
|
-
:
|
|
41
|
-
:
|
|
42
|
-
:
|
|
43
|
-
:
|
|
44
|
-
:
|
|
45
|
-
:
|
|
28
|
+
shipment: [{
|
|
29
|
+
from_address: ADDRESS[:california],
|
|
30
|
+
to_address: EasyPost::Address.create(ADDRESS[:missouri]),
|
|
31
|
+
parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
|
|
32
|
+
carrier: "usps",
|
|
33
|
+
service: "priority"
|
|
46
34
|
}, {
|
|
47
|
-
:
|
|
48
|
-
:
|
|
49
|
-
:
|
|
50
|
-
:
|
|
51
|
-
:
|
|
35
|
+
from_address: ADDRESS[:california],
|
|
36
|
+
to_address: EasyPost::Address.create(ADDRESS[:canada]),
|
|
37
|
+
parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
|
|
38
|
+
carrier: "usps",
|
|
39
|
+
service: "prioritymailinternational"
|
|
52
40
|
}],
|
|
53
|
-
:
|
|
41
|
+
reference: "batch123456789"
|
|
54
42
|
})
|
|
55
43
|
expect(batch).to be_an_instance_of(EasyPost::Batch)
|
|
56
44
|
expect(batch.state).to eq("creating")
|
|
57
45
|
expect(batch.num_shipments).to eq(2)
|
|
58
46
|
end
|
|
59
47
|
end
|
|
60
|
-
|
|
61
48
|
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe EasyPost::CarrierAccount do
|
|
4
|
+
before do
|
|
5
|
+
EasyPost.api_key = "PRODUCTION API KEY"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# it 'performs retrieve on a carrier account' do
|
|
9
|
+
# id = 'ca_r8hLl9jS'
|
|
10
|
+
# ca = EasyPost::CarrierAccount.retrieve(id)
|
|
11
|
+
#
|
|
12
|
+
# expect(ca.id).to eq(id)
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# context 'perform CRUD functions' do
|
|
16
|
+
# it 'performs all basic CRUD actions on a CarrierAccount' do
|
|
17
|
+
# original_num_cas = EasyPost::CarrierAccount.all.count
|
|
18
|
+
#
|
|
19
|
+
# description = "A test Ups Account"
|
|
20
|
+
# reference = "RubyClientUpsTestAccount"
|
|
21
|
+
#
|
|
22
|
+
# created_ca = EasyPost::CarrierAccount.create(
|
|
23
|
+
# type: "UpsAccount",
|
|
24
|
+
# description: description,
|
|
25
|
+
# reference: reference,
|
|
26
|
+
# credentials: {
|
|
27
|
+
# account_number: "A1A1A1",
|
|
28
|
+
# user_id: "UPSDOTCOM_USERNAME",
|
|
29
|
+
# password: "UPSDOTCOM_PASSWORD",
|
|
30
|
+
# access_license_number: "UPS_ACCESS_LICENSE_NUMBER"
|
|
31
|
+
# }
|
|
32
|
+
# )
|
|
33
|
+
#
|
|
34
|
+
# id = created_ca["id"]
|
|
35
|
+
#
|
|
36
|
+
# interm_num_cas = EasyPost::CarrierAccount.all.count
|
|
37
|
+
# expect(interm_num_cas).to eq(original_num_cas + 1)
|
|
38
|
+
#
|
|
39
|
+
# retrieved_ca = EasyPost::CarrierAccount.retrieve(id)
|
|
40
|
+
#
|
|
41
|
+
# expect(retrieved_ca["id"]).to eq(created_ca["id"])
|
|
42
|
+
# expect(retrieved_ca["description"]).to eq(description)
|
|
43
|
+
# expect(retrieved_ca["reference"]).to eq(reference)
|
|
44
|
+
#
|
|
45
|
+
# updated_description = "An updated description for a test Ups Account"
|
|
46
|
+
# updated_account_number = "B2B2B2B2"
|
|
47
|
+
# retrieved_ca.description = updated_description
|
|
48
|
+
# retrieved_ca.credentials = {
|
|
49
|
+
# account_number: updated_account_number,
|
|
50
|
+
# user_id: "UPSDOTCOM_USERNAME",
|
|
51
|
+
# password: "UPSDOTCOM_PASSWORD",
|
|
52
|
+
# access_license_number: "UPS_ACCESS_LICENSE_NUMBER"
|
|
53
|
+
# }
|
|
54
|
+
# retrieved_ca.save
|
|
55
|
+
#
|
|
56
|
+
# updated_ca = EasyPost::CarrierAccount.retrieve(id)
|
|
57
|
+
# expect(updated_ca["id"]).to eq(created_ca["id"])
|
|
58
|
+
# expect(updated_ca["description"]).to eq(updated_description)
|
|
59
|
+
# expect(updated_ca["credentials"]["account_number"]).to eq(updated_account_number)
|
|
60
|
+
#
|
|
61
|
+
# reupdated_account_number = "C3C3C3C3C3"
|
|
62
|
+
# updated_user_id = "A_NEW_UPS_USERNAME"
|
|
63
|
+
# updated_ca.credentials[:account_number] = reupdated_account_number
|
|
64
|
+
# updated_ca.credentials[:user_id] = updated_user_id
|
|
65
|
+
# updated_ca.save
|
|
66
|
+
#
|
|
67
|
+
# reupdated_ca = EasyPost::CarrierAccount.retrieve(id)
|
|
68
|
+
# expect(reupdated_ca["id"]).to eq(created_ca["id"])
|
|
69
|
+
# expect(reupdated_ca["credentials"]["account_number"]).to eq(reupdated_account_number)
|
|
70
|
+
# expect(reupdated_ca["credentials"]["user_id"]).to eq(updated_user_id)
|
|
71
|
+
#
|
|
72
|
+
# final_ca = reupdated_ca.save
|
|
73
|
+
# expect(final_ca["id"]).to eq(created_ca["id"])
|
|
74
|
+
# expect(final_ca["credentials"]["account_number"]).to eq(reupdated_account_number)
|
|
75
|
+
# expect(final_ca["credentials"]["user_id"]).to eq(updated_user_id)
|
|
76
|
+
#
|
|
77
|
+
# final_ca.delete
|
|
78
|
+
#
|
|
79
|
+
# final_num_cas = EasyPost::CarrierAccount.all.count
|
|
80
|
+
# expect(final_num_cas).to eq(original_num_cas)
|
|
81
|
+
# end
|
|
82
|
+
# end
|
|
83
|
+
#
|
|
84
|
+
# describe '#types' do
|
|
85
|
+
# let(:carrier_account_types) { [
|
|
86
|
+
# "AsendiaAccount",
|
|
87
|
+
# "AustraliaPostAccount",
|
|
88
|
+
# "CanadaPostAccount",
|
|
89
|
+
# "CanparAccount",
|
|
90
|
+
# "ColisPriveAccount",
|
|
91
|
+
# "DhlExpressAccount",
|
|
92
|
+
# "DhlGlobalMailAccount",
|
|
93
|
+
# "FastwayAccount",
|
|
94
|
+
# "FedexAccount",
|
|
95
|
+
# "FedexSmartpostAccount",
|
|
96
|
+
# "GsoAccount",
|
|
97
|
+
# "LasershipAccount",
|
|
98
|
+
# "LsoAccount",
|
|
99
|
+
# "NorcoAccount",
|
|
100
|
+
# "NzpostAccount",
|
|
101
|
+
# "OntracAccount",
|
|
102
|
+
# "PurolatorAccount",
|
|
103
|
+
# "RoyalMailAccount",
|
|
104
|
+
# "SpeedeeAccount",
|
|
105
|
+
# "TntExpressAccount",
|
|
106
|
+
# "UpsAccount",
|
|
107
|
+
# "UpsMailInnovationsAccount",
|
|
108
|
+
# "UpsSurepostAccount"
|
|
109
|
+
# ] }
|
|
110
|
+
#
|
|
111
|
+
# it 'returns the expected list of types' do
|
|
112
|
+
# types = EasyPost::CarrierAccount.types
|
|
113
|
+
# account_types = types.map(&:type)
|
|
114
|
+
#
|
|
115
|
+
# for account_type in carrier_account_types
|
|
116
|
+
# expect(account_types).to include(account_type)
|
|
117
|
+
# end
|
|
118
|
+
# end
|
|
119
|
+
# end
|
|
120
|
+
end
|
|
121
|
+
|
data/spec/container_spec.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe EasyPost::Container do
|
|
4
|
-
|
|
5
4
|
describe '#create' do
|
|
6
5
|
it 'creates a container object' do
|
|
7
6
|
container = EasyPost::Container.create(
|
|
@@ -73,15 +72,5 @@ describe EasyPost::Container do
|
|
|
73
72
|
expect(container_2.height).to eq(container_1.height)
|
|
74
73
|
expect(container_1.type).to eq("BOX")
|
|
75
74
|
end
|
|
76
|
-
|
|
77
|
-
it 'retrieves global containers' do
|
|
78
|
-
container_1 = EasyPost::Container.retrieve("container_USPSFR03")
|
|
79
|
-
container_2 = EasyPost::Container.retrieve("container_USPSFR02")
|
|
80
|
-
|
|
81
|
-
expect(container_1).to be_an_instance_of(EasyPost::Container)
|
|
82
|
-
expect(container_2).to be_an_instance_of(EasyPost::Container)
|
|
83
|
-
expect(container_1.reference).to eq(container_2.reference)
|
|
84
|
-
end
|
|
85
75
|
end
|
|
86
|
-
|
|
87
76
|
end
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
data/spec/item_spec.rb
CHANGED
|
@@ -1,102 +1,105 @@
|
|
|
1
|
-
|
|
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
|
|
2
105
|
|
|
3
|
-
describe EasyPost::Item do
|
|
4
|
-
|
|
5
|
-
describe '#create' do
|
|
6
|
-
it 'creates an item object', focus: true do
|
|
7
|
-
item = EasyPost::Item.create(
|
|
8
|
-
name: "Spec Item",
|
|
9
|
-
description: "Spec item description",
|
|
10
|
-
harmonized_code: "66.77.90.10",
|
|
11
|
-
country_of_origin: "US",
|
|
12
|
-
length: 6.0,
|
|
13
|
-
width: 11.8,
|
|
14
|
-
height: 12.5,
|
|
15
|
-
weight: 10.55,
|
|
16
|
-
warehouse_location: "SECTION A",
|
|
17
|
-
value: 96.00,
|
|
18
|
-
sku: "V4C3D5R2Z6",
|
|
19
|
-
upc: "UPCYEAHYOUKNOWME"
|
|
20
|
-
)
|
|
21
|
-
expect(item).to be_an_instance_of(EasyPost::Item)
|
|
22
|
-
expect(item.weight).to eq(10.55)
|
|
23
|
-
expect(item.harmonized_code).to eq("66.77.90.10")
|
|
24
|
-
expect(item.sku).to eq("V4C3D5R2Z6")
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'fails to create an item object' do
|
|
28
|
-
expect { EasyPost::Item.create(
|
|
29
|
-
length: 6,
|
|
30
|
-
width: 12,
|
|
31
|
-
height: 13,
|
|
32
|
-
weight: 40
|
|
33
|
-
) }.to raise_exception(EasyPost::Error, /Invalid request, 'name' is required./)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'creates an item object with default values' do
|
|
37
|
-
item = EasyPost::Item.create(
|
|
38
|
-
name: "Default Item",
|
|
39
|
-
length: 6.0,
|
|
40
|
-
width: 8.0,
|
|
41
|
-
height: 10,
|
|
42
|
-
weight: 13,
|
|
43
|
-
value: 19.99
|
|
44
|
-
)
|
|
45
|
-
expect(item.description).to be_nil
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe '#retrieve' do
|
|
50
|
-
it 'retrieves an item by id' do
|
|
51
|
-
item = EasyPost::Item.create(
|
|
52
|
-
name: "Test Item",
|
|
53
|
-
sku: "28374662838",
|
|
54
|
-
length: 6.0,
|
|
55
|
-
width: 8.0,
|
|
56
|
-
height: 10,
|
|
57
|
-
weight: 13,
|
|
58
|
-
value: 13.00
|
|
59
|
-
)
|
|
60
|
-
id = item.id
|
|
61
|
-
item = nil
|
|
62
|
-
item = EasyPost::Item.retrieve(id)
|
|
63
|
-
|
|
64
|
-
expect(item).to be_an_instance_of(EasyPost::Item)
|
|
65
|
-
expect(item.value).to eq("13.00")
|
|
66
|
-
expect(item.sku).to eq("28374662838")
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it 'retrieves an item by reference' do
|
|
70
|
-
item_1 = EasyPost::Item.create(
|
|
71
|
-
name: "Test Item",
|
|
72
|
-
reference: "81993736515",
|
|
73
|
-
length: 6.0,
|
|
74
|
-
width: 8.0,
|
|
75
|
-
height: 10,
|
|
76
|
-
weight: 13,
|
|
77
|
-
value: 13.00
|
|
78
|
-
)
|
|
79
|
-
item_2 = EasyPost::Item.retrieve(item_1.reference)
|
|
80
|
-
|
|
81
|
-
expect(item_2).to be_an_instance_of(EasyPost::Item)
|
|
82
|
-
expect(item_2.reference).to eq(item_1.reference)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'retrieves an item by custom reference' do
|
|
86
|
-
item_1 = EasyPost::Item.create(
|
|
87
|
-
name: "Test Item",
|
|
88
|
-
sku: "928273646",
|
|
89
|
-
length: 6.0,
|
|
90
|
-
width: 8.0,
|
|
91
|
-
height: 10,
|
|
92
|
-
weight: 13,
|
|
93
|
-
value: 17.38
|
|
94
|
-
)
|
|
95
|
-
item_2 = EasyPost::Item.retrieve_reference(sku: "928273646")
|
|
96
|
-
|
|
97
|
-
expect(item_2).to be_an_instance_of(EasyPost::Item)
|
|
98
|
-
expect(item_2.value).to eq("17.38")
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
end
|