@@ -30,9 +30,50 @@ describe('generateHackParserPresignedURL', () => {
3030 expect ( result ) . toBeUndefined ( ) ;
3131 } ) ;
3232
33- it ( 'should throw an error if the Lambda response is invalid' , async ( ) => {
33+ it ( 'should throw an error if the Lambda response is invalid JSON ' , async ( ) => {
3434 ( invokeLambda as jest . Mock ) . mockResolvedValue ( { Payload : 'invalid_json' } ) ;
3535
3636 await expect ( generateHackParserPresignedURL ( 'file3.txt' ) ) . rejects . toThrow ( ) ;
3737 } ) ;
38+
39+ it ( 'should decode ASCII-encoded payload and return a valid presigned URL' , async ( ) => {
40+ const key = 'file4.txt' ;
41+ const asciiPayload = JSON . stringify ( [
42+ 123 , 34 , 102 , 105 , 108 , 101 , 52 , 46 , 116 , 120 , 116 , 34 , 58 , 32 , 34 , 104 , 116 , 116 , 112 , 115 ,
43+ 58 , 47 , 47 , 109 , 111 , 99 , 107 , 45 , 117 , 114 , 108 , 45 , 52 , 34 , 125 ,
44+ ] ) ;
45+
46+ ( invokeLambda as jest . Mock ) . mockResolvedValue ( { Payload : asciiPayload } ) ;
47+
48+ const result = await generateHackParserPresignedURL ( key ) ;
49+
50+ expect ( result ) . toEqual ( 'https://mock-url-4' ) ;
51+ } ) ;
52+
53+ it ( 'should handle Uint8ArrayBlobAdapter payload correctly' , async ( ) => {
54+ const key = 'file5.txt' ;
55+ const mockResponse = { 'file5.txt' : 'https://mock-url-5' } ;
56+ const uint8ArrayPayload = new TextEncoder ( ) . encode ( JSON . stringify ( mockResponse ) ) ;
57+
58+ ( invokeLambda as jest . Mock ) . mockResolvedValue ( { Payload : uint8ArrayPayload } ) ;
59+
60+ const result = await generateHackParserPresignedURL ( key ) ;
61+ expect ( result ) . toEqual ( 'https://mock-url-5' ) ;
62+ } ) ;
63+
64+ it ( 'should return undefined if Payload is undefined' , async ( ) => {
65+ const key = 'file6.txt' ;
66+ ( invokeLambda as jest . Mock ) . mockResolvedValue ( { Payload : undefined } ) ;
67+
68+ const result = await generateHackParserPresignedURL ( key ) ;
69+ expect ( result ) . toBeUndefined ( ) ;
70+ } ) ;
71+
72+ it ( 'should handle empty Lambda response gracefully' , async ( ) => {
73+ const key = 'file8.txt' ;
74+ ( invokeLambda as jest . Mock ) . mockResolvedValue ( { } ) ;
75+
76+ const result = await generateHackParserPresignedURL ( key ) ;
77+ expect ( result ) . toBeUndefined ( ) ;
78+ } ) ;
3879} ) ;
0 commit comments