add object test cases

This commit is contained in:
Charlie Kolb 2025-10-28 11:33:49 +01:00
parent 87ecaad9ca
commit 272bba1889
No known key found for this signature in database
2 changed files with 42 additions and 1 deletions

View File

@ -3568,6 +3568,9 @@ describe('dataTable', () => {
[{ key: 'value' }, 0, 'eq', true],
[true, 1, 'eq', true],
[false, 0, 'eq', true],
[{ a: 3 }, { a: 3 }, 'eq', true],
[{ a: 3 }, { a: 4 }, 'neq', true],
[{}, {}, 'eq', true],
])(
'inserts json with input %p, filter %p, operator %p, expectPresent %p',
async (input, filter, operator, expectPresent) => {
@ -3655,5 +3658,42 @@ describe('dataTable', () => {
]);
}
});
it('handles object comparison', async () => {
// ARRANGE
const { id: dataStoreId } = await dataTableService.createDataTable(project1.id, {
name: 'dataStore',
columns: [{ name: 'c1', type: 'json' }],
});
// ACT
const rows = [{ c1: { a: { b: 4 } } }];
await dataTableService.insertRows(dataStoreId, project1.id, rows, 'id');
// ASSERT
{
const { data } = await dataTableService.getManyRowsAndCount(dataStoreId, project1.id, {
filter: {
type: 'and',
filters: [
{
columnName: 'c1',
condition: 'eq',
value: { a: { b: 4 } },
path: '',
},
],
},
});
expect(data).toEqual([
{
c1: { a: { b: 4 } },
id: 1,
createdAt: expect.any(Date),
updatedAt: expect.any(Date),
},
]);
}
});
});
});

View File

@ -490,7 +490,8 @@ export class DataTableService {
const fieldType = columnTypeToFieldType[columnType];
if (!fieldType) return cell;
if (!validateJsonInput && columnType === 'json') return cell;
if (!validateJsonInput && columnType === 'json')
return typeof cell === 'object' ? JSON.stringify(cell) : cell;
const validationResult = validateFieldType(key, cell, fieldType, {
strict: false, // Allow type coercion (e.g., string numbers to numbers)