Fix tests
This commit is contained in:
parent
d91292f532
commit
23d6c0dc3a
|
@ -14,6 +14,7 @@ import { cloneDeep } from "lodash/fp"
|
||||||
import {
|
import {
|
||||||
processInputBBReference,
|
processInputBBReference,
|
||||||
processInputBBReferences,
|
processInputBBReferences,
|
||||||
|
processOutputBBReference,
|
||||||
processOutputBBReferences,
|
processOutputBBReferences,
|
||||||
} from "./bbReferenceProcessor"
|
} from "./bbReferenceProcessor"
|
||||||
import { isExternalTableID } from "../../integrations/utils"
|
import { isExternalTableID } from "../../integrations/utils"
|
||||||
|
@ -258,7 +259,7 @@ export async function outputProcessing<T extends Row[] | Row>(
|
||||||
column.type == FieldType.BB_REFERENCE_SINGLE
|
column.type == FieldType.BB_REFERENCE_SINGLE
|
||||||
) {
|
) {
|
||||||
for (let row of enriched) {
|
for (let row of enriched) {
|
||||||
row[property] = await processOutputBBReferences(
|
row[property] = await processOutputBBReference(
|
||||||
row[property],
|
row[property],
|
||||||
column.subtype
|
column.subtype
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,7 +10,9 @@ import {
|
||||||
import * as bbReferenceProcessor from "../bbReferenceProcessor"
|
import * as bbReferenceProcessor from "../bbReferenceProcessor"
|
||||||
|
|
||||||
jest.mock("../bbReferenceProcessor", (): typeof bbReferenceProcessor => ({
|
jest.mock("../bbReferenceProcessor", (): typeof bbReferenceProcessor => ({
|
||||||
|
processInputBBReference: jest.fn(),
|
||||||
processInputBBReferences: jest.fn(),
|
processInputBBReferences: jest.fn(),
|
||||||
|
processOutputBBReference: jest.fn(),
|
||||||
processOutputBBReferences: jest.fn(),
|
processOutputBBReferences: jest.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -19,7 +21,64 @@ describe("rowProcessor - inputProcessing", () => {
|
||||||
jest.resetAllMocks()
|
jest.resetAllMocks()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("processes BB references if on the schema and it's populated", async () => {
|
const processInputBBReferenceMock =
|
||||||
|
bbReferenceProcessor.processInputBBReference as jest.Mock
|
||||||
|
const processInputBBReferencesMock =
|
||||||
|
bbReferenceProcessor.processInputBBReferences as jest.Mock
|
||||||
|
|
||||||
|
it("processes single BB references if on the schema and it's populated", async () => {
|
||||||
|
const userId = generator.guid()
|
||||||
|
|
||||||
|
const table: Table = {
|
||||||
|
_id: generator.guid(),
|
||||||
|
name: "TestTable",
|
||||||
|
type: "table",
|
||||||
|
sourceId: INTERNAL_TABLE_SOURCE_ID,
|
||||||
|
sourceType: TableSourceType.INTERNAL,
|
||||||
|
schema: {
|
||||||
|
name: {
|
||||||
|
type: FieldType.STRING,
|
||||||
|
name: "name",
|
||||||
|
constraints: {
|
||||||
|
presence: true,
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
type: FieldType.BB_REFERENCE_SINGLE,
|
||||||
|
subtype: BBReferenceFieldSubType.USER,
|
||||||
|
name: "user",
|
||||||
|
constraints: {
|
||||||
|
presence: true,
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const newRow = {
|
||||||
|
name: "Jack",
|
||||||
|
user: "123",
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = structures.users.user()
|
||||||
|
|
||||||
|
processInputBBReferenceMock.mockResolvedValue(user)
|
||||||
|
|
||||||
|
const { row } = await inputProcessing(userId, table, newRow)
|
||||||
|
|
||||||
|
expect(bbReferenceProcessor.processInputBBReference).toHaveBeenCalledTimes(
|
||||||
|
1
|
||||||
|
)
|
||||||
|
expect(bbReferenceProcessor.processInputBBReference).toHaveBeenCalledWith(
|
||||||
|
"123",
|
||||||
|
"user"
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(row).toEqual({ ...newRow, user })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("processes multiple BB references if on the schema and it's populated", async () => {
|
||||||
const userId = generator.guid()
|
const userId = generator.guid()
|
||||||
|
|
||||||
const table: Table = {
|
const table: Table = {
|
||||||
|
@ -56,9 +115,7 @@ describe("rowProcessor - inputProcessing", () => {
|
||||||
|
|
||||||
const user = structures.users.user()
|
const user = structures.users.user()
|
||||||
|
|
||||||
;(
|
processInputBBReferencesMock.mockResolvedValue(user)
|
||||||
bbReferenceProcessor.processInputBBReferences as jest.Mock
|
|
||||||
).mockResolvedValue(user)
|
|
||||||
|
|
||||||
const { row } = await inputProcessing(userId, table, newRow)
|
const { row } = await inputProcessing(userId, table, newRow)
|
||||||
|
|
||||||
|
@ -67,7 +124,6 @@ describe("rowProcessor - inputProcessing", () => {
|
||||||
)
|
)
|
||||||
expect(bbReferenceProcessor.processInputBBReferences).toHaveBeenCalledWith(
|
expect(bbReferenceProcessor.processInputBBReferences).toHaveBeenCalledWith(
|
||||||
"123",
|
"123",
|
||||||
"bb_reference",
|
|
||||||
"user"
|
"user"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,9 @@ import { generator, structures } from "@budibase/backend-core/tests"
|
||||||
import * as bbReferenceProcessor from "../bbReferenceProcessor"
|
import * as bbReferenceProcessor from "../bbReferenceProcessor"
|
||||||
|
|
||||||
jest.mock("../bbReferenceProcessor", (): typeof bbReferenceProcessor => ({
|
jest.mock("../bbReferenceProcessor", (): typeof bbReferenceProcessor => ({
|
||||||
|
processInputBBReference: jest.fn(),
|
||||||
processInputBBReferences: jest.fn(),
|
processInputBBReferences: jest.fn(),
|
||||||
|
processOutputBBReference: jest.fn(),
|
||||||
processOutputBBReferences: jest.fn(),
|
processOutputBBReferences: jest.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -20,10 +22,12 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
jest.resetAllMocks()
|
jest.resetAllMocks()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const processOutputBBReferenceMock =
|
||||||
|
bbReferenceProcessor.processOutputBBReference as jest.Mock
|
||||||
const processOutputBBReferencesMock =
|
const processOutputBBReferencesMock =
|
||||||
bbReferenceProcessor.processOutputBBReferences as jest.Mock
|
bbReferenceProcessor.processOutputBBReferences as jest.Mock
|
||||||
|
|
||||||
it("fetches bb user references given a populated field", async () => {
|
it("fetches single user references given a populated field", async () => {
|
||||||
const table: Table = {
|
const table: Table = {
|
||||||
_id: generator.guid(),
|
_id: generator.guid(),
|
||||||
name: "TestTable",
|
name: "TestTable",
|
||||||
|
@ -40,7 +44,7 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
type: FieldType.BB_REFERENCE,
|
type: FieldType.BB_REFERENCE_SINGLE,
|
||||||
subtype: BBReferenceFieldSubType.USER,
|
subtype: BBReferenceFieldSubType.USER,
|
||||||
name: "user",
|
name: "user",
|
||||||
constraints: {
|
constraints: {
|
||||||
|
@ -57,18 +61,66 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = structures.users.user()
|
const user = structures.users.user()
|
||||||
processOutputBBReferencesMock.mockResolvedValue(user)
|
processOutputBBReferenceMock.mockResolvedValue(user)
|
||||||
|
|
||||||
const result = await outputProcessing(table, row, { squash: false })
|
const result = await outputProcessing(table, row, { squash: false })
|
||||||
|
|
||||||
expect(result).toEqual({ name: "Jack", user })
|
expect(result).toEqual({ name: "Jack", user })
|
||||||
|
|
||||||
|
expect(bbReferenceProcessor.processOutputBBReference).toHaveBeenCalledTimes(
|
||||||
|
1
|
||||||
|
)
|
||||||
|
expect(bbReferenceProcessor.processOutputBBReference).toHaveBeenCalledWith(
|
||||||
|
"123",
|
||||||
|
BBReferenceFieldSubType.USER
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("fetches users references given a populated field", async () => {
|
||||||
|
const table: Table = {
|
||||||
|
_id: generator.guid(),
|
||||||
|
name: "TestTable",
|
||||||
|
type: "table",
|
||||||
|
sourceId: INTERNAL_TABLE_SOURCE_ID,
|
||||||
|
sourceType: TableSourceType.INTERNAL,
|
||||||
|
schema: {
|
||||||
|
name: {
|
||||||
|
type: FieldType.STRING,
|
||||||
|
name: "name",
|
||||||
|
constraints: {
|
||||||
|
presence: true,
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
users: {
|
||||||
|
type: FieldType.BB_REFERENCE,
|
||||||
|
subtype: BBReferenceFieldSubType.USER,
|
||||||
|
name: "users",
|
||||||
|
constraints: {
|
||||||
|
presence: false,
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const row = {
|
||||||
|
name: "Jack",
|
||||||
|
users: "123",
|
||||||
|
}
|
||||||
|
|
||||||
|
const users = [structures.users.user()]
|
||||||
|
processOutputBBReferencesMock.mockResolvedValue(users)
|
||||||
|
|
||||||
|
const result = await outputProcessing(table, row, { squash: false })
|
||||||
|
|
||||||
|
expect(result).toEqual({ name: "Jack", users })
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
bbReferenceProcessor.processOutputBBReferences
|
bbReferenceProcessor.processOutputBBReferences
|
||||||
).toHaveBeenCalledTimes(1)
|
).toHaveBeenCalledTimes(1)
|
||||||
expect(bbReferenceProcessor.processOutputBBReferences).toHaveBeenCalledWith(
|
expect(bbReferenceProcessor.processOutputBBReferences).toHaveBeenCalledWith(
|
||||||
"123",
|
"123",
|
||||||
FieldType.BB_REFERENCE,
|
|
||||||
BBReferenceFieldSubType.USER
|
BBReferenceFieldSubType.USER
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue