From 96bddbb545b8ddc1602e20e981d2999f9b5d46a0 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 18 Dec 2024 15:53:09 +0100 Subject: [PATCH] More relationship tests --- .../row/utils/tests/sqlUtils.spec.ts | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/packages/server/src/api/controllers/row/utils/tests/sqlUtils.spec.ts b/packages/server/src/api/controllers/row/utils/tests/sqlUtils.spec.ts index 5a1b8ae49e..767a325c7a 100644 --- a/packages/server/src/api/controllers/row/utils/tests/sqlUtils.spec.ts +++ b/packages/server/src/api/controllers/row/utils/tests/sqlUtils.spec.ts @@ -152,6 +152,23 @@ describe("buildSqlFieldList", () => { type: FieldType.STRING, visible: false, }, + formula: { + name: "formula", + type: FieldType.FORMULA, + formula: "any", + }, + ai: { + name: "ai", + type: FieldType.AI, + operation: AIOperationEnum.PROMPT, + }, + link: { + name: "link", + type: FieldType.LINK, + relationshipType: RelationshipType.ONE_TO_MANY, + fieldName: "link", + tableId: "otherTableId", + }, }, } @@ -173,4 +190,68 @@ describe("buildSqlFieldList", () => { "linkedTable.hidden", ]) }) + + it("never includes non-sql columns from relationships", async () => { + const table = cloneDeep(basicTable) + table.schema.link = { + name: "link", + type: FieldType.LINK, + relationshipType: RelationshipType.ONE_TO_MANY, + fieldName: "link", + tableId: sql.utils.buildExternalTableId("ds_id", "otherTableId"), + } + table.schema.formula = { + name: "formula", + type: FieldType.FORMULA, + formula: "any", + } + + const otherTable: Table = { + ...cloneDeep(basicTable), + name: "linkedTable", + schema: { + id: { + name: "id", + type: FieldType.NUMBER, + }, + hidden: { + name: "other", + type: FieldType.STRING, + visible: false, + }, + formula: { + name: "formula", + type: FieldType.FORMULA, + formula: "any", + }, + ai: { + name: "ai", + type: FieldType.AI, + operation: AIOperationEnum.PROMPT, + }, + link: { + name: "link", + type: FieldType.LINK, + relationshipType: RelationshipType.ONE_TO_MANY, + fieldName: "link", + tableId: "otherTableId", + }, + }, + } + + const allTables: Record = { + otherTableId: otherTable, + } + + const result = await buildSqlFieldList(table, allTables, { + relationships: true, + }) + expect(result).toEqual([ + "table.name", + "table.description", + "table.amount", + "linkedTable.id", + "linkedTable.hidden", + ]) + }) })