after_ship 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,190 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe AfterShip::Request do
4
- let(:response_401) do
5
- '
6
- {
7
- "meta": {
8
- "code": 401,
9
- "message": "Invalid API Key.",
10
- "type": "Unauthorized"
11
- },
12
- "data": {}
13
- }
14
- '
15
- end
16
-
17
- let(:response_200) do
18
- '
19
- {
20
- "meta": {
21
- "code": 200
22
- },
23
- "data": {
24
- "tracking": {
25
- "slug": "ups"
26
- }
27
- }
28
- }
29
- '
30
- end
31
-
32
- let(:typhoeus_response_timeout) do
33
- typhoeus_response = double('Typhoeus response')
34
- allow(typhoeus_response).to receive(:timed_out?).and_return(true)
35
- allow(typhoeus_response).to receive(:effective_url)
36
- .and_return('http://bla.bla/')
37
- typhoeus_response
38
- end
39
-
40
- let(:typhoeus_response_401) do
41
- typhoeus_response = double('Typhoeus response')
42
- allow(typhoeus_response).to receive(:timed_out?).and_return(false)
43
- allow(typhoeus_response).to receive(:body).and_return(response_401)
44
- typhoeus_response
45
- end
46
-
47
- let(:typhoeus_response_200) do
48
- typhoeus_response = double('Typhoeus response')
49
- allow(typhoeus_response).to receive(:timed_out?).and_return(false)
50
- allow(typhoeus_response).to receive(:body).and_return(response_200)
51
- typhoeus_response
52
- end
53
-
54
- it 'initialize with missing :api_key raises an error' do
55
- expect { AfterShip::Request.new(url: 'http://bla.bla/', method: :get) }
56
- .to raise_error(KeyError)
57
- end
58
-
59
- it 'initialize with missing :url raises an error' do
60
- expect { AfterShip::Request.new(api_key: 'key', method: :get) }
61
- .to raise_error(KeyError)
62
- end
63
-
64
- it 'initialize with missing :method raises an error' do
65
- expect { AfterShip::Request.new(api_key: 'key', url: 'http://bla.bla/') }
66
- .to raise_error(KeyError)
67
- end
68
-
69
- it 'get' do
70
- allow_any_instance_of(AfterShip::Request)
71
- .to receive(:typhoeus_response).and_return(typhoeus_response_200)
72
-
73
- args = { api_key: 'key', url: 'http://bla.bla/' }
74
- response = AfterShip::Request.get(args)
75
- expected = {
76
- meta: {
77
- code: 200
78
- },
79
- data: {
80
- tracking: {
81
- slug: 'ups'
82
- }
83
- }
84
- }
85
-
86
- expect(response).to eq(expected)
87
- end
88
-
89
- it 'post' do
90
- allow_any_instance_of(AfterShip::Request)
91
- .to receive(:typhoeus_response).and_return(typhoeus_response_200)
92
-
93
- args = { api_key: 'key', url: 'http://bla.bla/' }
94
- response = AfterShip::Request.post(args)
95
- expected = {
96
- meta: {
97
- code: 200
98
- },
99
- data: {
100
- tracking: {
101
- slug: 'ups'
102
- }
103
- }
104
- }
105
-
106
- expect(response).to eq(expected)
107
- end
108
-
109
- it 'put' do
110
- allow_any_instance_of(AfterShip::Request)
111
- .to receive(:typhoeus_response).and_return(typhoeus_response_200)
112
-
113
- args = { api_key: 'key', url: 'http://bla.bla/' }
114
- response = AfterShip::Request.put(args)
115
- expected = {
116
- meta: {
117
- code: 200
118
- },
119
- data: {
120
- tracking: {
121
- slug: 'ups'
122
- }
123
- }
124
- }
125
-
126
- expect(response).to eq(expected)
127
- end
128
-
129
- it 'response raises an error on timeout' do
130
- allow_any_instance_of(AfterShip::Request)
131
- .to receive(:typhoeus_response).and_return(typhoeus_response_timeout)
132
-
133
- args = { api_key: 'key', url: 'http://bla.bla/', method: :get }
134
- request = AfterShip::Request.new(args)
135
-
136
- expect { request.response }.to raise_error(AfterShip::Error::Timeout)
137
- end
138
-
139
- it 'response loads data and raises an error' do
140
- allow_any_instance_of(AfterShip::Request)
141
- .to receive(:typhoeus_response).and_return(typhoeus_response_401)
142
-
143
- args = { api_key: 'key', url: 'http://bla.bla/', method: :get }
144
- request = AfterShip::Request.new(args)
145
-
146
- expect { request.response }.to raise_error(AfterShip::Error::Unauthorized)
147
- end
148
-
149
- it 'response without a block' do
150
- allow_any_instance_of(AfterShip::Request)
151
- .to receive(:typhoeus_response).and_return(typhoeus_response_200)
152
-
153
- args = { api_key: 'key', url: 'http://bla.bla/', method: :get }
154
- request = AfterShip::Request.new(args)
155
- expected = {
156
- meta: {
157
- code: 200
158
- },
159
- data: {
160
- tracking: {
161
- slug: 'ups'
162
- }
163
- }
164
- }
165
-
166
- expect(request.response).to eq(expected)
167
- end
168
-
169
- it 'response with a block' do
170
- allow_any_instance_of(AfterShip::Request)
171
- .to receive(:typhoeus_response).and_return(typhoeus_response_200)
172
-
173
- args = { api_key: 'key', url: 'http://bla.bla/', method: :get }
174
- request = AfterShip::Request.new(args) do |response|
175
- response[:data][:tracking]
176
- end
177
- expected = {
178
- slug: 'ups'
179
- }
180
-
181
- expect(request.response).to eq(expected)
182
- end
183
-
184
- it 'typhoeus_response' do
185
- allow_any_instance_of(Typhoeus::Request).to receive(:run)
186
- args = { api_key: 'key', url: 'http://bla.bla/', method: :get }
187
- request = AfterShip::Request.new(args)
188
- expect { request.send(:typhoeus_response) }.to_not raise_error
189
- end
190
- end
@@ -1,276 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe AfterShip::Tracking do
4
- context 'Attributes' do
5
- it 'created_at' do
6
- data = { created_at: '2014-10-30T10:05:48' }
7
- tracking = AfterShip::Tracking.new(data)
8
- expect(tracking.created_at).to be_a(DateTime)
9
- expect(tracking.created_at.to_s).to eq('2014-10-30T10:05:48+00:00')
10
- end
11
-
12
- it 'updated_at' do
13
- data = { updated_at: '2014-10-30T10:05:48' }
14
- tracking = AfterShip::Tracking.new(data)
15
- expect(tracking.updated_at).to be_a(DateTime)
16
- expect(tracking.updated_at.to_s).to eq('2014-10-30T10:05:48+00:00')
17
- end
18
-
19
- it 'id' do
20
- data = { id: '5457a109bb8bce546b7abafa' }
21
- tracking = AfterShip::Tracking.new(data)
22
- expect(tracking.id).to eq('5457a109bb8bce546b7abafa')
23
- end
24
-
25
- it 'tracking_number' do
26
- data = { tracking_number: '1ZA2207X0444990982' }
27
- tracking = AfterShip::Tracking.new(data)
28
- expect(tracking.tracking_number).to eq('1ZA2207X0444990982')
29
- end
30
-
31
- it 'tracking_postal_code' do
32
- data = { tracking_postal_code: '???' }
33
- tracking = AfterShip::Tracking.new(data)
34
- expect(tracking.tracking_postal_code).to eq('???')
35
- end
36
-
37
- it 'tracking_ship_date' do
38
- data = { tracking_ship_date: '20141124' }
39
- tracking = AfterShip::Tracking.new(data)
40
- expect(tracking.tracking_ship_date).to be_a(Date)
41
- expect(tracking.tracking_ship_date.to_s)
42
- .to eq('2014-11-24')
43
- end
44
-
45
- it 'tracking_account_number' do
46
- data = { tracking_account_number: '???' }
47
- tracking = AfterShip::Tracking.new(data)
48
- expect(tracking.tracking_account_number).to eq('???')
49
- end
50
-
51
- it 'slug' do
52
- data = { slug: 'ups' }
53
- tracking = AfterShip::Tracking.new(data)
54
- expect(tracking.slug).to eq('ups')
55
- end
56
-
57
- it 'courier' do
58
- data = { slug: 'ups' }
59
- tracking = AfterShip::Tracking.new(data)
60
- expect(tracking.courier).to eq('UPS')
61
- end
62
-
63
- it 'active' do
64
- data = { active: false }
65
- tracking = AfterShip::Tracking.new(data)
66
- expect(tracking.active).to eq(false)
67
- end
68
-
69
- it 'android' do
70
- data = { android: [] }
71
- tracking = AfterShip::Tracking.new(data)
72
- expect(tracking.android).to eq([])
73
- end
74
-
75
- it 'custom_fields' do
76
- data = { custom_fields: [] }
77
- tracking = AfterShip::Tracking.new(data)
78
- expect(tracking.custom_fields).to eq([])
79
- end
80
-
81
- it 'customer_name' do
82
- data = { customer_name: nil }
83
- tracking = AfterShip::Tracking.new(data)
84
- expect(tracking.customer_name).to eq(nil)
85
- end
86
-
87
- it 'delivery_time' do
88
- data = { delivery_time: 4 }
89
- tracking = AfterShip::Tracking.new(data)
90
- expect(tracking.delivery_time).to eq(4)
91
- end
92
-
93
- it 'destination_country_iso3' do
94
- data = { destination_country_iso3: 'USA' }
95
- tracking = AfterShip::Tracking.new(data)
96
- expect(tracking.destination_country_iso3).to eq('USA')
97
- end
98
-
99
- it 'emails' do
100
- data = { emails: [] }
101
- tracking = AfterShip::Tracking.new(data)
102
- expect(tracking.emails).to eq([])
103
- end
104
-
105
- it 'expected_delivery' do
106
- data = { expected_delivery: '2014-10-30T10:05:48+00:00' }
107
- tracking = AfterShip::Tracking.new(data)
108
- expect(tracking.expected_delivery).to be_a(DateTime)
109
- expect(tracking.expected_delivery.to_s)
110
- .to eq('2014-10-30T10:05:48+00:00')
111
- end
112
-
113
- it 'ios' do
114
- data = { ios: [] }
115
- tracking = AfterShip::Tracking.new(data)
116
- expect(tracking.ios).to eq([])
117
- end
118
-
119
- it 'order_id' do
120
- data = { order_id: 'order-id' }
121
- tracking = AfterShip::Tracking.new(data)
122
- expect(tracking.order_id).to eq('order-id')
123
- end
124
-
125
- it 'order_id_path' do
126
- data = { order_id_path: '???' }
127
- tracking = AfterShip::Tracking.new(data)
128
- expect(tracking.order_id_path).to eq('???')
129
- end
130
-
131
- it 'origin_country_iso3' do
132
- data = { origin_country_iso3: 'IND' }
133
- tracking = AfterShip::Tracking.new(data)
134
- expect(tracking.origin_country_iso3).to eq('IND')
135
- end
136
-
137
- it 'unique_token' do
138
- data = { unique_token: 'bk6ysTW1U' }
139
- tracking = AfterShip::Tracking.new(data)
140
- expect(tracking.unique_token).to eq('bk6ysTW1U')
141
- end
142
-
143
- it 'shipment_package_count' do
144
- data = { shipment_package_count: 1 }
145
- tracking = AfterShip::Tracking.new(data)
146
- expect(tracking.shipment_package_count).to eq(1)
147
- end
148
-
149
- it 'shipment_type' do
150
- data = { shipment_type: 'UPS SAVER' }
151
- tracking = AfterShip::Tracking.new(data)
152
- expect(tracking.shipment_type).to eq('UPS SAVER')
153
- end
154
-
155
- it 'shipment_weight' do
156
- data = { shipment_weight: 1 }
157
- tracking = AfterShip::Tracking.new(data)
158
- expect(tracking.shipment_weight).to eq(1)
159
- end
160
-
161
- it 'shipment_weight_unit' do
162
- data = { shipment_weight_unit: 'kg' }
163
- tracking = AfterShip::Tracking.new(data)
164
- expect(tracking.shipment_weight_unit).to eq('kg')
165
- end
166
-
167
- it 'signed_by' do
168
- data = { signed_by: 'A GUPTA (OFFICE)' }
169
- tracking = AfterShip::Tracking.new(data)
170
- expect(tracking.signed_by).to eq('A GUPTA (OFFICE)')
171
- end
172
-
173
- it 'smses' do
174
- data = { smses: [] }
175
- tracking = AfterShip::Tracking.new(data)
176
- expect(tracking.smses).to eq([])
177
- end
178
-
179
- it 'source' do
180
- data = { source: 'api' }
181
- tracking = AfterShip::Tracking.new(data)
182
- expect(tracking.source).to eq('api')
183
- end
184
-
185
- it 'tag' do
186
- data = { tag: 'Delivered' }
187
- tracking = AfterShip::Tracking.new(data)
188
- expect(tracking.tag).to eq('Delivered')
189
- end
190
-
191
- it 'status' do
192
- data = { tag: 'Delivered' }
193
- tracking = AfterShip::Tracking.new(data)
194
- expect(tracking.status).to eq('Delivered')
195
- end
196
-
197
- it 'title' do
198
- data = { title: '1ZA2207X0444990982' }
199
- tracking = AfterShip::Tracking.new(data)
200
- expect(tracking.title).to eq('1ZA2207X0444990982')
201
- end
202
-
203
- it 'tracked_count' do
204
- data = { tracked_count: 3 }
205
- tracking = AfterShip::Tracking.new(data)
206
- expect(tracking.tracked_count).to eq(3)
207
- end
208
-
209
- it 'checkpoints' do
210
- data = {
211
- checkpoints: [
212
- {
213
- slug: 'ups'
214
- }
215
- ]
216
- }
217
- tracking = AfterShip::Tracking.new(data)
218
- expect(tracking.checkpoints.size).to eq(1)
219
- end
220
- end
221
-
222
- context 'status' do
223
- it 'Pending' do
224
- data = { tag: 'Pending' }
225
- tracking = AfterShip::Tracking.new(data)
226
- expect(tracking.status).to eq('Pending')
227
- end
228
-
229
- it 'InfoReceived' do
230
- data = { tag: 'InfoReceived' }
231
- tracking = AfterShip::Tracking.new(data)
232
- expect(tracking.status).to eq('Info Received')
233
- end
234
-
235
- it 'InTransit' do
236
- data = { tag: 'InTransit' }
237
- tracking = AfterShip::Tracking.new(data)
238
- expect(tracking.status).to eq('In Transit')
239
- end
240
-
241
- it 'OutForDelivery' do
242
- data = { tag: 'OutForDelivery' }
243
- tracking = AfterShip::Tracking.new(data)
244
- expect(tracking.status).to eq('Out for Delivery')
245
- end
246
-
247
- it 'AttemptFail' do
248
- data = { tag: 'AttemptFail' }
249
- tracking = AfterShip::Tracking.new(data)
250
- expect(tracking.status).to eq('Attempt Failed')
251
- end
252
-
253
- it 'Delivered' do
254
- data = { tag: 'Delivered' }
255
- tracking = AfterShip::Tracking.new(data)
256
- expect(tracking.status).to eq('Delivered')
257
- end
258
-
259
- it 'Exception' do
260
- data = { tag: 'Exception' }
261
- tracking = AfterShip::Tracking.new(data)
262
- expect(tracking.status).to eq('Exception')
263
- end
264
-
265
- it 'Expired' do
266
- data = { tag: 'Expired' }
267
- tracking = AfterShip::Tracking.new(data)
268
- expect(tracking.status).to eq('Expired')
269
- end
270
-
271
- it 'error' do
272
- data = { tag: 'error' }
273
- expect { AfterShip::Tracking.new(data) }.to raise_error(KeyError)
274
- end
275
- end
276
- end