Add test for string imports into array fields

This commit is contained in:
Andrew Kingston 2025-03-27 14:59:36 +00:00
parent e0511f8b07
commit a4caad86d1
No known key found for this signature in database
1 changed files with 34 additions and 1 deletions

View File

@ -1,4 +1,9 @@
import { AIOperationEnum, AutoFieldSubType, FieldType } from "@budibase/types"
import {
AIOperationEnum,
AutoFieldSubType,
FieldType,
JsonFieldSubType,
} from "@budibase/types"
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
import { importToRows } from "../utils"
@ -152,5 +157,33 @@ describe("utils", () => {
])
})
})
it("coerces strings into arrays for array fields", async () => {
await config.doInContext(config.appId, async () => {
const table = await config.createTable({
name: "table",
type: "table",
schema: {
colours: {
name: "colours",
type: FieldType.ARRAY,
constraints: {
type: JsonFieldSubType.ARRAY,
inclusion: ["red"],
},
},
},
})
const data = [{ colours: "red" }]
const result = await importToRows(data, table, config.user?._id)
expect(result).toEqual([
expect.objectContaining({
colours: ["red"],
}),
])
})
})
})
})