@thirstie/thirstieservices 0.1.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.
- package/CHANGELOG.md +38 -0
- package/README.md +41 -0
- package/dist/bundle.cjs +2851 -0
- package/dist/bundle.iife.js +1 -0
- package/dist/bundle.mjs +2848 -0
- package/package.json +37 -0
- package/rollup.config.mjs +28 -0
- package/src/geoservice/index.js +232 -0
- package/src/index.js +7 -0
- package/src/thirstieapi/index.js +331 -0
- package/src/thirstieapi/utils/apirequest.js +34 -0
- package/tests/env.json.tpl +5 -0
- package/tests/fixtures/catalog.json +757 -0
- package/tests/fixtures/catalog_productline_offerings.json +689 -0
- package/tests/fixtures/google_autocomplete_response.json +281 -0
- package/tests/fixtures/google_autocomplete_response_withzip.json +75 -0
- package/tests/fixtures/google_placeid_details.json +104 -0
- package/tests/fixtures/guest_user.json +20 -0
- package/tests/fixtures/session_anonymous.json +8 -0
- package/tests/fixtures/user_addressbook.json +22 -0
- package/tests/fixtures/user_guest.json +20 -0
- package/tests/fixtures/user_loggedin.json +23 -0
- package/tests/fixtures/user_wallet.json +194 -0
- package/tests/functional/apirequest.func.test.js +46 -0
- package/tests/functional/geoservice.func.test.js +53 -0
- package/tests/integration/thirstieapi.int.test.js +89 -0
- package/tests/unit/geoservice.unit.test.js +367 -0
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
|
|
3
|
+
// Fixtures
|
|
4
|
+
// NOTE: Fixtures have "request" property indicating what query was used to generate the suggestions.
|
|
5
|
+
// This is not in google's response.
|
|
6
|
+
import googleAutocompleteResponseNoZip from '../fixtures/google_autocomplete_response.json';
|
|
7
|
+
import googleAutocompleteResponseWithZip from '../fixtures/google_autocomplete_response_withzip.json';
|
|
8
|
+
import googlePlaceIdDetails from '../fixtures/google_placeid_details.json';
|
|
9
|
+
import { parsePlacesAddress, transformPredictionResponse } from '../../src/geoservice';
|
|
10
|
+
|
|
11
|
+
const TEST_FIXTURES = [
|
|
12
|
+
{
|
|
13
|
+
results: [
|
|
14
|
+
{
|
|
15
|
+
address_components: [
|
|
16
|
+
{
|
|
17
|
+
long_name: '10024',
|
|
18
|
+
short_name: '10024',
|
|
19
|
+
types: [
|
|
20
|
+
'postal_code'
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
long_name: 'Manhattan',
|
|
25
|
+
short_name: 'Manhattan',
|
|
26
|
+
types: [
|
|
27
|
+
'political',
|
|
28
|
+
'sublocality',
|
|
29
|
+
'sublocality_level_1'
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
long_name: 'New York',
|
|
34
|
+
short_name: 'New York',
|
|
35
|
+
types: [
|
|
36
|
+
'locality',
|
|
37
|
+
'political'
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
long_name: 'New York County',
|
|
42
|
+
short_name: 'New York County',
|
|
43
|
+
types: [
|
|
44
|
+
'administrative_area_level_2',
|
|
45
|
+
'political'
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
long_name: 'New York',
|
|
50
|
+
short_name: 'NY',
|
|
51
|
+
types: [
|
|
52
|
+
'administrative_area_level_1',
|
|
53
|
+
'political'
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
long_name: 'United States',
|
|
58
|
+
short_name: 'US',
|
|
59
|
+
types: [
|
|
60
|
+
'country',
|
|
61
|
+
'political'
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
formatted_address: 'New York, NY 10024, USA',
|
|
66
|
+
geometry: {
|
|
67
|
+
bounds: {
|
|
68
|
+
northeast: {
|
|
69
|
+
lat: 40.798198,
|
|
70
|
+
lng: -73.962856
|
|
71
|
+
},
|
|
72
|
+
southwest: {
|
|
73
|
+
lat: 40.773376,
|
|
74
|
+
lng: -73.99460669999999
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
location: {
|
|
78
|
+
lat: 40.7859464,
|
|
79
|
+
lng: -73.97418739999999
|
|
80
|
+
},
|
|
81
|
+
location_type: 'APPROXIMATE',
|
|
82
|
+
viewport: {
|
|
83
|
+
northeast: {
|
|
84
|
+
lat: 40.798198,
|
|
85
|
+
lng: -73.962856
|
|
86
|
+
},
|
|
87
|
+
southwest: {
|
|
88
|
+
lat: 40.773376,
|
|
89
|
+
lng: -73.99460669999999
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
place_id: 'ChIJHa5fkWJYwokR_psiHLKKLQg',
|
|
94
|
+
types: [
|
|
95
|
+
'postal_code'
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
status: 'OK'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
results: [
|
|
103
|
+
{
|
|
104
|
+
address_components: [
|
|
105
|
+
{
|
|
106
|
+
long_name: '11221',
|
|
107
|
+
short_name: '11221',
|
|
108
|
+
types: [
|
|
109
|
+
'postal_code'
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
long_name: 'Brooklyn',
|
|
114
|
+
short_name: 'Brooklyn',
|
|
115
|
+
types: [
|
|
116
|
+
'political',
|
|
117
|
+
'sublocality',
|
|
118
|
+
'sublocality_level_1'
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
long_name: 'Kings County',
|
|
123
|
+
short_name: 'Kings County',
|
|
124
|
+
types: [
|
|
125
|
+
'administrative_area_level_2',
|
|
126
|
+
'political'
|
|
127
|
+
]
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
long_name: 'New York',
|
|
131
|
+
short_name: 'NY',
|
|
132
|
+
types: [
|
|
133
|
+
'administrative_area_level_1',
|
|
134
|
+
'political'
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
long_name: 'United States',
|
|
139
|
+
short_name: 'US',
|
|
140
|
+
types: [
|
|
141
|
+
'country',
|
|
142
|
+
'political'
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
formatted_address: 'Brooklyn, NY 11221, USA',
|
|
147
|
+
geometry: {
|
|
148
|
+
bounds: {
|
|
149
|
+
northeast: {
|
|
150
|
+
lat: 40.7013338,
|
|
151
|
+
lng: -73.908799
|
|
152
|
+
},
|
|
153
|
+
southwest: {
|
|
154
|
+
lat: 40.6835669,
|
|
155
|
+
lng: -73.9456419
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
location: {
|
|
159
|
+
lat: 40.6903213,
|
|
160
|
+
lng: -73.9271644
|
|
161
|
+
},
|
|
162
|
+
location_type: 'APPROXIMATE',
|
|
163
|
+
viewport: {
|
|
164
|
+
northeast: {
|
|
165
|
+
lat: 40.7013338,
|
|
166
|
+
lng: -73.908799
|
|
167
|
+
},
|
|
168
|
+
southwest: {
|
|
169
|
+
lat: 40.6835669,
|
|
170
|
+
lng: -73.9456419
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
place_id: 'ChIJe_69LAxcwokR-nZfughhon4',
|
|
175
|
+
types: [
|
|
176
|
+
'postal_code'
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
status: 'OK'
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
results: [
|
|
184
|
+
{
|
|
185
|
+
address_components: [
|
|
186
|
+
{
|
|
187
|
+
long_name: '201',
|
|
188
|
+
short_name: '201',
|
|
189
|
+
types: [
|
|
190
|
+
'street_number'
|
|
191
|
+
]
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
long_name: 'West 89th Street',
|
|
195
|
+
short_name: 'W 89th St',
|
|
196
|
+
types: [
|
|
197
|
+
'route'
|
|
198
|
+
]
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
long_name: 'Manhattan',
|
|
202
|
+
short_name: 'Manhattan',
|
|
203
|
+
types: [
|
|
204
|
+
'political',
|
|
205
|
+
'sublocality',
|
|
206
|
+
'sublocality_level_1'
|
|
207
|
+
]
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
long_name: 'New York',
|
|
211
|
+
short_name: 'New York',
|
|
212
|
+
types: [
|
|
213
|
+
'locality',
|
|
214
|
+
'political'
|
|
215
|
+
]
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
long_name: 'New York County',
|
|
219
|
+
short_name: 'New York County',
|
|
220
|
+
types: [
|
|
221
|
+
'administrative_area_level_2',
|
|
222
|
+
'political'
|
|
223
|
+
]
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
long_name: 'New York',
|
|
227
|
+
short_name: 'NY',
|
|
228
|
+
types: [
|
|
229
|
+
'administrative_area_level_1',
|
|
230
|
+
'political'
|
|
231
|
+
]
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
long_name: 'United States',
|
|
235
|
+
short_name: 'US',
|
|
236
|
+
types: [
|
|
237
|
+
'country',
|
|
238
|
+
'political'
|
|
239
|
+
]
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
long_name: '10024',
|
|
243
|
+
short_name: '10024',
|
|
244
|
+
types: [
|
|
245
|
+
'postal_code'
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
],
|
|
249
|
+
formatted_address: '201 W 89th St, New York, NY 10024, USA',
|
|
250
|
+
geometry: {
|
|
251
|
+
location: {
|
|
252
|
+
lat: 40.789852,
|
|
253
|
+
lng: -73.97391330000001
|
|
254
|
+
},
|
|
255
|
+
location_type: 'ROOFTOP',
|
|
256
|
+
viewport: {
|
|
257
|
+
northeast: {
|
|
258
|
+
lat: 40.79116133029149,
|
|
259
|
+
lng: -73.9725932697085
|
|
260
|
+
},
|
|
261
|
+
southwest: {
|
|
262
|
+
lat: 40.7884633697085,
|
|
263
|
+
lng: -73.9752912302915
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
place_id: 'ChIJBQajC4NYwokRGOChEKhLPQU',
|
|
268
|
+
plus_code: {
|
|
269
|
+
compound_code: 'Q2QG+WC New York, NY',
|
|
270
|
+
global_code: '87G8Q2QG+WC'
|
|
271
|
+
},
|
|
272
|
+
types: [
|
|
273
|
+
'street_address'
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
],
|
|
277
|
+
status: 'OK'
|
|
278
|
+
}
|
|
279
|
+
];
|
|
280
|
+
const TEST_EXPECTED_RESULTS = [
|
|
281
|
+
{
|
|
282
|
+
state: 'NY',
|
|
283
|
+
latitude: 40.7859464,
|
|
284
|
+
longitude: -73.97418739999999,
|
|
285
|
+
city: 'New York',
|
|
286
|
+
street_1: null,
|
|
287
|
+
country: 'US',
|
|
288
|
+
zipcode: '10024'
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
state: 'NY',
|
|
292
|
+
latitude: 40.6903213,
|
|
293
|
+
longitude: -73.9271644,
|
|
294
|
+
city: 'Brooklyn',
|
|
295
|
+
street_1: null,
|
|
296
|
+
country: 'US',
|
|
297
|
+
zipcode: '11221'
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
state: 'NY',
|
|
301
|
+
latitude: 40.789852,
|
|
302
|
+
longitude: -73.97391330000001,
|
|
303
|
+
city: 'New York',
|
|
304
|
+
street_1: '201 West 89th Street',
|
|
305
|
+
country: 'US',
|
|
306
|
+
zipcode: '10024'
|
|
307
|
+
}
|
|
308
|
+
];
|
|
309
|
+
const FIXTURES = R.zip(TEST_FIXTURES, TEST_EXPECTED_RESULTS);
|
|
310
|
+
|
|
311
|
+
test('parsePlacesAddress should return valid addresses', () => {
|
|
312
|
+
FIXTURES.forEach((test) => {
|
|
313
|
+
const testResult = parsePlacesAddress(test[0]);
|
|
314
|
+
const expectedResult = test[1];
|
|
315
|
+
expect(testResult.city).toBe(expectedResult.city);
|
|
316
|
+
expect(testResult.street_1 || '').toBe(expectedResult.street_1 || '');
|
|
317
|
+
expect(testResult.latitude).toBeCloseTo(expectedResult.latitude, 5);
|
|
318
|
+
expect(testResult.longitude).toBeCloseTo(expectedResult.longitude, 5);
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
test('parsePlacesAddress should parse place id response', () => {
|
|
323
|
+
const testResult = parsePlacesAddress(googlePlaceIdDetails);
|
|
324
|
+
expect(testResult.city).toBe('New York');
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test('transformPredictionResponse should parse google suggestions', () => {
|
|
328
|
+
const predictions = googleAutocompleteResponseNoZip.predictions;
|
|
329
|
+
const testResult = transformPredictionResponse(predictions);
|
|
330
|
+
expect(testResult).toHaveLength(predictions.length);
|
|
331
|
+
testResult.forEach((row) => {
|
|
332
|
+
expect(row).toHaveProperty('description');
|
|
333
|
+
expect(row).toHaveProperty('placeId');
|
|
334
|
+
expect(row.description).not.toBeNull();
|
|
335
|
+
expect(row.placeId).not.toBeNull();
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
test('transformPredictionResponse should filter by state', () => {
|
|
340
|
+
const predictions = googleAutocompleteResponseNoZip.predictions;
|
|
341
|
+
const options = {
|
|
342
|
+
requestState: 'NY'
|
|
343
|
+
};
|
|
344
|
+
const testResult = transformPredictionResponse(predictions, options);
|
|
345
|
+
expect(testResult).toHaveLength(2);
|
|
346
|
+
testResult.forEach((row) => {
|
|
347
|
+
expect(row).toHaveProperty('description');
|
|
348
|
+
expect(row).toHaveProperty('placeId');
|
|
349
|
+
expect(row.description).not.toBeNull();
|
|
350
|
+
expect(row.placeId).not.toBeNull();
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test('transformPredictionResponse should filter by zipcode', () => {
|
|
355
|
+
const predictions = googleAutocompleteResponseWithZip.predictions;
|
|
356
|
+
const options = {
|
|
357
|
+
requestZipcode: '10024'
|
|
358
|
+
};
|
|
359
|
+
const testResult = transformPredictionResponse(predictions, options);
|
|
360
|
+
expect(testResult).toHaveLength(1);
|
|
361
|
+
testResult.forEach((row) => {
|
|
362
|
+
expect(row).toHaveProperty('description');
|
|
363
|
+
expect(row).toHaveProperty('placeId');
|
|
364
|
+
expect(row.description).not.toBeNull();
|
|
365
|
+
expect(row.placeId).not.toBeNull();
|
|
366
|
+
});
|
|
367
|
+
});
|