piper-utils 1.0.4 → 1.0.5-7.1
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/README.md +1 -119
- package/bin/main.js +137 -107
- package/bin/main.js.map +1 -1
- package/package.json +3 -4
- package/src/database/dbUtils/queryStringUtils/accessRightsUtils.js +82 -36
- package/src/database/dbUtils/queryStringUtils/accessRightsUtils.test.js +368 -216
- package/src/database/dbUtils/queryStringUtils/createFilters.js +36 -1
- package/src/database/dbUtils/queryStringUtils/createFilters.test.js +21 -3
- package/src/database/dbUtils/queryStringUtils/findAll.js +2 -1
- package/src/database/dbUtils/queryStringUtils/mocks/mocks.js +43 -0
- package/src/eventManager/handleEvents.js +31 -1
- package/src/eventManager/handleFile.js +20 -3
- package/src/eventManager/handleFile.test.js +32 -3
- package/src/eventManager/watchBucket.js +22 -3
- package/src/eventManager/watchBucket.test.js +119 -0
- package/src/index.js +10 -0
- package/src/requestResonse/requestResponse.js +43 -6
- package/src/requestResonse/requestResponse.test.js +10 -1
- package/webpack.config.js +1 -1
|
@@ -1,216 +1,368 @@
|
|
|
1
|
-
import { accessRightsUtils, checkModule, checkWriteAccess, getBusinessesInfo, userDefaultBid } from '../../../index.js';
|
|
2
|
-
import { getModuleInfo } from './accessRightsUtils.js';
|
|
3
|
-
|
|
4
|
-
export const mock = {
|
|
5
|
-
pathParameters: {
|
|
6
|
-
id: 1
|
|
7
|
-
},
|
|
8
|
-
queryStringParameters: {
|
|
9
|
-
businessIds: 'ABC,1'
|
|
10
|
-
},
|
|
11
|
-
requestContext: {
|
|
12
|
-
authorizer: {
|
|
13
|
-
claims: {
|
|
14
|
-
'custom:AR': JSON.stringify({ businessIds: { 'ABC': 'A', 'XYZ': 'A' } }),
|
|
15
|
-
'custom:DBI': JSON.stringify({ defaultBid: 'spam' }),
|
|
16
|
-
'custom:MOD': JSON.stringify({ module: { part: true } })
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
body: { number: 'B201', businessId: 'ABC', taxRate: { rate: .325, name: 'name', agency: 'agency', ref: '' }, defaultLocationId: 1, uoms: [{ name: 'EA', conversion: 1 }] }
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
body: { number: 'B201', taxRate: { rate: .325, name: 'name', agency: 'agency', ref: '' }, defaultLocationId: 1, uoms: [{ name: 'EA', conversion: 1 }] }
|
|
68
|
-
};
|
|
69
|
-
export const
|
|
70
|
-
pathParameters: {
|
|
71
|
-
id: 1
|
|
72
|
-
},
|
|
73
|
-
queryStringParameters: {
|
|
74
|
-
businessIds: '
|
|
75
|
-
},
|
|
76
|
-
requestContext: {
|
|
77
|
-
authorizer: {
|
|
78
|
-
claims: {
|
|
79
|
-
'custom:AR': JSON.stringify({ businessIds: { 'ABC': '
|
|
80
|
-
'custom:DBI': JSON.stringify({ defaultBid: 'spam' }),
|
|
81
|
-
'custom:MOD': JSON.stringify({ module: { part: true } })
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
body: {
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
1
|
+
import { accessRightsUtils, checkModule, checkWriteAccess, getBusinessesInfo, userDefaultBid } from '../../../index.js';
|
|
2
|
+
import { getModuleInfo, getRequestedBusinessIds } from './accessRightsUtils.js';
|
|
3
|
+
|
|
4
|
+
export const mock = {
|
|
5
|
+
pathParameters: {
|
|
6
|
+
id: 1
|
|
7
|
+
},
|
|
8
|
+
queryStringParameters: {
|
|
9
|
+
businessIds: 'ABC,1'
|
|
10
|
+
},
|
|
11
|
+
requestContext: {
|
|
12
|
+
authorizer: {
|
|
13
|
+
claims: {
|
|
14
|
+
'custom:AR': JSON.stringify({ businessIds: { 'ABC': 'A', 'XYZ': 'A' } }),
|
|
15
|
+
'custom:DBI': JSON.stringify({ defaultBid: 'spam' }),
|
|
16
|
+
'custom:MOD': JSON.stringify({ module: { part: true } })
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
body: { number: 'B201', businessId: 'ABC', taxRate: { rate: .325, name: 'name', agency: 'agency', ref: '' }, defaultLocationId: 1, uoms: [{ name: 'EA', conversion: 1 }] }
|
|
21
|
+
};
|
|
22
|
+
export const mock2NoAuth = {
|
|
23
|
+
pathParameters: {
|
|
24
|
+
id: 1
|
|
25
|
+
},
|
|
26
|
+
queryStringParameters: {
|
|
27
|
+
businessIds: 'ABC,1'
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify({ number: 'B201', businessId: 'ABC', taxRate: { rate: .325, name: 'name', agency: 'agency', ref: '' }, defaultLocationId: 1, uoms: [{ name: 'EA', conversion: 1 }] })
|
|
30
|
+
};
|
|
31
|
+
export const mockSystem = {
|
|
32
|
+
pathParameters: {
|
|
33
|
+
id: 1
|
|
34
|
+
},
|
|
35
|
+
queryStringParameters: {
|
|
36
|
+
businessIds: 'ABC,1'
|
|
37
|
+
},
|
|
38
|
+
requestContext: {
|
|
39
|
+
authorizer: {
|
|
40
|
+
claims: {
|
|
41
|
+
'custom:AR': JSON.stringify({ businessIds: { 'ABC': 'A', 'XYZ': 'A' } }),
|
|
42
|
+
'custom:DBI': JSON.stringify({ defaultBid: 'spam' }),
|
|
43
|
+
'custom:MOD': JSON.stringify({ module: { part: false } }),
|
|
44
|
+
'custom:SYSTEM': JSON.stringify('true')
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
body: { number: 'B201', businessId: 'ABC', taxRate: { rate: .325, name: 'name', agency: 'agency', ref: '' }, defaultLocationId: 1, uoms: [{ name: 'EA', conversion: 1 }] }
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const mockNOAccess = {
|
|
52
|
+
pathParameters: {
|
|
53
|
+
id: 1
|
|
54
|
+
},
|
|
55
|
+
queryStringParameters: {
|
|
56
|
+
businessIds: 'XYZ'
|
|
57
|
+
},
|
|
58
|
+
requestContext: {
|
|
59
|
+
authorizer: {
|
|
60
|
+
claims: {
|
|
61
|
+
'custom:AR': JSON.stringify({ businessIds: { 'ABC': 'A' } }),
|
|
62
|
+
'custom:DBI': JSON.stringify({ defaultBid: 'spam' }),
|
|
63
|
+
'custom:MOD': JSON.stringify({ module: { part: true } })
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
body: { number: 'B201', taxRate: { rate: .325, name: 'name', agency: 'agency', ref: '' }, defaultLocationId: 1, uoms: [{ name: 'EA', conversion: 1 }] }
|
|
68
|
+
};
|
|
69
|
+
export const mockNoneRequested = {
|
|
70
|
+
pathParameters: {
|
|
71
|
+
id: 1
|
|
72
|
+
},
|
|
73
|
+
queryStringParameters: {
|
|
74
|
+
businessIds: ''
|
|
75
|
+
},
|
|
76
|
+
requestContext: {
|
|
77
|
+
authorizer: {
|
|
78
|
+
claims: {
|
|
79
|
+
'custom:AR': JSON.stringify({ businessIds: { 'ABC': 'A' } }),
|
|
80
|
+
'custom:DBI': JSON.stringify({ defaultBid: 'spam' }),
|
|
81
|
+
'custom:MOD': JSON.stringify({ module: { part: true } })
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
body: { number: 'B201', taxRate: { rate: .325, name: 'name', agency: 'agency', ref: '' }, defaultLocationId: 1, uoms: [{ name: 'EA', conversion: 1 }] }
|
|
86
|
+
};
|
|
87
|
+
export const mockNoneRequestedSystem = {
|
|
88
|
+
pathParameters: {
|
|
89
|
+
id: 1
|
|
90
|
+
},
|
|
91
|
+
queryStringParameters: {
|
|
92
|
+
businessIds: 'DUCK'
|
|
93
|
+
},
|
|
94
|
+
requestContext: {
|
|
95
|
+
authorizer: {
|
|
96
|
+
claims: {
|
|
97
|
+
'custom:AR': JSON.stringify({ businessIds: { 'ABC': 'A' } }),
|
|
98
|
+
'custom:DBI': JSON.stringify({ defaultBid: 'spam' }),
|
|
99
|
+
'custom:MOD': JSON.stringify({ module: { part: true } }),
|
|
100
|
+
'custom:SYSTEM': JSON.stringify('true')
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
body: { number: 'B201', taxRate: { rate: .325, name: 'name', agency: 'agency', ref: '' }, defaultLocationId: 1, uoms: [{ name: 'EA', conversion: 1 }] }
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const mock2 = {
|
|
108
|
+
pathParameters: {
|
|
109
|
+
id: 1
|
|
110
|
+
},
|
|
111
|
+
queryStringParameters: {
|
|
112
|
+
businessIds: '2'
|
|
113
|
+
},
|
|
114
|
+
body: { number: 'B201', taxRate: { rate: .325, name: 'name', agency: 'agency', ref: '' }, defaultLocationId: 1, uoms: [{ name: 'EA', conversion: 1 }] }
|
|
115
|
+
};
|
|
116
|
+
export const mock3 = {
|
|
117
|
+
pathParameters: {
|
|
118
|
+
id: 1
|
|
119
|
+
},
|
|
120
|
+
queryStringParameters: {
|
|
121
|
+
businessIds: 'ABC'
|
|
122
|
+
},
|
|
123
|
+
requestContext: {
|
|
124
|
+
authorizer: {
|
|
125
|
+
claims: {
|
|
126
|
+
'custom:AR': JSON.stringify({ businessIds: { 'ABC': 'R', 'XYZ': 'R' } }),
|
|
127
|
+
'custom:DBI': JSON.stringify({ defaultBid: 'spam' }),
|
|
128
|
+
'custom:MOD': JSON.stringify({ module: { part: true } })
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
body: { businessId: 'ABC' }
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const mock4 = {
|
|
136
|
+
pathParameters: {
|
|
137
|
+
id: 1
|
|
138
|
+
},
|
|
139
|
+
queryStringParameters: {
|
|
140
|
+
businessIds: 'ALPHA'
|
|
141
|
+
},
|
|
142
|
+
requestContext: {
|
|
143
|
+
authorizer: {
|
|
144
|
+
claims: {
|
|
145
|
+
'custom:AR': JSON.stringify({ businessIds: { 'ABC': 'R', 'XYZ': 'R' } }),
|
|
146
|
+
'custom:DBI': JSON.stringify({ defaultBid: 'spam' }),
|
|
147
|
+
'custom:MOD': JSON.stringify({ module: { part: true } }),
|
|
148
|
+
'custom:SYSTEM': JSON.stringify('true')
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
body: { businessId: 'ALPHA' }
|
|
153
|
+
};
|
|
154
|
+
export const mock5 = {
|
|
155
|
+
pathParameters: {
|
|
156
|
+
id: 1
|
|
157
|
+
},
|
|
158
|
+
queryStringParameters: {
|
|
159
|
+
businessIds: 'ALPHA'
|
|
160
|
+
},
|
|
161
|
+
requestContext: {
|
|
162
|
+
authorizer: {
|
|
163
|
+
claims: {
|
|
164
|
+
'custom:AR': JSON.stringify({ businessIds: { 'ABC': 'R', 'XYZ': 'R' } }),
|
|
165
|
+
'custom:DBI': JSON.stringify({ defaultBid: 'spam' }),
|
|
166
|
+
'custom:MOD': JSON.stringify({ module: { part: true } }),
|
|
167
|
+
'custom:SYSTEM': JSON.stringify('true')
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
body: { businessId: 'DOG' }
|
|
172
|
+
};
|
|
173
|
+
export const mock6 = {
|
|
174
|
+
pathParameters: {
|
|
175
|
+
id: 1
|
|
176
|
+
},
|
|
177
|
+
requestContext: {
|
|
178
|
+
authorizer: {
|
|
179
|
+
claims: {
|
|
180
|
+
'custom:AR': JSON.stringify({ businessIds: { 'ABC': 'R', 'XYZ': 'R' } }),
|
|
181
|
+
'custom:DBI': JSON.stringify({ defaultBid: 'spam' }),
|
|
182
|
+
'custom:MOD': JSON.stringify({ module: { part: true } }),
|
|
183
|
+
'custom:SYSTEM': JSON.stringify('true')
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
body: { businessId: 'DOG' }
|
|
188
|
+
};
|
|
189
|
+
export const mock7 = {
|
|
190
|
+
pathParameters: {
|
|
191
|
+
id: 1
|
|
192
|
+
},
|
|
193
|
+
requestContext: {
|
|
194
|
+
authorizer: {
|
|
195
|
+
claims: {
|
|
196
|
+
'custom:AR': JSON.stringify({ businessIds: { 'ABC': 'R', 'XYZ': 'R' } }),
|
|
197
|
+
'custom:DBI': JSON.stringify({ defaultBid: 'spam' }),
|
|
198
|
+
'custom:MOD': JSON.stringify({ module: { part: true } }),
|
|
199
|
+
'custom:SYSTEM': JSON.stringify('true')
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
body: null
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
describe('accessRightsUtils', () => {
|
|
207
|
+
describe('getRequestedBusinessIds', () => {
|
|
208
|
+
it('should get bid from query', () => {
|
|
209
|
+
const r = getRequestedBusinessIds(mock5);
|
|
210
|
+
|
|
211
|
+
expect(r).toEqual(['ALPHA']);
|
|
212
|
+
});
|
|
213
|
+
it('should get bid from body', () => {
|
|
214
|
+
const r = getRequestedBusinessIds(mock6);
|
|
215
|
+
|
|
216
|
+
expect(r).toEqual(['DOG']);
|
|
217
|
+
});
|
|
218
|
+
it('returns [] if no bids found', () => {
|
|
219
|
+
const r = getRequestedBusinessIds(mock7);
|
|
220
|
+
|
|
221
|
+
expect(r).toEqual([]);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe('accessRightsUtils', () => {
|
|
226
|
+
it('should return access of request query stings if they are granted in JWT', () => {
|
|
227
|
+
const result = accessRightsUtils(mock);
|
|
228
|
+
expect(result).toEqual(['ABC']);
|
|
229
|
+
});
|
|
230
|
+
it('should return access 2', () => {
|
|
231
|
+
const result = accessRightsUtils(mock2);
|
|
232
|
+
expect(result).toEqual([]);
|
|
233
|
+
});
|
|
234
|
+
it('should not return access', () => {
|
|
235
|
+
const result = accessRightsUtils(mockNOAccess);
|
|
236
|
+
expect(result).toEqual([]);
|
|
237
|
+
});
|
|
238
|
+
it('should return access for all if not requested in list', () => {
|
|
239
|
+
const result = accessRightsUtils(mockNoneRequested);
|
|
240
|
+
expect(result).toEqual(['ABC']);
|
|
241
|
+
});
|
|
242
|
+
it('should return access for all if not requested in list', () => {
|
|
243
|
+
const result = accessRightsUtils(mockNoneRequestedSystem);
|
|
244
|
+
expect(result).toEqual(['DUCK']);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
describe('userDefaultBid', () => {
|
|
248
|
+
it('should return defaultBid', () => {
|
|
249
|
+
const result = userDefaultBid(mock);
|
|
250
|
+
expect(result).toEqual('spam');
|
|
251
|
+
});
|
|
252
|
+
it('should return defaultBid', () => {
|
|
253
|
+
const result = userDefaultBid(mock2);
|
|
254
|
+
expect(result).toEqual('1');
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
describe('getModuleInfo', () => {
|
|
258
|
+
it('should return default module list', () => {
|
|
259
|
+
const result = getModuleInfo(mock);
|
|
260
|
+
expect(result).toEqual({ part: true });
|
|
261
|
+
});
|
|
262
|
+
it('should return empty module', () => {
|
|
263
|
+
const result = getModuleInfo(mock2);
|
|
264
|
+
expect(result).toEqual({});
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
describe('checkModule', () => {
|
|
268
|
+
it('all system users all access', () => {
|
|
269
|
+
checkModule('part', mockSystem);
|
|
270
|
+
});
|
|
271
|
+
it('check for module access', () => {
|
|
272
|
+
checkModule('part', mock);
|
|
273
|
+
});
|
|
274
|
+
it('should throw', () => {
|
|
275
|
+
try {
|
|
276
|
+
checkModule('span', mock);
|
|
277
|
+
} catch (e) {
|
|
278
|
+
expect(e).toEqual({ message: 'UNAUTHORIZED', errorCode: '4111', statusCode: 401 });
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
describe('checkWriteAccess', () => {
|
|
283
|
+
it('check for write access', () => {
|
|
284
|
+
const result = checkWriteAccess(mock);
|
|
285
|
+
expect(result).toEqual('ABC');
|
|
286
|
+
});
|
|
287
|
+
it('should throw if no access', () => {
|
|
288
|
+
try {
|
|
289
|
+
checkWriteAccess({});
|
|
290
|
+
} catch (e) {
|
|
291
|
+
expect(e).toEqual({ message: 'UNAUTHORIZED', errorCode: '4111', statusCode: 401 });
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
it('should throw if read only', () => {
|
|
295
|
+
try {
|
|
296
|
+
checkWriteAccess(mock3);
|
|
297
|
+
} catch (e) {
|
|
298
|
+
expect(e).toEqual({ message: 'UNAUTHORIZED', errorCode: '4111', statusCode: 401 });
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
it('return businessId in body if is a system uer', () => {
|
|
302
|
+
const v = checkWriteAccess(mock4);
|
|
303
|
+
expect(v).toEqual('ALPHA');
|
|
304
|
+
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
describe('special env cases', () => {
|
|
310
|
+
beforeEach(() => {
|
|
311
|
+
process.env.BUILD_ENV = 'local';
|
|
312
|
+
});
|
|
313
|
+
afterEach(() => {
|
|
314
|
+
process.env.BUILD_ENV = 'test';
|
|
315
|
+
});
|
|
316
|
+
it('should return localBidList and support use cognito bid option', () => {
|
|
317
|
+
const event = {
|
|
318
|
+
requestContext: {
|
|
319
|
+
authorizer: {
|
|
320
|
+
claims: {
|
|
321
|
+
'custom:AR': JSON.stringify({ businessIds: { 'ABC': 'A', 'XYZ': 'A' } })
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
const result = accessRightsUtils(event, { useCognitoBid: true });
|
|
327
|
+
expect(result).toEqual(['ABC', 'XYZ']);
|
|
328
|
+
});
|
|
329
|
+
it('should return localBidList if no claims and support use cognito bid option', () => {
|
|
330
|
+
const event = {
|
|
331
|
+
requestContext: {
|
|
332
|
+
authorizer: {
|
|
333
|
+
claims: {}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
const result = accessRightsUtils(event, { useCognitoBid: true });
|
|
338
|
+
expect(result).toEqual(['1']);
|
|
339
|
+
});
|
|
340
|
+
describe('getBusinessesInfo', () => {
|
|
341
|
+
it('should handle local', () => {
|
|
342
|
+
const result = getBusinessesInfo(mock);
|
|
343
|
+
expect(result).toEqual({ '1': 'A', ABC: 'A', XYZ: 'A' });
|
|
344
|
+
});
|
|
345
|
+
it('should handle local v2', () => {
|
|
346
|
+
const result = getBusinessesInfo(mock2NoAuth);
|
|
347
|
+
expect(result).toEqual({ '1': 'A', ABC: 'A' });
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
it('should return localBidList no options', () => {
|
|
351
|
+
const event = {
|
|
352
|
+
requestContext: {
|
|
353
|
+
authorizer: {
|
|
354
|
+
claims: null,
|
|
355
|
+
custom: {
|
|
356
|
+
AR: null
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
const result = accessRightsUtils(event);
|
|
362
|
+
expect(result).toEqual(['1']);
|
|
363
|
+
});
|
|
364
|
+
it('not prod or stg', () => {
|
|
365
|
+
const result = accessRightsUtils({});
|
|
366
|
+
expect(result).toEqual(['1']);
|
|
367
|
+
});
|
|
368
|
+
});
|
|
@@ -11,8 +11,9 @@ import { accessRightsUtils } from './accessRightsUtils.js';
|
|
|
11
11
|
* @param {object} objectFilters - the default filters object created by createDefaultFilters
|
|
12
12
|
* @returns {object} An sequelize where object
|
|
13
13
|
*/
|
|
14
|
-
export const createFilters = function (event, objectFilters){
|
|
14
|
+
export const createFilters = function (event, objectFilters) {
|
|
15
15
|
let query = _.get(event, 'queryStringParameters', {}) || {};
|
|
16
|
+
const searchString = _.get(query, 'searchString');
|
|
16
17
|
const startDate = _.get(query, 'startDate');
|
|
17
18
|
const endDate = _.get(query, 'endDate');
|
|
18
19
|
const where = Object.keys(query).reduce((acc, item) => {
|
|
@@ -86,6 +87,40 @@ export const createFilters = function (event, objectFilters){
|
|
|
86
87
|
filterAdds.createdAt = dates;
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
if (searchString) {
|
|
91
|
+
const adds = Object.keys(objectFilters).reduce((acc, item) => {
|
|
92
|
+
const type = objectFilters[item].filterType;
|
|
93
|
+
const dataType = objectFilters[item].type;
|
|
94
|
+
|
|
95
|
+
if (type === DB.Op.iLike) {
|
|
96
|
+
const newOr = {};
|
|
97
|
+
const itemName = item.includes('.')
|
|
98
|
+
? `$${item}$`
|
|
99
|
+
: item;
|
|
100
|
+
newOr[itemName] = {
|
|
101
|
+
[DB.Op.iLike]: `%${query['searchString']}%`
|
|
102
|
+
};
|
|
103
|
+
acc.push(newOr);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!_.isNaN(Number(query['searchString'])) && !(dataType instanceof DB.BOOLEAN)) {
|
|
107
|
+
|
|
108
|
+
if (type === DB.Op.eq) {
|
|
109
|
+
const newOr = {};
|
|
110
|
+
const itemName = item.includes('.') ? `$${item}$` : item;
|
|
111
|
+
newOr[itemName] = {
|
|
112
|
+
[DB.Op.eq]: `${query['searchString']}`
|
|
113
|
+
};
|
|
114
|
+
acc.push(newOr);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return acc;
|
|
119
|
+
}, []);
|
|
120
|
+
|
|
121
|
+
filterAdds[DB.Op.or] = adds;
|
|
122
|
+
}
|
|
123
|
+
|
|
89
124
|
const withDate = Object.assign(where, filterAdds);
|
|
90
125
|
|
|
91
126
|
return withDate;
|