fix(Postgres Node): Convert js arrays to postgres type, if column type is ARRAY (#9160)

This commit is contained in:
Michael Kret
2024-04-18 12:58:04 +03:00
committed by GitHub
parent d756609826
commit 08e35027f1
8 changed files with 160 additions and 7 deletions

View File

@@ -10,7 +10,9 @@ import {
prepareItem,
replaceEmptyStringsByNulls,
wrapData,
convertArraysToPostgresFormat,
} from '../../v2/helpers/utils';
import type { ColumnInfo } from '../../v2/helpers/interfaces';
const node: INode = {
id: '1',
@@ -373,3 +375,78 @@ describe('Test PostgresV2, checkItemAgainstSchema', () => {
}
});
});
describe('Test PostgresV2, convertArraysToPostgresFormat', () => {
it('should convert js arrays to postgres format', () => {
const item = {
jsonb_array: [
{
key: 'value44',
},
],
json_array: [
{
key: 'value54',
},
],
int_array: [1, 2, 5],
text_array: ['one', 't"w"o'],
bool_array: [true, false],
};
const schema: ColumnInfo[] = [
{
column_name: 'id',
data_type: 'integer',
is_nullable: 'NO',
udt_name: 'int4',
column_default: "nextval('test_data_array_id_seq'::regclass)",
},
{
column_name: 'jsonb_array',
data_type: 'ARRAY',
is_nullable: 'YES',
udt_name: '_jsonb',
column_default: null,
},
{
column_name: 'json_array',
data_type: 'ARRAY',
is_nullable: 'YES',
udt_name: '_json',
column_default: null,
},
{
column_name: 'int_array',
data_type: 'ARRAY',
is_nullable: 'YES',
udt_name: '_int4',
column_default: null,
},
{
column_name: 'bool_array',
data_type: 'ARRAY',
is_nullable: 'YES',
udt_name: '_bool',
column_default: null,
},
{
column_name: 'text_array',
data_type: 'ARRAY',
is_nullable: 'YES',
udt_name: '_text',
column_default: null,
},
];
convertArraysToPostgresFormat(item, schema, node, 0);
expect(item).toEqual({
jsonb_array: '{"{\\"key\\":\\"value44\\"}"}',
json_array: '{"{\\"key\\":\\"value54\\"}"}',
int_array: '{1,2,5}',
text_array: '{"one","t\\"w\\"o"}',
bool_array: '{"true","false"}',
});
});
});