From 2365a6ecd5c5b7772baa189e5c4dd1e3370ff8f8 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 2 Sep 2024 17:32:21 +0200 Subject: [PATCH] Add renaming column tests --- .../src/api/routes/tests/viewV2.spec.ts | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index 356f01dee02..5ff8fed0bdc 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -18,6 +18,7 @@ import { ViewV2, SearchResponse, BasicOperator, + RelationshipType, } from "@budibase/types" import { generator, mocks } from "@budibase/backend-core/tests" import { DatabaseName, getDatasource } from "../../../integrations/tests/utils" @@ -1176,6 +1177,87 @@ describe.each([ } ) }) + + it("updating a column will update link columns configuration", async () => { + let auxTable = await config.api.table.save( + saveTableRequest({ + primaryDisplay: "name", + schema: { + name: { + name: "name", + type: FieldType.STRING, + constraints: { presence: true }, + }, + age: { + name: "age", + type: FieldType.NUMBER, + constraints: { presence: true }, + }, + }, + }) + ) + + const table = await config.api.table.save( + saveTableRequest({ + schema: { + aux: { + name: "aux", + relationshipType: RelationshipType.ONE_TO_MANY, + type: FieldType.LINK, + tableId: auxTable._id!, + fieldName: "fk_aux", + constraints: { presence: true }, + }, + }, + }) + ) + + const view = await config.api.viewV2.create({ + name: "view a", + tableId: table._id!, + schema: { + aux: { + visible: true, + columns: { + name: { visible: true, readonly: true }, + age: { visible: true, readonly: true }, + }, + }, + }, + }) + + // Refetch autTable + auxTable = await config.api.table.get(auxTable._id!) + await config.api.table.save({ + ...auxTable, + schema: { + ...auxTable.schema, + // @ts-ignore deleting age to force the rename + age: undefined, + dob: { + name: "dob", + type: FieldType.NUMBER, + constraints: { presence: true }, + }, + }, + _rename: { old: "age", updated: "dob" }, + }) + + const updatedView = await config.api.viewV2.get(view.id) + expect(updatedView).toEqual( + expect.objectContaining({ + schema: expect.objectContaining({ + aux: expect.objectContaining({ + columns: { + id: { visible: false, readonly: false }, + name: { visible: true, readonly: true }, + dob: { visible: true, readonly: true }, + }, + }), + }), + }) + ) + }) }) }) })