1
0
Fork 0
mirror of synced 2024-09-27 06:42:03 +12:00
budibase/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts

68 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-09-15 20:33:36 +12:00
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
import { inputProcessing } from ".."
import { generator, structures } from "@budibase/backend-core/tests"
import { FieldType, FieldTypeSubtypes, Table } from "@budibase/types"
import * as bbReferenceProcessor from "../bbReferenceProcessor"
const config = new TestConfiguration()
jest.mock("../bbReferenceProcessor", (): typeof bbReferenceProcessor => ({
processOutputBBReferences: jest.fn(),
}))
describe("rowProcessor - inputProcessing", () => {
beforeAll(async () => {
await config.init()
})
it("populate user BB references", async () => {
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: true,
type: "string",
},
},
},
}
const newRow = {
name: "Jack",
user: "123",
}
const user = structures.users.user()
;(
bbReferenceProcessor.processOutputBBReferences as jest.Mock
).mockResolvedValue(user)
const { row } = await inputProcessing(userId, table, newRow)
expect(bbReferenceProcessor.processOutputBBReferences).toBeCalledTimes(1)
expect(bbReferenceProcessor.processOutputBBReferences).toBeCalledWith(
"123",
"user"
)
expect(row).toEqual({ ...newRow, user })
})
})