@ -223,12 +223,6 @@ describe('WebhookServer', () => {
}
} ) ;
function getFutureDate ( days : number ) : string {
const date = new Date ( ) ;
date . setDate ( date . getDate ( ) + days ) ;
return date . toISOString ( ) . split ( 'T' ) [ 0 ] ;
}
describe ( '/tarea command logging' , ( ) = > {
let consoleSpy : any ;
@ -274,7 +268,6 @@ describe('WebhookServer', () => {
} ) ;
test ( 'should log command with due date' , async ( ) = > {
const futureDate = getFutureDate ( 3 ) ; // Get date 3 days in future
const payload = {
event : 'messages.upsert' ,
instance : 'test-instance' ,
@ -284,7 +277,7 @@ describe('WebhookServer', () => {
participant : 'user123@s.whatsapp.net'
} ,
message : {
conversation : ` /tarea nueva Finish project @user2 ${ futureDate } ` ,
conversation : '/tarea nueva Finish project @user2 2025-04-30' ,
contextInfo : {
mentionedJid : [ 'user2@s.whatsapp.net' ]
}
@ -295,25 +288,24 @@ describe('WebhookServer', () => {
await WebhookServer . handleRequest ( createTestRequest ( payload ) ) ;
// Verify the two command-related log calls
expect ( consoleSpy ) . toHaveBeenCalledTimes ( 2 ) ;
// First call should be the command detection
expect ( consoleSpy . mock . calls [ 0 ] [ 0 ] ) . toBe ( '🔍 Detected /tarea command:' ) ;
expect ( consoleSpy . mock . calls [ 0 ] [ 1 ] ) . toEqual ( {
timestamp : expect.any ( String ) ,
from : 'user123@s.whatsapp.net' ,
group : 'group123@g.us' ,
rawMessage : ` /tarea nueva Finish project @user2 ${ futureDate } `
} ) ;
expect ( consoleSpy ) . toHaveBeenCalledWith (
'🔍 Detected /tarea command:' ,
expect . objectContaining ( {
from : 'user123@s.whatsapp.net' ,
group : 'group123@g.us' ,
rawMessage : '/tarea nueva Finish project @user2 2025-04-30'
} )
) ;
// Second call should be the successful parsing
expect ( consoleSpy . mock . calls [ 1 ] [ 0 ] ) . toBe ( '✅ Successfully parsed command:' ) ;
expect ( consoleSpy . mock . calls [ 1 ] [ 1 ] ) . toEqual ( {
action : 'nueva' ,
description : 'Finish project @user2' ,
dueDate : futureDate ,
mentionCount : 1
} ) ;
expect ( consoleSpy ) . toHaveBeenCalledWith (
'✅ Successfully parsed command:' ,
expect . objectContaining ( {
action : 'nueva' ,
description : 'Finish project @user2' ,
dueDate : '2025-04-30' ,
mentionCount : expect.any ( Number )
} )
) ;
} ) ;
} ) ;
@ -335,115 +327,4 @@ describe('WebhookServer', () => {
expect ( response . status ) . toBe ( 200 ) ;
expect ( mockAdd ) . toHaveBeenCalled ( ) ;
} ) ;
test ( 'should handle multiple dates in command (use last one as due date)' , async ( ) = > {
const futureDate1 = getFutureDate ( 3 ) ;
const futureDate2 = getFutureDate ( 5 ) ;
const payload = {
event : 'messages.upsert' ,
instance : 'test-instance' ,
data : {
key : {
remoteJid : 'group-id@g.us' ,
participant : 'sender-id@s.whatsapp.net'
} ,
message : {
conversation : ` /tarea nueva Test task ${ futureDate1 } some text ${ futureDate2 } `
}
}
} ;
await WebhookServer . handleRequest ( createTestRequest ( payload ) ) ;
expect ( console . log ) . toHaveBeenCalledWith (
'✅ Successfully parsed command:' ,
expect . objectContaining ( {
description : ` Test task ${ futureDate1 } some text ` ,
dueDate : futureDate2
} )
) ;
} ) ;
test ( 'should ignore past dates as due dates' , async ( ) = > {
const pastDate = '2020-01-01' ;
const futureDate = getFutureDate ( 2 ) ;
const payload = {
event : 'messages.upsert' ,
instance : 'test-instance' ,
data : {
key : {
remoteJid : 'group-id@g.us' ,
participant : 'sender-id@s.whatsapp.net'
} ,
message : {
conversation : ` /tarea nueva Test task ${ pastDate } more text ${ futureDate } `
}
}
} ;
await WebhookServer . handleRequest ( createTestRequest ( payload ) ) ;
expect ( console . log ) . toHaveBeenCalledWith (
'✅ Successfully parsed command:' ,
expect . objectContaining ( {
description : ` Test task ${ pastDate } more text ` ,
dueDate : futureDate
} )
) ;
} ) ;
test ( 'should handle multiple past dates correctly' , async ( ) = > {
const pastDate1 = '2020-01-01' ;
const pastDate2 = '2021-01-01' ;
const payload = {
event : 'messages.upsert' ,
instance : 'test-instance' ,
data : {
key : {
remoteJid : 'group-id@g.us' ,
participant : 'sender-id@s.whatsapp.net'
} ,
message : {
conversation : ` /tarea nueva Test task ${ pastDate1 } and ${ pastDate2 } `
}
}
} ;
await WebhookServer . handleRequest ( createTestRequest ( payload ) ) ;
expect ( console . log ) . toHaveBeenCalledWith (
'✅ Successfully parsed command:' ,
expect . objectContaining ( {
description : ` Test task ${ pastDate1 } and ${ pastDate2 } ` ,
dueDate : 'none'
} )
) ;
} ) ;
test ( 'should handle mixed valid and invalid date formats' , async ( ) = > {
const futureDate = getFutureDate ( 2 ) ;
const payload = {
event : 'messages.upsert' ,
instance : 'test-instance' ,
data : {
key : {
remoteJid : 'group-id@g.us' ,
participant : 'sender-id@s.whatsapp.net'
} ,
message : {
conversation : ` /tarea nueva Test task 2023-13-01 (invalid) ${ futureDate } 25/12/2023 (invalid) `
}
}
} ;
await WebhookServer . handleRequest ( createTestRequest ( payload ) ) ;
expect ( console . log ) . toHaveBeenCalledWith (
'✅ Successfully parsed command:' ,
expect . objectContaining ( {
description : 'Test task 2023-13-01 (invalid) 25/12/2023 (invalid)' ,
dueDate : futureDate
} )
) ;
} ) ;
} ) ;