piper-utils 1.1.69 → 1.1.70
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/bin/main.js +27 -17
- package/bin/main.js.map +1 -1
- package/package.json +1 -1
- package/src/database/dbUtils/partnerAccess/accessScope.js +128 -99
- package/src/database/dbUtils/partnerAccess/createAccessHelpers.js +3 -3
- package/src/database/dbUtils/queryStringUtils/createFilters.js +311 -311
- package/src/database/dbUtils/queryStringUtils/createFilters.test.js +682 -682
- package/src/requestResponse/requestResponse.test.js +58 -0
|
@@ -135,6 +135,64 @@ describe('requestResponse', () => {
|
|
|
135
135
|
expect(res.headers['Access-Control-Allow-Origin']).toEqual('*');
|
|
136
136
|
expect(res.headers['Referrer-Policy']).toEqual('strict-origin-when-cross-origin');
|
|
137
137
|
});
|
|
138
|
+
it('should NOT log a known/handled 4xx error (errorCode + 4xx)', () => {
|
|
139
|
+
const prevBuildEnv = process.env.BUILD_ENV;
|
|
140
|
+
const prevUtilLog = process.env.UTIL_LOG;
|
|
141
|
+
process.env.BUILD_ENV = 'production';
|
|
142
|
+
delete process.env.UTIL_LOG;
|
|
143
|
+
const errorSpy = spyOn(console, 'error');
|
|
144
|
+
|
|
145
|
+
const res = failure({ statusCode: 400, errorCode: '4007', message: 'Insufficient funds' }, {});
|
|
146
|
+
|
|
147
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
148
|
+
expect(res.statusCode).toEqual(400);
|
|
149
|
+
|
|
150
|
+
process.env.BUILD_ENV = prevBuildEnv;
|
|
151
|
+
if (prevUtilLog === undefined) {
|
|
152
|
+
delete process.env.UTIL_LOG;
|
|
153
|
+
} else {
|
|
154
|
+
process.env.UTIL_LOG = prevUtilLog;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
it('should log the full object for a 5xx error', () => {
|
|
158
|
+
const prevBuildEnv = process.env.BUILD_ENV;
|
|
159
|
+
const prevUtilLog = process.env.UTIL_LOG;
|
|
160
|
+
process.env.BUILD_ENV = 'production';
|
|
161
|
+
delete process.env.UTIL_LOG;
|
|
162
|
+
const errorSpy = spyOn(console, 'error');
|
|
163
|
+
const body = { statusCode: 500, errorCode: '5001', message: 'boom' };
|
|
164
|
+
|
|
165
|
+
failure(body, {});
|
|
166
|
+
|
|
167
|
+
expect(errorSpy).toHaveBeenCalledWith('------->UTIL ERROR:', 500, 'boom', body);
|
|
168
|
+
|
|
169
|
+
process.env.BUILD_ENV = prevBuildEnv;
|
|
170
|
+
if (prevUtilLog === undefined) {
|
|
171
|
+
delete process.env.UTIL_LOG;
|
|
172
|
+
} else {
|
|
173
|
+
process.env.UTIL_LOG = prevUtilLog;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
it('should log a concise one-liner for an unmapped 4xx error (no deliberate errorCode)', () => {
|
|
177
|
+
const prevBuildEnv = process.env.BUILD_ENV;
|
|
178
|
+
const prevUtilLog = process.env.UTIL_LOG;
|
|
179
|
+
process.env.BUILD_ENV = 'production';
|
|
180
|
+
delete process.env.UTIL_LOG;
|
|
181
|
+
const errorSpy = spyOn(console, 'error');
|
|
182
|
+
|
|
183
|
+
// A Joi-style error (has `details`, no errorCode) maps to a 4xx via detectJoyError,
|
|
184
|
+
// so the original body is not a known client error -> concise branch, no object dump.
|
|
185
|
+
failure({ details: 'bar' }, {});
|
|
186
|
+
|
|
187
|
+
expect(errorSpy).toHaveBeenCalledWith('------->UTIL ERROR:', 400, 'INTERNAL UTIL ERROR');
|
|
188
|
+
|
|
189
|
+
process.env.BUILD_ENV = prevBuildEnv;
|
|
190
|
+
if (prevUtilLog === undefined) {
|
|
191
|
+
delete process.env.UTIL_LOG;
|
|
192
|
+
} else {
|
|
193
|
+
process.env.UTIL_LOG = prevUtilLog;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
138
196
|
});
|
|
139
197
|
describe('parseBody', () => {
|
|
140
198
|
it('parse a json string', () => {
|