@@ -75,6 +75,20 @@ describe('HMAC Utility Functions', () => {
7575 ) . to . equal ( expectedSubject ) ;
7676 } ) ;
7777
78+ it ( 'should not include undefined for a response when text is undefined' , ( ) => {
79+ const expectedSubject = 'GET|1672531200000|/api/test|200|' ;
80+ expect (
81+ calculateHMACSubject ( {
82+ urlPath : '/api/test' ,
83+ text : undefined as unknown as string ,
84+ timestamp : MOCK_TIMESTAMP ,
85+ statusCode : 200 ,
86+ method : 'get' ,
87+ authVersion : 3 ,
88+ } )
89+ ) . to . equal ( expectedSubject ) ;
90+ } ) ;
91+
7892 it ( 'should handle Buffer text input and return a Buffer for requests' , ( ) => {
7993 const buffer = Buffer . from ( 'binary-data-content' ) ;
8094 const result = calculateHMACSubject ( {
@@ -96,6 +110,22 @@ describe('HMAC Utility Functions', () => {
96110 expect ( result ) . to . deep . equal ( expectedBuffer ) ;
97111 } ) ;
98112
113+ it ( 'should handle Buffer undefined text input and return a Buffer for requests' , ( ) => {
114+ const buffer = undefined as unknown as Buffer ;
115+ const result = calculateHMACSubject ( {
116+ urlPath : '/api/test' ,
117+ text : buffer ,
118+ timestamp : MOCK_TIMESTAMP ,
119+ method : 'get' ,
120+ authVersion : 3 ,
121+ } ) ;
122+
123+ expect ( Buffer . isBuffer ( result ) ) . to . be . false ;
124+
125+ const expectedSubject = 'GET|1672531200000|3.0|/api/test|' ;
126+ expect ( result ) . to . deep . equal ( expectedSubject ) ;
127+ } ) ;
128+
99129 it ( 'should handle Buffer text input and return a Buffer for responses' , ( ) => {
100130 const buffer = Buffer . from ( 'binary-response-data' ) ;
101131 const result = calculateHMACSubject ( {
0 commit comments