From 68a3e030c2df46f81975ea81af9c3919bb6de0f6 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 7 Nov 2023 18:34:51 +0000 Subject: [PATCH] Adding test case to check that relationships can be used in external table formulas. --- .../server/src/api/routes/tests/row.spec.ts | 47 +++++++++++++++++++ .../server/src/tests/utilities/api/row.ts | 3 +- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 48f7ab4f09..97b06f33c8 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -10,6 +10,7 @@ import { FieldSchema, FieldType, FieldTypeSubtypes, + FormulaTypes, INTERNAL_TABLE_SOURCE_ID, MonthlyQuotaName, PermissionLevel, @@ -1998,4 +1999,50 @@ describe.each([ }) }) }) + + describe("Formula fields", () => { + let relationshipTable: Table, tableId: string, relatedRow: Row + + beforeAll(async () => { + const otherTableId = config.table!._id! + const cfg = generateTableConfig() + relationshipTable = await config.createLinkedTable( + RelationshipType.ONE_TO_MANY, + ["links"], + { + ...cfg, + schema: { + ...cfg.schema, + formula: { + name: "formula", + type: FieldType.FORMULA, + formula: "{{ links.0.name }}", + formulaType: FormulaTypes.DYNAMIC, + }, + }, + } + ) + + tableId = relationshipTable._id! + + relatedRow = await config.api.row.save(otherTableId, { + name: generator.word(), + description: generator.paragraph(), + }) + await config.api.row.save(tableId, { + name: generator.word(), + description: generator.paragraph(), + tableId, + links: [relatedRow._id], + }) + }) + + it("should be able to search for rows containing formulas", async () => { + const { rows } = await config.api.row.search(tableId) + expect(rows.length).toBe(1) + expect(rows[0].links.length).toBe(1) + const row = rows[0] + expect(row.formula).toBe(relatedRow.name) + }) + }) }) diff --git a/packages/server/src/tests/utilities/api/row.ts b/packages/server/src/tests/utilities/api/row.ts index 20b1d6f9ee..3d4cf6c82c 100644 --- a/packages/server/src/tests/utilities/api/row.ts +++ b/packages/server/src/tests/utilities/api/row.ts @@ -6,6 +6,7 @@ import { ExportRowsRequest, BulkImportRequest, BulkImportResponse, + SearchRowResponse, } from "@budibase/types" import TestConfiguration from "../TestConfiguration" import { TestAPI } from "./base" @@ -154,7 +155,7 @@ export class RowAPI extends TestAPI { search = async ( sourceId: string, { expectStatus } = { expectStatus: 200 } - ): Promise => { + ): Promise => { const request = this.request .post(`/api/${sourceId}/search`) .set(this.config.defaultHeaders())