mirror of
https://github.com/n8n-io/n8n.git
synced 2026-06-01 09:17:08 +02:00
add initial test cases
This commit is contained in:
parent
5cc5cac7ee
commit
20a8a74811
|
|
@ -1,9 +1,13 @@
|
|||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
import type { AddDataTableColumnDto, CreateDataTableColumnDto } from '@n8n/api-types';
|
||||
import type {
|
||||
AddDataTableColumnDto,
|
||||
CreateDataTableColumnDto,
|
||||
DataTableFilterConditionType,
|
||||
} from '@n8n/api-types';
|
||||
import { createTeamProject, testDb, testModules } from '@n8n/backend-test-utils';
|
||||
import type { Project } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
import type { DataTableRow } from 'n8n-workflow';
|
||||
import type { DataTableColumnJsType, DataTableRow } from 'n8n-workflow';
|
||||
|
||||
import { DataTableRowsRepository } from '../data-table-rows.repository';
|
||||
import { DataTableRepository } from '../data-table.repository';
|
||||
|
|
@ -3599,4 +3603,74 @@ describe('dataTable', () => {
|
|||
expect(dataTable2.id).toBe(dataTableId2);
|
||||
});
|
||||
});
|
||||
describe('json datatype', () => {
|
||||
it.each<[DataTableColumnJsType, DataTableColumnJsType, DataTableFilterConditionType, boolean]>([
|
||||
[3, 3, 'eq', true],
|
||||
[3, 3, 'neq', false],
|
||||
[3, '3', 'eq', true],
|
||||
[3, '3', 'neq', false],
|
||||
[null, null, 'eq', true],
|
||||
[null, null, 'neq', false],
|
||||
[11, 3, 'gt', true],
|
||||
[11, 3, 'lt', false],
|
||||
[11, '3', 'gt', false],
|
||||
[11, '3', 'lt', true],
|
||||
])(
|
||||
'inserts json with input %p, filter %p, operator %p, expectPresent %p',
|
||||
async (input, filter, operator, expectPresent) => {
|
||||
// ARRANGE
|
||||
|
||||
const { id: dataStoreId } = await dataTableService.createDataTable(project1.id, {
|
||||
name: 'dataStore',
|
||||
columns: [{ name: 'c1', type: 'json' }],
|
||||
});
|
||||
|
||||
// ACT
|
||||
const rows = [{ c1: { input } }];
|
||||
const result = await dataTableService.insertRows(dataStoreId, project1.id, rows, 'id');
|
||||
|
||||
// ASSERT
|
||||
expect(result).toEqual([{ id: 1 }]);
|
||||
{
|
||||
const { count, data } = await dataTableService.getManyRowsAndCount(
|
||||
dataStoreId,
|
||||
project1.id,
|
||||
{},
|
||||
);
|
||||
expect(count).toEqual(1);
|
||||
expect(data).toHaveLength(1);
|
||||
expect(data[0]).toMatchObject({
|
||||
c1: { input },
|
||||
});
|
||||
}
|
||||
{
|
||||
const { data } = await dataTableService.getManyRowsAndCount(dataStoreId, project1.id, {
|
||||
filter: {
|
||||
type: 'and',
|
||||
filters: [
|
||||
{
|
||||
columnName: 'c1',
|
||||
condition: operator,
|
||||
value: filter,
|
||||
path: 'input',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(data).toEqual(
|
||||
expectPresent
|
||||
? [
|
||||
{
|
||||
c1: { input },
|
||||
id: 1,
|
||||
createdAt: expect.any(Date),
|
||||
updatedAt: expect.any(Date),
|
||||
},
|
||||
]
|
||||
: [],
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user