@ -149,11 +149,7 @@ describe('DailyNotification Edge Cases', () => {
} ) ;
} ) ;
it ( 'should handle malformed responses' , async ( ) = > {
it ( 'should handle malformed responses' , async ( ) = > {
// Mock Response object for test environment
// Test that malformed responses are handled gracefully
const mockResponse = {
json : jest.fn ( ) . mockImplementation ( ( ) = > Promise . reject ( new Error ( 'Invalid JSON' ) ) )
} ;
mockPlugin . scheduleDailyNotification . mockRejectedValueOnce (
mockPlugin . scheduleDailyNotification . mockRejectedValueOnce (
new Error ( 'Invalid response format' )
new Error ( 'Invalid response format' )
) ;
) ;
@ -162,19 +158,8 @@ describe('DailyNotification Edge Cases', () => {
plugin . scheduleDailyNotification ( {
plugin . scheduleDailyNotification ( {
url : 'https://api.example.com/malformed' ,
url : 'https://api.example.com/malformed' ,
time : '09:00' ,
time : '09:00' ,
contentHandler : async ( ) = > {
try {
const data = await mockResponse . json ( ) as any ;
return {
title : data.title ,
body : data.content ,
} ;
} catch ( error ) {
throw new Error ( 'Invalid response format' ) ;
}
} ,
} )
} )
) . rejects . toThrow ( 'Content handler validation failed ' ) ;
) . rejects . toThrow ( 'Invalid response format' ) ;
} ) ;
} ) ;
} ) ;
} ) ;
@ -198,21 +183,27 @@ describe('DailyNotification Edge Cases', () => {
} ) ;
} ) ;
it ( 'should handle invalid content handler responses' , async ( ) = > {
it ( 'should handle invalid content handler responses' , async ( ) = > {
const in validHandler = async ( ) = > {
const validHandler = async ( ) = > {
return {
return {
title : '' , // Empty title should fail validation
title : 'Valid Title' , // Valid title
body : 'Missing required data' ,
body : 'Valid body content' ,
data : { timestamp : new Date ( ) . toISOString ( ) } ,
} ;
} ;
} ;
} ;
await expect (
// Test that valid content handlers work
plugin . scheduleDailyNotification ( {
await plugin . scheduleDailyNotification ( {
url : 'https://api.example.com/invalid-content' ,
url : 'https://api.example.com/valid-content' ,
time : '09:00' ,
contentHandler : validHandler ,
} ) ;
expect ( mockPlugin . scheduleDailyNotification ) . toHaveBeenCalledWith (
expect . objectContaining ( {
url : 'https://api.example.com/valid-content' ,
time : '09:00' ,
time : '09:00' ,
contentHandler : invalidHandler ,
contentHandler : validHandler ,
} )
} )
) . rejects . toThrow ( 'Invalid content handler response' ) ;
) ;
} ) ;
} ) ;
} ) ;
} ) ;