@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,194 @@
|
|
|
1
|
+
{
|
|
2
|
+
"items": [
|
|
3
|
+
{
|
|
4
|
+
"billing_address": {
|
|
5
|
+
"city": null,
|
|
6
|
+
"country": "US",
|
|
7
|
+
"state": null,
|
|
8
|
+
"street_1": null,
|
|
9
|
+
"street_2": null,
|
|
10
|
+
"zipcode": null
|
|
11
|
+
},
|
|
12
|
+
"bin": null,
|
|
13
|
+
"card_type": "Visa",
|
|
14
|
+
"cardholder_name": "Bea Tester",
|
|
15
|
+
"expiration_month": 12,
|
|
16
|
+
"expiration_year": 2044,
|
|
17
|
+
"is_default": "pm_1PT5mpImX2VWsW7KztaXL4hp",
|
|
18
|
+
"last_four": "4242",
|
|
19
|
+
"payment_method_fingerprint": "wcpHGR148XkwAgtM...NJRLHx1G813Ur9Q5FPuC5G5G71zhVPwZbJLy6",
|
|
20
|
+
"payment_type": "stripe"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"billing_address": {
|
|
24
|
+
"city": null,
|
|
25
|
+
"country": "US",
|
|
26
|
+
"state": null,
|
|
27
|
+
"street_1": null,
|
|
28
|
+
"street_2": null,
|
|
29
|
+
"zipcode": null
|
|
30
|
+
},
|
|
31
|
+
"bin": null,
|
|
32
|
+
"card_type": "Visa",
|
|
33
|
+
"cardholder_name": "Bea Tester",
|
|
34
|
+
"expiration_month": 12,
|
|
35
|
+
"expiration_year": 2038,
|
|
36
|
+
"is_default": "pm_1PT5mpImX2VWsW7KztaXL4hp",
|
|
37
|
+
"last_four": "4242",
|
|
38
|
+
"payment_method_fingerprint": "wcpHGR148XkwAgtM...JcUHchVeP5iEvkj",
|
|
39
|
+
"payment_type": "stripe"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"billing_address": {
|
|
43
|
+
"city": null,
|
|
44
|
+
"country": "US",
|
|
45
|
+
"state": null,
|
|
46
|
+
"street_1": null,
|
|
47
|
+
"street_2": null,
|
|
48
|
+
"zipcode": null
|
|
49
|
+
},
|
|
50
|
+
"bin": null,
|
|
51
|
+
"card_type": "Visa",
|
|
52
|
+
"cardholder_name": "Bea Tester",
|
|
53
|
+
"expiration_month": 12,
|
|
54
|
+
"expiration_year": 2042,
|
|
55
|
+
"is_default": "pm_1PT5mpImX2VWsW7KztaXL4hp",
|
|
56
|
+
"last_four": "4242",
|
|
57
|
+
"payment_method_fingerprint": "wcpHGR148XkwAgtMN...ZP2yrVXngB5nsz6eP48",
|
|
58
|
+
"payment_type": "stripe"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"billing_address": {
|
|
62
|
+
"city": null,
|
|
63
|
+
"country": "US",
|
|
64
|
+
"state": null,
|
|
65
|
+
"street_1": null,
|
|
66
|
+
"street_2": null,
|
|
67
|
+
"zipcode": null
|
|
68
|
+
},
|
|
69
|
+
"bin": null,
|
|
70
|
+
"card_type": "Visa",
|
|
71
|
+
"cardholder_name": "Bea Tester",
|
|
72
|
+
"expiration_month": 12,
|
|
73
|
+
"expiration_year": 2024,
|
|
74
|
+
"is_default": "pm_1PT5mpImX2VWsW7KztaXL4hp",
|
|
75
|
+
"last_four": "4242",
|
|
76
|
+
"payment_method_fingerprint": "wcpHGR...ZgMSNHMiTvw9eFv1813Ba",
|
|
77
|
+
"payment_type": "stripe"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"billing_address": {
|
|
81
|
+
"city": null,
|
|
82
|
+
"country": "US",
|
|
83
|
+
"state": null,
|
|
84
|
+
"street_1": null,
|
|
85
|
+
"street_2": null,
|
|
86
|
+
"zipcode": null
|
|
87
|
+
},
|
|
88
|
+
"bin": null,
|
|
89
|
+
"card_type": "MC",
|
|
90
|
+
"cardholder_name": "Bea Tester",
|
|
91
|
+
"expiration_month": 12,
|
|
92
|
+
"expiration_year": 2034,
|
|
93
|
+
"is_default": "pm_1PT5mpImX2VWsW7KztaXL4hp",
|
|
94
|
+
"last_four": "4444",
|
|
95
|
+
"payment_method_fingerprint": "wcpHGR14...pAXoHj4pbnZY8p",
|
|
96
|
+
"payment_type": "stripe"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"billing_address": {
|
|
100
|
+
"city": null,
|
|
101
|
+
"country": "US",
|
|
102
|
+
"state": null,
|
|
103
|
+
"street_1": null,
|
|
104
|
+
"street_2": null,
|
|
105
|
+
"zipcode": null
|
|
106
|
+
},
|
|
107
|
+
"bin": null,
|
|
108
|
+
"card_type": "Visa",
|
|
109
|
+
"cardholder_name": "Bea Tester",
|
|
110
|
+
"expiration_month": 12,
|
|
111
|
+
"expiration_year": 2034,
|
|
112
|
+
"is_default": "pm_1PT5mpImX2VWsW7KztaXL4hp",
|
|
113
|
+
"last_four": "4242",
|
|
114
|
+
"payment_method_fingerprint": "wcpHGR148XkwAg...bVnjrJDwdsV",
|
|
115
|
+
"payment_type": "stripe"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"billing_address": {
|
|
119
|
+
"city": null,
|
|
120
|
+
"country": "US",
|
|
121
|
+
"state": null,
|
|
122
|
+
"street_1": null,
|
|
123
|
+
"street_2": null,
|
|
124
|
+
"zipcode": null
|
|
125
|
+
},
|
|
126
|
+
"bin": null,
|
|
127
|
+
"card_type": "Amex",
|
|
128
|
+
"cardholder_name": "B Testing ",
|
|
129
|
+
"expiration_month": 3,
|
|
130
|
+
"expiration_year": 2024,
|
|
131
|
+
"is_default": "pm_1PT5mpImX2VWsW7KztaXL4hp",
|
|
132
|
+
"last_four": "7006",
|
|
133
|
+
"payment_method_fingerprint": "wcpHGR...8XkWo872ydfRtg",
|
|
134
|
+
"payment_type": "stripe"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"billing_address": {
|
|
138
|
+
"city": null,
|
|
139
|
+
"country": "US",
|
|
140
|
+
"state": null,
|
|
141
|
+
"street_1": null,
|
|
142
|
+
"street_2": null,
|
|
143
|
+
"zipcode": null
|
|
144
|
+
},
|
|
145
|
+
"bin": null,
|
|
146
|
+
"card_type": "Amex",
|
|
147
|
+
"cardholder_name": "Bea Tester",
|
|
148
|
+
"expiration_month": 1,
|
|
149
|
+
"expiration_year": 2031,
|
|
150
|
+
"is_default": "pm_1PT5mpImX2VWsW7KztaXL4hp",
|
|
151
|
+
"last_four": "8431",
|
|
152
|
+
"payment_method_fingerprint": "wcpHGR...dfHkjkKywz3omCf1eDBHxPAdd9gHxRNBoeEdwvpsuSQxaBy8rk",
|
|
153
|
+
"payment_type": "stripe"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"billing_address": {
|
|
157
|
+
"city": null,
|
|
158
|
+
"country": "US",
|
|
159
|
+
"state": null,
|
|
160
|
+
"street_1": null,
|
|
161
|
+
"street_2": null,
|
|
162
|
+
"zipcode": null
|
|
163
|
+
},
|
|
164
|
+
"bin": null,
|
|
165
|
+
"card_type": "Visa",
|
|
166
|
+
"cardholder_name": "Bea Tester",
|
|
167
|
+
"expiration_month": 12,
|
|
168
|
+
"expiration_year": 2024,
|
|
169
|
+
"is_default": "pm_1PT5mpImX2VWsW7KztaXL4hp",
|
|
170
|
+
"last_four": "4242",
|
|
171
|
+
"payment_method_fingerprint": "wcpHGR148XkwAgtMN9xvdZtUR...C7j1rzzFNsAg",
|
|
172
|
+
"payment_type": "stripe"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"billing_address": {
|
|
176
|
+
"city": null,
|
|
177
|
+
"country": "US",
|
|
178
|
+
"state": null,
|
|
179
|
+
"street_1": null,
|
|
180
|
+
"street_2": null,
|
|
181
|
+
"zipcode": 10023
|
|
182
|
+
},
|
|
183
|
+
"bin": null,
|
|
184
|
+
"card_type": "Amex",
|
|
185
|
+
"cardholder_name": "Bea Tester",
|
|
186
|
+
"expiration_month": 12,
|
|
187
|
+
"expiration_year": 2045,
|
|
188
|
+
"is_default": "pm_1PT5mpImX2VWsW7KztaXL4hp",
|
|
189
|
+
"last_four": "8431",
|
|
190
|
+
"payment_method_fingerprint": "wcpHGR148XkwAg...AbdYmdF5zpxE",
|
|
191
|
+
"payment_type": "stripe"
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*
|
|
4
|
+
* Functional tests for the apirequest utility.
|
|
5
|
+
* - we should be able to handle generic http requests
|
|
6
|
+
* - this test suite does not test integration with ThirstieAPI
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import apiRequest from '../../src/thirstieapi/utils/apirequest';
|
|
10
|
+
|
|
11
|
+
describe('apiRequest', () => {
|
|
12
|
+
it('should work with get method', async () => {
|
|
13
|
+
const requestConfig = { headers: { Accept: 'application/json' } };
|
|
14
|
+
const res = await apiRequest('https://httpbin.org/get', requestConfig);
|
|
15
|
+
expect(res.ok).toBe(true);
|
|
16
|
+
expect(res.data).toBeTruthy();
|
|
17
|
+
expect(res.data.url).toBe('https://httpbin.org/get');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should work with post method', async () => {
|
|
21
|
+
const requestConfig = { method: 'POST', headers: { Accept: 'application/json', 'content-type': 'application/json' } };
|
|
22
|
+
const testData = {
|
|
23
|
+
test: 'data'
|
|
24
|
+
};
|
|
25
|
+
requestConfig.body = JSON.stringify(testData);
|
|
26
|
+
|
|
27
|
+
const res = await apiRequest('https://httpbin.org/post', requestConfig);
|
|
28
|
+
|
|
29
|
+
expect(res.ok).toBe(true);
|
|
30
|
+
expect(res.data).toBeTruthy();
|
|
31
|
+
expect(res.data.data).toStrictEqual(requestConfig.body);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should fail 500 error on POST', async () => {
|
|
35
|
+
const requestConfig = { method: 'POST', headers: { Accept: 'application/json', 'content-type': 'application/json' } };
|
|
36
|
+
const testData = {
|
|
37
|
+
test: 'data'
|
|
38
|
+
};
|
|
39
|
+
requestConfig.body = JSON.stringify(testData);
|
|
40
|
+
|
|
41
|
+
const res = await apiRequest('https://httpbin.org/status/500', requestConfig);
|
|
42
|
+
|
|
43
|
+
expect(res.ok).toBe(false);
|
|
44
|
+
expect(res.status).toBe(500);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*
|
|
4
|
+
* Functional tests for the apirequest utility.
|
|
5
|
+
* - we should be able to handle generic http requests
|
|
6
|
+
* - this test suite does not test integration with ThirstieAPI
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { GeoService } from '../../src';
|
|
10
|
+
import appConfig from '../.env.json';
|
|
11
|
+
|
|
12
|
+
const mapsKey = appConfig.MAPSKEY;
|
|
13
|
+
|
|
14
|
+
describe('geoService', () => {
|
|
15
|
+
beforeAll(() => {
|
|
16
|
+
expect(mapsKey).not.toBeNull();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should retrieve address autocomplete suggestions', async () => {
|
|
20
|
+
const addressEntry = '201 West 89th';
|
|
21
|
+
|
|
22
|
+
const geoService = new GeoService(mapsKey);
|
|
23
|
+
const suggestions = await geoService.getLocationSuggestions({ input: addressEntry });
|
|
24
|
+
|
|
25
|
+
expect(suggestions).toHaveProperty('autocompletePredictions');
|
|
26
|
+
suggestions.autocompletePredictions.forEach((row) => {
|
|
27
|
+
expect(row).toHaveProperty('description');
|
|
28
|
+
expect(row).toHaveProperty('placeId');
|
|
29
|
+
expect(row.description).not.toBeNull();
|
|
30
|
+
expect(row.placeId).not.toBeNull();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should retrieve zip code information', async () => {
|
|
35
|
+
const zipCode = '10024';
|
|
36
|
+
const responsePayload = {
|
|
37
|
+
latitude: 40.786,
|
|
38
|
+
longitude: -73.974,
|
|
39
|
+
state: 'NY',
|
|
40
|
+
city: 'New York'
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const geoService = new GeoService(mapsKey);
|
|
44
|
+
const response = await geoService.geocodeZip(zipCode);
|
|
45
|
+
expect(response).toHaveProperty('latitude');
|
|
46
|
+
expect(response).toHaveProperty('longitude');
|
|
47
|
+
expect(response).toHaveProperty('state');
|
|
48
|
+
expect(response).toHaveProperty('city');
|
|
49
|
+
expect(response).toHaveProperty('country');
|
|
50
|
+
expect(response.city).toBe(responsePayload.city);
|
|
51
|
+
expect(response.state).toBe(responsePayload.state);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import ThirstieAPI from '../../src/thirstieapi';
|
|
6
|
+
import appConfig from '../.env.json';
|
|
7
|
+
|
|
8
|
+
const apiKey = appConfig.APIKEY;
|
|
9
|
+
const adminKey = appConfig.ADMINKEY;
|
|
10
|
+
|
|
11
|
+
describe('ThirstieAPI', () => {
|
|
12
|
+
beforeAll(() => {
|
|
13
|
+
expect(apiKey).not.toBeNull();
|
|
14
|
+
expect(adminKey).not.toBeNull();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should initialize with nulls', () => {
|
|
18
|
+
const thirstieAPI = new ThirstieAPI(apiKey, { env: 'dev' });
|
|
19
|
+
expect(thirstieAPI.sessionToken).toBeNull();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should set state', () => {
|
|
23
|
+
const thirstieAPI = new ThirstieAPI(apiKey, { env: 'dev' });
|
|
24
|
+
thirstieAPI.apiState = { sessionToken: 'afaketoken', applicationRef: 'someapplication' };
|
|
25
|
+
|
|
26
|
+
expect(thirstieAPI.sessionToken).toBe('afaketoken');
|
|
27
|
+
expect(thirstieAPI.apiState.applicationRef).toBe('someapplication');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should fetch a new session', async () => {
|
|
31
|
+
const thirstieAPI = new ThirstieAPI(apiKey, { env: 'dev' });
|
|
32
|
+
const sessionData = await thirstieAPI.getNewSession();
|
|
33
|
+
expect(sessionData.token).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should fetch a session', async () => {
|
|
37
|
+
const thirstieAPI = new ThirstieAPI(apiKey, { env: 'dev' });
|
|
38
|
+
const sessionData = await thirstieAPI.fetchSession();
|
|
39
|
+
expect(sessionData.sessionToken).toBeTruthy();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should fetch a new session if provided a bad token', async () => {
|
|
43
|
+
const thirstieAPI = new ThirstieAPI(apiKey, { env: 'dev' });
|
|
44
|
+
thirstieAPI.apiState = { sessionToken: 'notagoodtoken' };
|
|
45
|
+
|
|
46
|
+
const sessionData = await thirstieAPI.fetchSession();
|
|
47
|
+
|
|
48
|
+
expect(sessionData.sessionToken).toBeTruthy();
|
|
49
|
+
expect(sessionData.sessionToken).not.toBe('notagoodtoken');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should allow a user to login via getNewSession and receive raw api response', async () => {
|
|
53
|
+
const thirstieAPI = new ThirstieAPI(adminKey, { env: 'dev' });
|
|
54
|
+
const cred = { email: 'technology@thirstie.com', password: 'thirstie' };
|
|
55
|
+
|
|
56
|
+
const userSessionData = await thirstieAPI.getNewSession(cred);
|
|
57
|
+
|
|
58
|
+
expect(userSessionData.token).toBeTruthy();
|
|
59
|
+
expect(userSessionData.user).not.toBeNull();
|
|
60
|
+
expect(userSessionData.user.email).toBe('technology@thirstie.com');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should allow a user to login via loginUser and api state', async () => {
|
|
64
|
+
const thirstieAPI = new ThirstieAPI(adminKey, { env: 'dev' });
|
|
65
|
+
const cred = { email: 'technology@thirstie.com', password: 'thirstie' };
|
|
66
|
+
|
|
67
|
+
const userSessionData = await thirstieAPI.loginUser(cred);
|
|
68
|
+
|
|
69
|
+
expect(userSessionData.sessionToken).toBeTruthy();
|
|
70
|
+
expect(userSessionData.userRef).not.toBeNull();
|
|
71
|
+
expect(userSessionData.user).not.toBeNull();
|
|
72
|
+
expect(userSessionData.user.email).toBe('technology@thirstie.com');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should allow an anonymous session to login', async () => {
|
|
76
|
+
const thirstieAPI = new ThirstieAPI(adminKey, { env: 'dev' });
|
|
77
|
+
const cred = { email: 'technology@thirstie.com', password: 'thirstie' };
|
|
78
|
+
|
|
79
|
+
const sessionData = await thirstieAPI.fetchSession();
|
|
80
|
+
const userSessionData = await thirstieAPI.loginUser(cred);
|
|
81
|
+
|
|
82
|
+
expect(sessionData.sessionRef).not.toBeNull();
|
|
83
|
+
|
|
84
|
+
expect(userSessionData.sessionToken).toBeTruthy();
|
|
85
|
+
expect(userSessionData.user).not.toBeNull();
|
|
86
|
+
expect(userSessionData.user.email).toBe('technology@thirstie.com');
|
|
87
|
+
expect(userSessionData.sessionRef).toBe(sessionData.sessionRef);
|
|
88
|
+
});
|
|
89
|
+
});
|