From b06074128fe666f6d6a507f2a1c2c6fd32e9d1cc Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 30 Oct 2024 11:27:49 +0000 Subject: [PATCH] unit test to cover --- .../api/controllers/table/tests/utils.spec.ts | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/table/tests/utils.spec.ts b/packages/server/src/api/controllers/table/tests/utils.spec.ts index 68b00d3268..0cac17dd06 100644 --- a/packages/server/src/api/controllers/table/tests/utils.spec.ts +++ b/packages/server/src/api/controllers/table/tests/utils.spec.ts @@ -1,4 +1,4 @@ -import { AutoFieldSubType, FieldType } from "@budibase/types" +import { AIOperationEnum, AutoFieldSubType, FieldType } from "@budibase/types" import TestConfiguration from "../../../../tests/utilities/TestConfiguration" import { importToRows } from "../utils" @@ -92,5 +92,65 @@ describe("utils", () => { expect(result).toHaveLength(3) }) }) + + it("Imports write as expected with AI columns", async () => { + await config.doInContext(config.appId, async () => { + const table = await config.createTable({ + name: "table", + type: "table", + schema: { + autoId: { + name: "autoId", + type: FieldType.NUMBER, + subtype: AutoFieldSubType.AUTO_ID, + autocolumn: true, + constraints: { + type: FieldType.NUMBER, + presence: true, + }, + }, + name: { + name: "name", + type: FieldType.STRING, + constraints: { + type: FieldType.STRING, + presence: true, + }, + }, + aicol: { + name: "aicol", + type: FieldType.AI, + operation: AIOperationEnum.PROMPT, + prompt: "Test prompt" + }, + }, + }) + + const data = [ + { name: "Alice", aicol: "test" }, + { name: "Bob", aicol: "test" }, + { name: "Claire", aicol: "test" } + ] + + const result = await importToRows(data, table, config.user?._id) + expect(result).toEqual([ + expect.objectContaining({ + autoId: 1, + name: "Alice", + aicol: "test", + }), + expect.objectContaining({ + autoId: 2, + name: "Bob", + aicol: "test", + }), + expect.objectContaining({ + autoId: 3, + name: "Claire", + aicol: "test", + }), + ]) + }) + }) }) })