piper-utils 1.1.69 → 1.1.71

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/src/index.js CHANGED
@@ -34,6 +34,7 @@ import { requireCrmAccess as requireCrmAccessImport, requireTicketAccess as requ
34
34
  import { scopeToOwnBusiness as scopeToOwnBusinessImport, scopeToPartnerBook as scopeToPartnerBookImport, scopeToBookUnionOwn as scopeToBookUnionOwnImport } from './database/dbUtils/partnerAccess/accessScope.js';
35
35
  import { assertCanWriteOwnBusiness as assertCanWriteOwnBusinessImport, assertCanWriteBookBusiness as assertCanWriteBookBusinessImport, assertCanWriteBookUnionOwn as assertCanWriteBookUnionOwnImport, stampOwnBusinessId as stampOwnBusinessIdImport } from './database/dbUtils/partnerAccess/accessWrites.js';
36
36
  import { createAccessHelpers as createAccessHelpersImport } from './database/dbUtils/partnerAccess/createAccessHelpers.js';
37
+ import { contractChoices as contractChoicesImport, contractStatuses as contractStatusesImport, isContractChoice as isContractChoiceImport } from './contract/contract.js';
37
38
  import {
38
39
  attachAudit as attachAuditImport,
39
40
  bindAuditRequest as bindAuditRequestImport,
@@ -96,3 +97,6 @@ export const decrementWithAudit = decrementWithAuditImport;
96
97
  export const getAuditFilter = getAuditFilterImport;
97
98
  export const getAuditModel = getAuditModelImport;
98
99
  export const incrementWithAudit = incrementWithAuditImport;
100
+ export const contractChoices = contractChoicesImport;
101
+ export const contractStatuses = contractStatusesImport;
102
+ export const isContractChoice = isContractChoiceImport;
@@ -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', () => {