Process output
This commit is contained in:
parent
bebe342b33
commit
385989eca4
|
@ -7,7 +7,10 @@ import { InternalTables } from "../../db/utils"
|
||||||
import { TYPE_TRANSFORM_MAP } from "./map"
|
import { TYPE_TRANSFORM_MAP } from "./map"
|
||||||
import { FieldSubtype, Row, RowAttachment, Table } from "@budibase/types"
|
import { FieldSubtype, Row, RowAttachment, Table } from "@budibase/types"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { processInputBBReferences } from "./bbReferenceProcessor"
|
import {
|
||||||
|
processInputBBReferences,
|
||||||
|
processOutputBBReferences,
|
||||||
|
} from "./bbReferenceProcessor"
|
||||||
export * from "./utils"
|
export * from "./utils"
|
||||||
|
|
||||||
type AutoColumnProcessingOpts = {
|
type AutoColumnProcessingOpts = {
|
||||||
|
@ -224,6 +227,16 @@ export async function outputProcessing<T extends Row[] | Row>(
|
||||||
attachment.url = objectStore.getAppFileUrl(attachment.key)
|
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) {
|
if (opts.squash) {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import * as backendCore from "@budibase/backend-core"
|
import * as backendCore from "@budibase/backend-core"
|
||||||
import { FieldSubtype, User } from "@budibase/types"
|
import { FieldSubtype, User } from "@budibase/types"
|
||||||
import { processInputBBReferences } from "../bbReferenceProcessor"
|
import {
|
||||||
|
processInputBBReferences,
|
||||||
|
processOutputBBReferences,
|
||||||
|
} from "../bbReferenceProcessor"
|
||||||
import { generator, structures } from "@budibase/backend-core/tests"
|
import { generator, structures } from "@budibase/backend-core/tests"
|
||||||
import { InvalidBBRefError } from "../errors"
|
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)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue