@@ -180,6 +180,11 @@ describe('CustomFormula', () => {
180180 expect ( result ) . toBe ( '2025-01-08' ) ; // Should use oldest transaction date (2025-01-08)
181181 } ) ;
182182
183+ test ( 'should compute enddate formula using transactions' , ( ) => {
184+ const result = compute ( '{report:enddate}' , mockContext ) ;
185+ expect ( result ) . toBe ( '2025-01-14' ) ; // Should use newest transaction date (2025-01-14)
186+ } ) ;
187+
183188 test ( 'should compute created formula using report actions' , ( ) => {
184189 const result = compute ( '{report:created}' , mockContext ) ;
185190 expect ( result ) . toBe ( '2025-01-10' ) ; // Should use oldest report action date (2025-01-10)
@@ -190,6 +195,11 @@ describe('CustomFormula', () => {
190195 expect ( result ) . toBe ( '01/08/2025' ) ; // Should use oldest transaction date with yyyy-MM-dd format
191196 } ) ;
192197
198+ test ( 'should compute enddate with custom format' , ( ) => {
199+ const result = compute ( '{report:enddate:MM/dd/yyyy}' , mockContext ) ;
200+ expect ( result ) . toBe ( '01/14/2025' ) ; // Should use newest transaction date with MM/dd/yyyy format
201+ } ) ;
202+
193203 test ( 'should compute created with custom format' , ( ) => {
194204 const result = compute ( '{report:created:MMMM dd, yyyy}' , mockContext ) ;
195205 expect ( result ) . toBe ( 'January 10, 2025' ) ; // Should use oldest report action date with MMMM dd, yyyy format
@@ -200,6 +210,11 @@ describe('CustomFormula', () => {
200210 expect ( result ) . toBe ( '08 Jan 2025' ) ; // Should use oldest transaction date with dd MMM yyyy format
201211 } ) ;
202212
213+ test ( 'should compute enddate with short month format' , ( ) => {
214+ const result = compute ( '{report:enddate:dd MMM yyyy}' , mockContext ) ;
215+ expect ( result ) . toBe ( '14 Jan 2025' ) ; // Should use newest transaction date with dd MMM yyyy format
216+ } ) ;
217+
203218 test ( 'should compute policy name' , ( ) => {
204219 const result = compute ( '{report:policyname}' , mockContext ) ;
205220 expect ( result ) . toBe ( 'Test Policy' ) ;
@@ -366,6 +381,18 @@ describe('CustomFormula', () => {
366381 expect ( result ) . toBe ( expected ) ;
367382 } ) ;
368383
384+ test ( 'should handle missing transactions for enddate' , ( ) => {
385+ mockReportUtils . getReportTransactions . mockReturnValue ( [ ] ) ;
386+ const context : FormulaContext = {
387+ report : { reportID : '123' } as Report ,
388+ policy : null as unknown as Policy ,
389+ } ;
390+ const today = new Date ( ) ;
391+ const expected = `${ today . getFullYear ( ) } -${ String ( today . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) } -${ String ( today . getDate ( ) ) . padStart ( 2 , '0' ) } ` ;
392+ const result = compute ( '{report:enddate}' , context ) ;
393+ expect ( result ) . toBe ( expected ) ;
394+ } ) ;
395+
369396 test ( 'should call getReportTransactions with correct reportID for startdate' , ( ) => {
370397 const context : FormulaContext = {
371398 report : { reportID : 'test-report-123' } as Report ,
@@ -416,6 +443,9 @@ describe('CustomFormula', () => {
416443
417444 const result = compute ( '{report:startdate}' , context ) ;
418445 expect ( result ) . toBe ( '2025-01-12' ) ;
446+
447+ const endResult = compute ( '{report:enddate}' , context ) ;
448+ expect ( endResult ) . toBe ( '2025-01-15' ) ;
419449 } ) ;
420450
421451 test ( 'should skip partial transactions (zero amount)' , ( ) => {
@@ -449,6 +479,9 @@ describe('CustomFormula', () => {
449479
450480 const result = compute ( '{report:startdate}' , context ) ;
451481 expect ( result ) . toBe ( '2025-01-12' ) ;
482+
483+ const endResult = compute ( '{report:enddate}' , context ) ;
484+ expect ( endResult ) . toBe ( '2025-01-15' ) ;
452485 } ) ;
453486 } ) ;
454487} ) ;
0 commit comments