Process bb ref on input processing
This commit is contained in:
parent
9860023c9e
commit
a1bb33bb4a
|
@ -0,0 +1,6 @@
|
|||
import { FieldSubtype } from "@budibase/types"
|
||||
|
||||
export async function processOutputBBReferences(
|
||||
value: string,
|
||||
subtype: FieldSubtype
|
||||
) {}
|
|
@ -5,8 +5,9 @@ import { ObjectStoreBuckets } from "../../constants"
|
|||
import { context, db as dbCore, objectStore } from "@budibase/backend-core"
|
||||
import { InternalTables } from "../../db/utils"
|
||||
import { TYPE_TRANSFORM_MAP } from "./map"
|
||||
import { Row, RowAttachment, Table } from "@budibase/types"
|
||||
import { FieldSubtype, Row, RowAttachment, Table } from "@budibase/types"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
import { processOutputBBReferences } from "./bbReferenceProcessor"
|
||||
export * from "./utils"
|
||||
|
||||
type AutoColumnProcessingOpts = {
|
||||
|
@ -166,6 +167,13 @@ export async function inputProcessing(
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (field.type === FieldTypes.BB_REFERENCE) {
|
||||
clonedRow[key] = await processOutputBBReferences(
|
||||
value,
|
||||
field.subtype as FieldSubtype
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (!clonedRow._id || !clonedRow._rev) {
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
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 })
|
||||
})
|
||||
})
|
|
@ -34,3 +34,13 @@ export interface Row extends Document {
|
|||
_viewId?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export enum FieldSubtype {
|
||||
USER = "user",
|
||||
}
|
||||
|
||||
export const FieldTypeSubtypes = {
|
||||
BB_REFERENCE: {
|
||||
USER: FieldSubtype.USER,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue