after_ship 0.0.2 → 0.0.4

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,137 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe AfterShip do
4
- it 'fails to make a client' do
5
- expect { AfterShip.new }.to raise_error
6
- end
7
-
8
- context 'With api_key' do
9
- before do
10
- @client = AfterShip.new(api_key: 'key')
11
- end
12
-
13
- it 'api_key' do
14
- expect(@client.api_key).to eq('key')
15
- end
16
-
17
- context 'require_arguments' do
18
- it 'tracking_number: nil raises error' do
19
- expect { @client.require_arguments tracking_number: nil }
20
- .to raise_error(ArgumentError)
21
- end
22
-
23
- it "tracking_number: 1, courier: '' raises error" do
24
- expect { @client.require_arguments tracking_number: 1, courier: '' }
25
- .to raise_error(ArgumentError)
26
- end
27
-
28
- it "tracking_number: 'abc', courier: 'def' does not raise error" do
29
- options = { tracking_number: 'abc', courier: 'def' }
30
- expect { @client.require_arguments(options) }
31
- .to_not raise_error
32
- end
33
- end
34
-
35
- context 'trackings' do
36
- it 'response 200' do
37
- expect { @client.trackings }
38
- .to_not raise_error
39
- end
40
-
41
- it 'response 200 with debug' do
42
- AfterShip.debug = true
43
-
44
- expect { @client.trackings }
45
- .to_not raise_error
46
-
47
- AfterShip.debug = nil
48
- end
49
- end
50
-
51
- context 'tracking' do
52
- it 'response 200' do
53
- expect { @client.tracking('ABC123', 'ups') }
54
- .to_not raise_error
55
- end
56
-
57
- it 'response 201' do
58
- expect { @client.tracking('201', 'ups') }
59
- .to_not raise_error
60
- end
61
-
62
- it 'response 400' do
63
- expect { @client.tracking('400', 'ups') }
64
- .to raise_error(AfterShip::InvalidJSONDataError)
65
- end
66
-
67
- it 'response 401' do
68
- expect { @client.tracking('401', 'ups') }
69
- .to raise_error(AfterShip::InvalidCredentialsError)
70
- end
71
-
72
- it 'response 402' do
73
- expect { @client.tracking('402', 'ups') }
74
- .to raise_error(AfterShip::RequestFailedError)
75
- end
76
-
77
- it 'response 404' do
78
- expect { @client.tracking('404', 'ups') }
79
- .to raise_error(AfterShip::ResourceNotFoundError)
80
- end
81
-
82
- it 'response 409' do
83
- expect { @client.tracking('409', 'ups') }
84
- .to raise_error(AfterShip::InvalidArgumentError)
85
- end
86
-
87
- it 'response 429' do
88
- expect { @client.tracking('429', 'ups') }
89
- .to raise_error(AfterShip::TooManyRequestsError)
90
- end
91
-
92
- it 'response 500' do
93
- expect { @client.tracking('500', 'ups') }
94
- .to raise_error(AfterShip::ServerError)
95
- end
96
-
97
- it 'response 502' do
98
- expect { @client.tracking('502', 'ups') }
99
- .to raise_error(AfterShip::ServerError)
100
- end
101
-
102
- it 'response 503' do
103
- expect { @client.tracking('503', 'ups') }
104
- .to raise_error(AfterShip::ServerError)
105
- end
106
-
107
- it 'response 504' do
108
- expect { @client.tracking('504', 'ups') }
109
- .to raise_error(AfterShip::ServerError)
110
- end
111
-
112
- it 'response 666' do
113
- expect { @client.tracking('666', 'ups') }
114
- .to raise_error(AfterShip::UnknownError)
115
- end
116
- end
117
-
118
- context 'create_tracking' do
119
- it 'response 200' do
120
- expect { @client.create_tracking('ABC123', 'ups') }
121
- .to_not raise_error
122
- end
123
-
124
- it 'with options response 200' do
125
- expect { @client.create_tracking('ABC123', 'ups', order_id: '1234') }
126
- .to_not raise_error
127
- end
128
- end
129
-
130
- context 'update_tracking' do
131
- it 'response 200' do
132
- expect { @client.update_tracking('ABC123', 'ups', order_id: '1234') }
133
- .to_not raise_error
134
- end
135
- end
136
- end
137
- end
@@ -1,139 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe AfterShip::Tracking do
4
- before do
5
- @client = AfterShip.new(api_key: 'key')
6
- end
7
-
8
- context 'Attributes' do
9
- before do
10
- data = {
11
- checkpoints: [
12
- {
13
- slug: 'ups',
14
- city: 'Mumbai',
15
- created_at: '2014-05-06T08:03:52+00:00',
16
- country_name: 'IN',
17
- message: 'BILLING INFORMATION RECEIVED',
18
- country_iso3: 'IND',
19
- tag: 'InfoReceived',
20
- checkpoint_time: '2014-05-01T10:33:38',
21
- coordinates: [],
22
- state: nil,
23
- zip: nil
24
- }
25
- ]
26
- }
27
-
28
- tracking = AfterShip::Tracking.new(data)
29
- @checkpoint = tracking.checkpoints.first
30
- end
31
-
32
- it 'slug' do
33
- expect(@checkpoint.slug).to eq('ups')
34
- end
35
-
36
- it 'city' do
37
- expect(@checkpoint.city).to eq('Mumbai')
38
- end
39
-
40
- it 'courier' do
41
- expect(@checkpoint.courier).to eq('UPS')
42
- end
43
-
44
- it 'created_at is a DateTime' do
45
- expect(@checkpoint.created_at).to be_a(DateTime)
46
- end
47
-
48
- it 'created_at matches pattern' do
49
- expect(@checkpoint.created_at.to_s).to eq('2014-05-06T08:03:52+00:00')
50
- end
51
-
52
- it 'country_name' do
53
- expect(@checkpoint.country_name).to eq('IN')
54
- end
55
-
56
- it 'country_iso3' do
57
- expect(@checkpoint.country_iso3).to eq('IND')
58
- end
59
-
60
- it 'message' do
61
- expect(@checkpoint.message).to eq('BILLING INFORMATION RECEIVED')
62
- end
63
-
64
- it 'tag' do
65
- expect(@checkpoint.tag).to eq('InfoReceived')
66
- end
67
-
68
- it 'checkpoint_time is a DateTime' do
69
- expect(@checkpoint.checkpoint_time).to be_a(DateTime)
70
- end
71
-
72
- it 'checkpoint_time matches pattern' do
73
- expect(@checkpoint.checkpoint_time.to_s).to eq('2014-05-01T10:33:38+00:00')
74
- end
75
-
76
- it 'state' do
77
- expect(@checkpoint.state).to be_nil
78
- end
79
-
80
- it 'zip' do
81
- expect(@checkpoint.zip).to be_nil
82
- end
83
- end
84
-
85
- context 'status' do
86
- it 'Pending' do
87
- data = { tag: 'Pending' }
88
- checkpoint = AfterShip::Checkpoint.new(data)
89
- expect(checkpoint.status).to eq('Pending')
90
- end
91
-
92
- it 'InfoReceived' do
93
- data = { tag: 'InfoReceived' }
94
- checkpoint = AfterShip::Checkpoint.new(data)
95
- expect(checkpoint.status).to eq('Info Received')
96
- end
97
-
98
- it 'InTransit' do
99
- data = { tag: 'InTransit' }
100
- checkpoint = AfterShip::Checkpoint.new(data)
101
- expect(checkpoint.status).to eq('In Transit')
102
- end
103
-
104
- it 'OutForDelivery' do
105
- data = { tag: 'OutForDelivery' }
106
- checkpoint = AfterShip::Checkpoint.new(data)
107
- expect(checkpoint.status).to eq('Out for Delivery')
108
- end
109
-
110
- it 'AttemptFail' do
111
- data = { tag: 'AttemptFail' }
112
- checkpoint = AfterShip::Checkpoint.new(data)
113
- expect(checkpoint.status).to eq('Attempt Failed')
114
- end
115
-
116
- it 'Delivered' do
117
- data = { tag: 'Delivered' }
118
- checkpoint = AfterShip::Checkpoint.new(data)
119
- expect(checkpoint.status).to eq('Delivered')
120
- end
121
-
122
- it 'Exception' do
123
- data = { tag: 'Exception' }
124
- checkpoint = AfterShip::Checkpoint.new(data)
125
- expect(checkpoint.status).to eq('Exception')
126
- end
127
-
128
- it 'Expired' do
129
- data = { tag: 'Expired' }
130
- checkpoint = AfterShip::Checkpoint.new(data)
131
- expect(checkpoint.status).to eq('Expired')
132
- end
133
-
134
- it 'error' do
135
- data = { tag: 'error' }
136
- expect { AfterShip::Checkpoint.new(data) }.to raise_error(KeyError)
137
- end
138
- end
139
- end
@@ -1,89 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe AfterShip::Tracking do
4
- before do
5
- @client = AfterShip.new(api_key: 'key')
6
- end
7
-
8
- context 'Real data' do
9
- it 'builds delivered Tracking (simple)' do
10
- tracking = @client.tracking('delivered-ok', 'ups')
11
- expect(tracking).to be_a(AfterShip::Tracking)
12
- expect(tracking.checkpoints.size).to eq(15)
13
- end
14
-
15
- it 'builds delivered Tracking (quite crazy)' do
16
- tracking = @client.tracking('delivered-wild', 'ups')
17
- expect(tracking).to be_a(AfterShip::Tracking)
18
- expect(tracking.checkpoints.size).to eq(41)
19
- end
20
-
21
- it 'builds in-transit Tracking' do
22
- tracking = @client.tracking('in-transit', 'usps')
23
- expect(tracking).to be_a(AfterShip::Tracking)
24
- expect(tracking.checkpoints.size).to eq(27)
25
- expect(tracking.expected_delivery.to_s).to eq('2014-07-02T00:00:00+00:00')
26
- end
27
- end
28
-
29
- it 'has courier' do
30
- data = { slug: 'ups' }
31
- tracking = AfterShip::Tracking.new(data)
32
- expect(tracking.courier).to eq('UPS')
33
- end
34
-
35
- context 'status' do
36
- it 'Pending' do
37
- data = { tag: 'Pending' }
38
- tracking = AfterShip::Tracking.new(data)
39
- expect(tracking.status).to eq('Pending')
40
- end
41
-
42
- it 'InfoReceived' do
43
- data = { tag: 'InfoReceived' }
44
- tracking = AfterShip::Tracking.new(data)
45
- expect(tracking.status).to eq('Info Received')
46
- end
47
-
48
- it 'InTransit' do
49
- data = { tag: 'InTransit' }
50
- tracking = AfterShip::Tracking.new(data)
51
- expect(tracking.status).to eq('In Transit')
52
- end
53
-
54
- it 'OutForDelivery' do
55
- data = { tag: 'OutForDelivery' }
56
- tracking = AfterShip::Tracking.new(data)
57
- expect(tracking.status).to eq('Out for Delivery')
58
- end
59
-
60
- it 'AttemptFail' do
61
- data = { tag: 'AttemptFail' }
62
- tracking = AfterShip::Tracking.new(data)
63
- expect(tracking.status).to eq('Attempt Failed')
64
- end
65
-
66
- it 'Delivered' do
67
- data = { tag: 'Delivered' }
68
- tracking = AfterShip::Tracking.new(data)
69
- expect(tracking.status).to eq('Delivered')
70
- end
71
-
72
- it 'Exception' do
73
- data = { tag: 'Exception' }
74
- tracking = AfterShip::Tracking.new(data)
75
- expect(tracking.status).to eq('Exception')
76
- end
77
-
78
- it 'Expired' do
79
- data = { tag: 'Expired' }
80
- tracking = AfterShip::Tracking.new(data)
81
- expect(tracking.status).to eq('Expired')
82
- end
83
-
84
- it 'error' do
85
- data = { tag: 'error' }
86
- expect { AfterShip::Tracking.new(data) }.to raise_error(KeyError)
87
- end
88
- end
89
- end