Fix tests.
This commit is contained in:
parent
f9f528e880
commit
bced81d241
|
@ -4,6 +4,7 @@ import {
|
||||||
cache,
|
cache,
|
||||||
context,
|
context,
|
||||||
db,
|
db,
|
||||||
|
features,
|
||||||
HTTPError,
|
HTTPError,
|
||||||
objectStore,
|
objectStore,
|
||||||
utils,
|
utils,
|
||||||
|
@ -350,7 +351,7 @@ export async function outputProcessing<T extends Row[] | Row>(
|
||||||
}
|
}
|
||||||
// remove null properties to match internal API
|
// remove null properties to match internal API
|
||||||
const isExternal = isExternalTableID(table._id!)
|
const isExternal = isExternalTableID(table._id!)
|
||||||
if (isExternal || db.isSqsEnabledForTenant()) {
|
if (isExternal || (await features.flags.isEnabled("SQS"))) {
|
||||||
for (const row of enriched) {
|
for (const row of enriched) {
|
||||||
for (const key of Object.keys(row)) {
|
for (const key of Object.keys(row)) {
|
||||||
if (row[key] === null) {
|
if (row[key] === null) {
|
||||||
|
|
|
@ -8,15 +8,9 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { outputProcessing } from ".."
|
import { outputProcessing } from ".."
|
||||||
import { generator, structures } from "@budibase/backend-core/tests"
|
import { generator, structures } from "@budibase/backend-core/tests"
|
||||||
|
import { setEnv as setCoreEnv } from "@budibase/backend-core"
|
||||||
import * as bbReferenceProcessor from "../bbReferenceProcessor"
|
import * as bbReferenceProcessor from "../bbReferenceProcessor"
|
||||||
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
jest.mock("@budibase/backend-core", () => ({
|
|
||||||
...jest.requireActual("@budibase/backend-core"),
|
|
||||||
db: {
|
|
||||||
...jest.requireActual("@budibase/backend-core").db,
|
|
||||||
isSqsEnabledForTenant: () => true,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
jest.mock("../bbReferenceProcessor", (): typeof bbReferenceProcessor => ({
|
jest.mock("../bbReferenceProcessor", (): typeof bbReferenceProcessor => ({
|
||||||
processInputBBReference: jest.fn(),
|
processInputBBReference: jest.fn(),
|
||||||
|
@ -26,8 +20,24 @@ jest.mock("../bbReferenceProcessor", (): typeof bbReferenceProcessor => ({
|
||||||
}))
|
}))
|
||||||
|
|
||||||
describe("rowProcessor - outputProcessing", () => {
|
describe("rowProcessor - outputProcessing", () => {
|
||||||
|
const config = new TestConfiguration()
|
||||||
|
let cleanupEnv: () => void = () => {}
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await config.init()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
config.end()
|
||||||
|
})
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks()
|
jest.resetAllMocks()
|
||||||
|
cleanupEnv = setCoreEnv({ TENANT_FEATURE_FLAGS: "*SQS" })
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cleanupEnv()
|
||||||
})
|
})
|
||||||
|
|
||||||
const processOutputBBReferenceMock =
|
const processOutputBBReferenceMock =
|
||||||
|
@ -36,6 +46,7 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
bbReferenceProcessor.processOutputBBReferences as jest.Mock
|
bbReferenceProcessor.processOutputBBReferences as jest.Mock
|
||||||
|
|
||||||
it("fetches single user references given a populated field", async () => {
|
it("fetches single user references given a populated field", async () => {
|
||||||
|
await config.doInContext(config.getAppId(), async () => {
|
||||||
const table: Table = {
|
const table: Table = {
|
||||||
_id: generator.guid(),
|
_id: generator.guid(),
|
||||||
name: "TestTable",
|
name: "TestTable",
|
||||||
|
@ -75,16 +86,17 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
|
|
||||||
expect(result).toEqual({ name: "Jack", user })
|
expect(result).toEqual({ name: "Jack", user })
|
||||||
|
|
||||||
expect(bbReferenceProcessor.processOutputBBReference).toHaveBeenCalledTimes(
|
expect(
|
||||||
1
|
bbReferenceProcessor.processOutputBBReference
|
||||||
)
|
).toHaveBeenCalledTimes(1)
|
||||||
expect(bbReferenceProcessor.processOutputBBReference).toHaveBeenCalledWith(
|
expect(
|
||||||
"123",
|
bbReferenceProcessor.processOutputBBReference
|
||||||
BBReferenceFieldSubType.USER
|
).toHaveBeenCalledWith("123", BBReferenceFieldSubType.USER)
|
||||||
)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("fetches users references given a populated field", async () => {
|
it("fetches users references given a populated field", async () => {
|
||||||
|
await config.doInContext(config.getAppId(), async () => {
|
||||||
const table: Table = {
|
const table: Table = {
|
||||||
_id: generator.guid(),
|
_id: generator.guid(),
|
||||||
name: "TestTable",
|
name: "TestTable",
|
||||||
|
@ -127,13 +139,14 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
expect(
|
expect(
|
||||||
bbReferenceProcessor.processOutputBBReferences
|
bbReferenceProcessor.processOutputBBReferences
|
||||||
).toHaveBeenCalledTimes(1)
|
).toHaveBeenCalledTimes(1)
|
||||||
expect(bbReferenceProcessor.processOutputBBReferences).toHaveBeenCalledWith(
|
expect(
|
||||||
"123",
|
bbReferenceProcessor.processOutputBBReferences
|
||||||
BBReferenceFieldSubType.USER
|
).toHaveBeenCalledWith("123", BBReferenceFieldSubType.USER)
|
||||||
)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle attachment list correctly", async () => {
|
it("should handle attachment list correctly", async () => {
|
||||||
|
await config.doInContext(config.getAppId(), async () => {
|
||||||
const table: Table = {
|
const table: Table = {
|
||||||
_id: generator.guid(),
|
_id: generator.guid(),
|
||||||
name: "TestTable",
|
name: "TestTable",
|
||||||
|
@ -175,8 +188,10 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
const output3 = await outputProcessing(table, row, { squash: false })
|
const output3 = await outputProcessing(table, row, { squash: false })
|
||||||
expect(output3.attach[0].url).toBe("aaaa")
|
expect(output3.attach[0].url).toBe("aaaa")
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it("should handle single attachment correctly", async () => {
|
it("should handle single attachment correctly", async () => {
|
||||||
|
await config.doInContext(config.getAppId(), async () => {
|
||||||
const table: Table = {
|
const table: Table = {
|
||||||
_id: generator.guid(),
|
_id: generator.guid(),
|
||||||
name: "TestTable",
|
name: "TestTable",
|
||||||
|
@ -216,8 +231,10 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
const output3 = await outputProcessing(table, row, { squash: false })
|
const output3 = await outputProcessing(table, row, { squash: false })
|
||||||
expect(output3.attach.url).toBe("aaaa")
|
expect(output3.attach.url).toBe("aaaa")
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it("process output even when the field is not empty", async () => {
|
it("process output even when the field is not empty", async () => {
|
||||||
|
await config.doInContext(config.getAppId(), async () => {
|
||||||
const table: Table = {
|
const table: Table = {
|
||||||
_id: generator.guid(),
|
_id: generator.guid(),
|
||||||
name: "TestTable",
|
name: "TestTable",
|
||||||
|
@ -257,8 +274,10 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
bbReferenceProcessor.processOutputBBReferences
|
bbReferenceProcessor.processOutputBBReferences
|
||||||
).toHaveBeenCalledTimes(1)
|
).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it("does not fetch bb references when not in the schema", async () => {
|
it("does not fetch bb references when not in the schema", async () => {
|
||||||
|
await config.doInContext(config.getAppId(), async () => {
|
||||||
const table: Table = {
|
const table: Table = {
|
||||||
_id: generator.guid(),
|
_id: generator.guid(),
|
||||||
name: "TestTable",
|
name: "TestTable",
|
||||||
|
@ -299,3 +318,4 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
).not.toHaveBeenCalled()
|
).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue