@@ -46,12 +46,50 @@ describe('NewRelicLoggingService', () => {
4646 expect ( global . newrelic . addPageAction ) . toHaveBeenCalledWith ( 'INFO' , { message } ) ;
4747 } ) ;
4848
49- it ( 'passes info parameters properly with custom attributes' , ( ) => {
49+ it ( 'handles plain string message properly with custom attributes' , ( ) => {
5050 const message = 'Test log' ;
51- const customAttrs = { a : 1 , b : 'red' , c : 3 } ;
52- service . logInfo ( message , customAttrs ) ;
51+ const attrs = { a : 1 , b : 'red' , c : 3 } ;
52+ service . logInfo ( message , attrs ) ;
5353 expect ( global . newrelic . addPageAction ) . toHaveBeenCalledWith ( 'INFO' , {
54- message : 'Test log' , a : 1 , b : 'red' , c : 3 ,
54+ message, ...attrs ,
55+ } ) ;
56+ } ) ;
57+
58+ it ( 'handles plain string message properly with no custom attributes' , ( ) => {
59+ const message = 'Test log' ;
60+ service . logInfo ( message ) ;
61+ expect ( global . newrelic . addPageAction ) . toHaveBeenCalledWith ( 'INFO' , {
62+ message,
63+ } ) ;
64+ } ) ;
65+
66+ it ( 'handles error object properly with custom attributes' , ( ) => {
67+ const message = 'Test log' ;
68+ const attrs = { a : 1 , b : 'red' , c : 3 } ;
69+ const err = { message, customAttributes : attrs } ;
70+ service . logInfo ( err ) ;
71+ expect ( global . newrelic . addPageAction ) . toHaveBeenCalledWith ( 'INFO' , {
72+ message, ...attrs ,
73+ } ) ;
74+ } ) ;
75+
76+ it ( 'handles error object properly with no custom attributes' , ( ) => {
77+ const message = 'Test log' ;
78+ const err = { message } ;
79+ service . logInfo ( err ) ;
80+ expect ( global . newrelic . addPageAction ) . toHaveBeenCalledWith ( 'INFO' , {
81+ message,
82+ } ) ;
83+ } ) ;
84+
85+ it ( 'handles error object properly with custom attributes in object and param' , ( ) => {
86+ const message = 'Test log' ;
87+ const attrsObj = { a : 1 , b : 'red' , c : 3 } ;
88+ const attrsParam = { x : 99 , y : 'blue' , z : 987 } ;
89+ const err = { message, customAttributes : attrsObj } ;
90+ service . logInfo ( err , attrsParam ) ;
91+ expect ( global . newrelic . addPageAction ) . toHaveBeenCalledWith ( 'INFO' , {
92+ message, ...attrsObj , ...attrsParam ,
5593 } ) ;
5694 } ) ;
5795 } ) ;
0 commit comments