Skip to content

Commit bf7a379

Browse files
Add tests
1 parent 9834390 commit bf7a379

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

packages/server/shared/test/log-cleaner.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,48 @@ describe('log-cleaner', () => {
263263
});
264264
});
265265

266+
it('should handle error context with circular reference', () => {
267+
const error = new Error('test error');
268+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
269+
const circularContext: any = { key: 'value' };
270+
circularContext.circular = circularContext;
271+
Object.assign(error, circularContext);
272+
273+
const logEvent = {
274+
event: error,
275+
};
276+
277+
const result = cleanLogEvent(logEvent);
278+
279+
expect(result.event.errorContext).toMatch(
280+
/^Logger error - could not stringify object\./,
281+
);
282+
});
283+
284+
it('should handle ApplicationError params with circular reference', () => {
285+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
286+
const circularParams: any = {
287+
message: 'test',
288+
data: {},
289+
};
290+
circularParams.data.circular = circularParams;
291+
292+
const appError = new ApplicationError({
293+
code: ErrorCode.ENTITY_NOT_FOUND,
294+
params: circularParams,
295+
});
296+
297+
const logEvent = {
298+
event: appError,
299+
};
300+
301+
const result = cleanLogEvent(logEvent);
302+
303+
expect(result.event.errorParams).toMatch(
304+
/^Logger error - could not stringify object\./,
305+
);
306+
});
307+
266308
it('should flatten error in correct fields by prefix', () => {
267309
const logEvent = {
268310
event: {

0 commit comments

Comments
 (0)