1
0
Fork 0
mirror of synced 2024-08-09 15:17:57 +12:00

Process output

This commit is contained in:
Adria Navarro 2023-09-15 13:31:56 +02:00
parent bebe342b33
commit 385989eca4
2 changed files with 58 additions and 2 deletions

View file

@ -7,7 +7,10 @@ import { InternalTables } from "../../db/utils"
import { TYPE_TRANSFORM_MAP } from "./map"
import { FieldSubtype, Row, RowAttachment, Table } from "@budibase/types"
import { cloneDeep } from "lodash/fp"
import { processInputBBReferences } from "./bbReferenceProcessor"
import {
processInputBBReferences,
processOutputBBReferences,
} from "./bbReferenceProcessor"
export * from "./utils"
type AutoColumnProcessingOpts = {
@ -224,6 +227,16 @@ export async function outputProcessing<T extends Row[] | Row>(
attachment.url = objectStore.getAppFileUrl(attachment.key)
})
}
} else if (column.type == FieldTypes.BB_REFERENCE) {
for (let row of enriched) {
if (!row[property]) {
continue
}
row[property] = await processOutputBBReferences(
row[property],
column.subtype as FieldSubtype
)
}
}
}
if (opts.squash) {

View file

@ -1,6 +1,9 @@
import * as backendCore from "@budibase/backend-core"
import { FieldSubtype, User } from "@budibase/types"
import { processInputBBReferences } from "../bbReferenceProcessor"
import {
processInputBBReferences,
processOutputBBReferences,
} from "../bbReferenceProcessor"
import { generator, structures } from "@budibase/backend-core/tests"
import { InvalidBBRefError } from "../errors"
@ -128,4 +131,44 @@ describe("bbReferenceProcessor", () => {
})
})
})
describe("processOutputBBReferences", () => {
describe("subtype user", () => {
it("fetches user given a valid string id", async () => {
const userId = generator.guid()
const userFromCache = structures.users.user()
mockedCacheGetUser.mockResolvedValueOnce(userFromCache)
const result = await processOutputBBReferences(
userId,
FieldSubtype.USER
)
expect(result).toEqual(userFromCache)
expect(mockedCacheGetUser).toBeCalledTimes(1)
expect(mockedCacheGetUser).toBeCalledWith(userId)
})
it("fetches user given a valid string id csv", async () => {
const userId1 = generator.guid()
const userId2 = generator.guid()
const userFromCache1 = structures.users.user({ _id: userId1 })
const userFromCache2 = structures.users.user({ _id: userId2 })
mockedCacheGetUser.mockResolvedValueOnce(userFromCache1)
mockedCacheGetUser.mockResolvedValueOnce(userFromCache2)
const result = await processOutputBBReferences(
[userId1, userId2].join(","),
FieldSubtype.USER
)
expect(result).toEqual([userFromCache1, userFromCache2])
expect(mockedCacheGetUser).toBeCalledTimes(2)
expect(mockedCacheGetUser).toBeCalledWith(userId1)
expect(mockedCacheGetUser).toBeCalledWith(userId2)
})
})
})
})