From 272bba188955e90e365de5c67bb7bee1edb51240 Mon Sep 17 00:00:00 2001 From: Charlie Kolb Date: Tue, 28 Oct 2025 11:33:49 +0100 Subject: [PATCH] add object test cases --- .../data-table.service.integration.test.ts | 40 +++++++++++++++++++ .../modules/data-table/data-table.service.ts | 3 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/modules/data-table/__tests__/data-table.service.integration.test.ts b/packages/cli/src/modules/data-table/__tests__/data-table.service.integration.test.ts index 28f5e42b97a..9ef9e4804f0 100644 --- a/packages/cli/src/modules/data-table/__tests__/data-table.service.integration.test.ts +++ b/packages/cli/src/modules/data-table/__tests__/data-table.service.integration.test.ts @@ -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), + }, + ]); + } + }); }); }); diff --git a/packages/cli/src/modules/data-table/data-table.service.ts b/packages/cli/src/modules/data-table/data-table.service.ts index 3180c822061..da24cf88654 100644 --- a/packages/cli/src/modules/data-table/data-table.service.ts +++ b/packages/cli/src/modules/data-table/data-table.service.ts @@ -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)