Skip to content

Commit

Permalink
additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Feb 11, 2025
1 parent b4990ce commit e469cfb
Show file tree
Hide file tree
Showing 3 changed files with 696 additions and 197 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { INodeExecutionData } from 'n8n-workflow';
import type { IBinaryData, INodeExecutionData } from 'n8n-workflow';
import { ApplicationError } from 'n8n-workflow';

import { normalizeItems } from '../normalize-items';
Expand Down Expand Up @@ -41,6 +41,30 @@ describe('normalizeItems', () => {
{ json: {}, binary: { data: { data: 'binary2', mimeType: 'mime2' } } },
],
},
{
description: 'object with null or undefined values',
input: { key: null, another: undefined } as unknown as INodeExecutionData,
expected: [{ json: { key: null, another: undefined } }],
},
{
description: 'array with mixed non-standard objects',
input: [{ custom: 'value1' }, { another: 'value2' }] as unknown as INodeExecutionData[],
expected: [{ json: { custom: 'value1' } }, { json: { another: 'value2' } }],
},
{
description: 'empty object',
input: {} as INodeExecutionData,
expected: [{ json: {} }],
},
{
description: 'array with primitive values',
input: [1, 'string', true] as unknown as INodeExecutionData[],
expected: [
{ json: 1 },
{ json: 'string' },
{ json: true },
] as unknown as INodeExecutionData[],
},
];
test.each(successTests)('$description', ({ input, expected }) => {
const result = normalizeItems(input);
Expand All @@ -64,6 +88,20 @@ describe('normalizeItems', () => {
{ key: 'value' } as unknown as INodeExecutionData,
],
},
{
description: 'when mixing json and non-json objects with non-json properties',
input: [
{ json: { key1: 'value1' } },
{ other: 'value', custom: 'prop' } as unknown as INodeExecutionData,
],
},
{
description: 'when mixing binary and non-binary objects',
input: [
{ json: {}, binary: { data: { data: 'binarydata' } as IBinaryData } },
{ custom: 'value' } as unknown as INodeExecutionData,
],
},
];
test.each(errorTests)('$description', ({ input }) => {
expect(() => normalizeItems(input)).toThrow(new ApplicationError('Inconsistent item format'));
Expand Down
Loading

0 comments on commit e469cfb

Please sign in to comment.