2025-02-10 07:51:01 -08:00
import { mock } from 'jest-mock-extended' ;
import type { IExecuteFunctions , INodeExecutionData } from 'n8n-workflow' ;
2024-12-19 09:46:14 -08:00
2024-11-27 08:31:36 -08:00
import { addPostExecutionWarning } from '../utils' ;
describe ( 'addPostExecutionWarning' , ( ) = > {
2025-02-10 07:51:01 -08:00
const context = mock < IExecuteFunctions > ( ) ;
2024-11-27 08:31:36 -08:00
const inputItemsLength = 2 ;
2025-02-10 07:51:01 -08:00
beforeEach ( ( ) = > jest . resetAllMocks ( ) ) ;
it ( 'should add execution hints when returnData length differs from inputItemsLength' , ( ) = > {
2024-11-27 08:31:36 -08:00
const returnData : INodeExecutionData [ ] = [ { json : { } , pairedItem : 0 } ] ;
2025-02-10 07:51:01 -08:00
addPostExecutionWarning ( context , returnData , inputItemsLength ) ;
2024-11-27 08:31:36 -08:00
2025-02-10 07:51:01 -08:00
expect ( context . addExecutionHints ) . toHaveBeenCalledWith ( {
message :
'To make sure expressions after this node work, return the input items that produced each output item. <a target="_blank" href="https://docs.n8n.io/data/data-mapping/data-item-linking/item-linking-code-node/">More info</a>' ,
location : 'outputPane' ,
} ) ;
2024-11-27 08:31:36 -08:00
} ) ;
2025-02-10 07:51:01 -08:00
it ( 'should add execution hints when any item has undefined pairedItem' , ( ) = > {
2024-11-27 08:31:36 -08:00
const returnData : INodeExecutionData [ ] = [ { json : { } , pairedItem : 0 } , { json : { } } ] ;
2025-02-10 07:51:01 -08:00
addPostExecutionWarning ( context , returnData , inputItemsLength ) ;
2024-11-27 08:31:36 -08:00
2025-02-10 07:51:01 -08:00
expect ( context . addExecutionHints ) . toHaveBeenCalledWith ( {
message :
'To make sure expressions after this node work, return the input items that produced each output item. <a target="_blank" href="https://docs.n8n.io/data/data-mapping/data-item-linking/item-linking-code-node/">More info</a>' ,
location : 'outputPane' ,
} ) ;
2024-11-27 08:31:36 -08:00
} ) ;
2025-02-10 07:51:01 -08:00
it ( 'should not add execution hints when all items match inputItemsLength and have defined pairedItem' , ( ) = > {
2024-11-27 08:31:36 -08:00
const returnData : INodeExecutionData [ ] = [
{ json : { } , pairedItem : 0 } ,
{ json : { } , pairedItem : 1 } ,
] ;
2025-02-10 07:51:01 -08:00
addPostExecutionWarning ( context , returnData , inputItemsLength ) ;
2024-11-27 08:31:36 -08:00
2025-02-10 07:51:01 -08:00
expect ( context . addExecutionHints ) . not . toHaveBeenCalled ( ) ;
2024-11-27 08:31:36 -08:00
} ) ;
} ) ;