From 9510c37b7a344490a0113390d27fefdce471b3bc Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 15 Sep 2023 13:04:45 +0200 Subject: [PATCH] Handle bb ref only if there is a value --- .../src/utilities/rowProcessor/index.ts | 2 +- .../tests/inputProcessing.spec.ts | 46 ++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index a69bebd0a2..e30eecf829 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -168,7 +168,7 @@ export async function inputProcessing( } } - if (field.type === FieldTypes.BB_REFERENCE) { + if (field.type === FieldTypes.BB_REFERENCE && value) { clonedRow[key] = await processInputBBReferences( value, field.subtype as FieldSubtype diff --git a/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts b/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts index e291b62663..65630da2b9 100644 --- a/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts @@ -62,7 +62,7 @@ describe("rowProcessor - inputProcessing", () => { expect(row).toEqual({ ...newRow, user }) }) - it("it does not processe BB references if on the schema but it is not populated", async () => { + it("it does not process BB references if on the schema but it is not populated", async () => { const userId = generator.guid() const table: Table = { @@ -100,7 +100,49 @@ describe("rowProcessor - inputProcessing", () => { expect(row).toEqual({ ...newRow, user: undefined }) }) - it("it does not processe BB references if not in the schema", async () => { + it.each([undefined, null, ""])( + "it does not process BB references the field is $%", + async userValue => { + const userId = generator.guid() + + const table: Table = { + _id: generator.guid(), + name: "TestTable", + type: "table", + schema: { + name: { + type: FieldType.STRING, + name: "name", + constraints: { + presence: true, + type: "string", + }, + }, + user: { + type: FieldType.BB_REFERENCE, + subtype: FieldTypeSubtypes.BB_REFERENCE.USER, + name: "user", + constraints: { + presence: false, + type: "string", + }, + }, + }, + } + + const newRow = { + name: "Jack", + user: userValue, + } + + const { row } = await inputProcessing(userId, table, newRow) + + expect(bbReferenceProcessor.processInputBBReferences).not.toBeCalled() + expect(row).toEqual(newRow) + } + ) + + it("it does not process BB references if not in the schema", async () => { const userId = generator.guid() const table: Table = {