From 80dfef9c42f411ab02ff0c47ea91b00234f81bad Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 4 Apr 2024 21:07:44 +0200 Subject: [PATCH] Test single attachment on outputProcessing --- .../tests/outputProcessing.spec.ts | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts b/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts index 93404e0469..74d55aff36 100644 --- a/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts @@ -73,7 +73,7 @@ describe("rowProcessor - outputProcessing", () => { ) }) - it("should handle attachments correctly", async () => { + it("should handle attachment list correctly", async () => { const table: Table = { _id: generator.guid(), name: "TestTable", @@ -116,6 +116,47 @@ describe("rowProcessor - outputProcessing", () => { expect(output3.attach[0].url).toBe("aaaa") }) + it("should handle single attachment correctly", async () => { + const table: Table = { + _id: generator.guid(), + name: "TestTable", + type: "table", + sourceId: INTERNAL_TABLE_SOURCE_ID, + sourceType: TableSourceType.INTERNAL, + schema: { + attach: { + type: FieldType.ATTACHMENT_SINGLE, + name: "attach", + constraints: {}, + }, + }, + } + + const row: { attach: RowAttachment } = { + attach: { + size: 10, + name: "test", + extension: "jpg", + key: "test.jpg", + }, + } + + const output = await outputProcessing(table, row, { squash: false }) + expect(output.attach.url).toBe( + "/files/signed/prod-budi-app-assets/test.jpg" + ) + + row.attach.url = "" + const output2 = await outputProcessing(table, row, { squash: false }) + expect(output2.attach.url).toBe( + "/files/signed/prod-budi-app-assets/test.jpg" + ) + + row.attach.url = "aaaa" + const output3 = await outputProcessing(table, row, { squash: false }) + expect(output3.attach.url).toBe("aaaa") + }) + it("process output even when the field is not empty", async () => { const table: Table = { _id: generator.guid(),