Datasource usage on tests
This commit is contained in:
parent
8c99ac3f9b
commit
0cec026932
|
@ -73,7 +73,7 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
...response,
|
...response,
|
||||||
row,
|
row: await outputProcessing(table, row),
|
||||||
table,
|
table,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ export async function save(ctx: UserCtx) {
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
...response,
|
...response,
|
||||||
row,
|
row: await outputProcessing(table, row),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return response
|
return response
|
||||||
|
@ -132,7 +132,8 @@ export async function find(ctx: UserCtx): Promise<Row> {
|
||||||
ctx.throw(404)
|
ctx.throw(404)
|
||||||
}
|
}
|
||||||
|
|
||||||
return row
|
const table = await sdk.tables.getTable(tableId)
|
||||||
|
return await outputProcessing(table, row)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function destroy(ctx: UserCtx) {
|
export async function destroy(ctx: UserCtx) {
|
||||||
|
|
|
@ -1518,8 +1518,16 @@ describe.each([
|
||||||
describe("bb reference fields", () => {
|
describe("bb reference fields", () => {
|
||||||
let tableId: string
|
let tableId: string
|
||||||
let users: User[]
|
let users: User[]
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const tableConfig = generateTableConfig()
|
const tableConfig = generateTableConfig()
|
||||||
|
|
||||||
|
if (config.datasource) {
|
||||||
|
tableConfig.sourceId = config.datasource._id
|
||||||
|
if (config.datasource.plus) {
|
||||||
|
tableConfig.type = "external"
|
||||||
|
}
|
||||||
|
}
|
||||||
const table = await config.api.table.create({
|
const table = await config.api.table.create({
|
||||||
...tableConfig,
|
...tableConfig,
|
||||||
schema: {
|
schema: {
|
||||||
|
@ -1559,10 +1567,11 @@ describe.each([
|
||||||
expect(row).toEqual({
|
expect(row).toEqual({
|
||||||
name: rowData.name,
|
name: rowData.name,
|
||||||
description: rowData.description,
|
description: rowData.description,
|
||||||
type: "row",
|
|
||||||
tableId,
|
tableId,
|
||||||
_id: expect.any(String),
|
_id: expect.any(String),
|
||||||
_rev: expect.any(String),
|
_rev: expect.any(String),
|
||||||
|
id: isInternal ? undefined : expect.any(Number),
|
||||||
|
type: isInternal ? "row" : undefined,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1579,7 +1588,6 @@ describe.each([
|
||||||
expect(row).toEqual({
|
expect(row).toEqual({
|
||||||
name: rowData.name,
|
name: rowData.name,
|
||||||
description: rowData.description,
|
description: rowData.description,
|
||||||
type: "row",
|
|
||||||
tableId,
|
tableId,
|
||||||
user: [
|
user: [
|
||||||
{
|
{
|
||||||
|
@ -1592,6 +1600,8 @@ describe.each([
|
||||||
],
|
],
|
||||||
_id: expect.any(String),
|
_id: expect.any(String),
|
||||||
_rev: expect.any(String),
|
_rev: expect.any(String),
|
||||||
|
id: isInternal ? undefined : expect.any(Number),
|
||||||
|
type: isInternal ? "row" : undefined,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1608,7 +1618,6 @@ describe.each([
|
||||||
expect(row).toEqual({
|
expect(row).toEqual({
|
||||||
name: rowData.name,
|
name: rowData.name,
|
||||||
description: rowData.description,
|
description: rowData.description,
|
||||||
type: "row",
|
|
||||||
tableId,
|
tableId,
|
||||||
users: selectedUsers.map(u => ({
|
users: selectedUsers.map(u => ({
|
||||||
_id: u._id,
|
_id: u._id,
|
||||||
|
@ -1619,6 +1628,8 @@ describe.each([
|
||||||
})),
|
})),
|
||||||
_id: expect.any(String),
|
_id: expect.any(String),
|
||||||
_rev: expect.any(String),
|
_rev: expect.any(String),
|
||||||
|
id: isInternal ? undefined : expect.any(Number),
|
||||||
|
type: isInternal ? "row" : undefined,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1634,14 +1645,13 @@ describe.each([
|
||||||
expect(retrieved).toEqual({
|
expect(retrieved).toEqual({
|
||||||
name: rowData.name,
|
name: rowData.name,
|
||||||
description: rowData.description,
|
description: rowData.description,
|
||||||
type: "row",
|
|
||||||
tableId,
|
tableId,
|
||||||
user: undefined,
|
user: undefined,
|
||||||
users: undefined,
|
users: undefined,
|
||||||
_id: row._id,
|
_id: row._id,
|
||||||
_rev: expect.any(String),
|
_rev: expect.any(String),
|
||||||
createdAt: timestamp,
|
id: isInternal ? undefined : expect.any(Number),
|
||||||
updatedAt: timestamp,
|
...defaultRowFields,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1661,7 +1671,6 @@ describe.each([
|
||||||
expect(retrieved).toEqual({
|
expect(retrieved).toEqual({
|
||||||
name: rowData.name,
|
name: rowData.name,
|
||||||
description: rowData.description,
|
description: rowData.description,
|
||||||
type: "row",
|
|
||||||
tableId,
|
tableId,
|
||||||
user: [user1].map(u => ({
|
user: [user1].map(u => ({
|
||||||
_id: u._id,
|
_id: u._id,
|
||||||
|
@ -1679,8 +1688,8 @@ describe.each([
|
||||||
})),
|
})),
|
||||||
_id: row._id,
|
_id: row._id,
|
||||||
_rev: expect.any(String),
|
_rev: expect.any(String),
|
||||||
createdAt: timestamp,
|
id: isInternal ? undefined : expect.any(Number),
|
||||||
updatedAt: timestamp,
|
...defaultRowFields,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1703,7 +1712,6 @@ describe.each([
|
||||||
expect(updatedRow).toEqual({
|
expect(updatedRow).toEqual({
|
||||||
name: rowData.name,
|
name: rowData.name,
|
||||||
description: rowData.description,
|
description: rowData.description,
|
||||||
type: "row",
|
|
||||||
tableId,
|
tableId,
|
||||||
user: [
|
user: [
|
||||||
{
|
{
|
||||||
|
@ -1723,6 +1731,8 @@ describe.each([
|
||||||
})),
|
})),
|
||||||
_id: row._id,
|
_id: row._id,
|
||||||
_rev: expect.any(String),
|
_rev: expect.any(String),
|
||||||
|
id: isInternal ? undefined : expect.any(Number),
|
||||||
|
type: isInternal ? "row" : undefined,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1745,12 +1755,13 @@ describe.each([
|
||||||
expect(updatedRow).toEqual({
|
expect(updatedRow).toEqual({
|
||||||
name: rowData.name,
|
name: rowData.name,
|
||||||
description: rowData.description,
|
description: rowData.description,
|
||||||
type: "row",
|
|
||||||
tableId,
|
tableId,
|
||||||
user: null,
|
user: isInternal ? null : undefined,
|
||||||
users: null,
|
users: isInternal ? null : undefined,
|
||||||
_id: row._id,
|
_id: row._id,
|
||||||
_rev: expect.any(String),
|
_rev: expect.any(String),
|
||||||
|
id: isInternal ? undefined : expect.any(Number),
|
||||||
|
type: isInternal ? "row" : undefined,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1796,7 +1807,6 @@ describe.each([
|
||||||
rows.map(r => ({
|
rows.map(r => ({
|
||||||
name: r.name,
|
name: r.name,
|
||||||
description: r.description,
|
description: r.description,
|
||||||
type: "row",
|
|
||||||
tableId,
|
tableId,
|
||||||
user: r.user?.map(u => ({
|
user: r.user?.map(u => ({
|
||||||
_id: u._id,
|
_id: u._id,
|
||||||
|
@ -1814,8 +1824,8 @@ describe.each([
|
||||||
})),
|
})),
|
||||||
_id: expect.any(String),
|
_id: expect.any(String),
|
||||||
_rev: expect.any(String),
|
_rev: expect.any(String),
|
||||||
createdAt: timestamp,
|
id: isInternal ? undefined : expect.any(Number),
|
||||||
updatedAt: timestamp,
|
...defaultRowFields,
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -1863,7 +1873,6 @@ describe.each([
|
||||||
rows.map(r => ({
|
rows.map(r => ({
|
||||||
name: r.name,
|
name: r.name,
|
||||||
description: r.description,
|
description: r.description,
|
||||||
type: "row",
|
|
||||||
tableId,
|
tableId,
|
||||||
user: r.user?.map(u => ({
|
user: r.user?.map(u => ({
|
||||||
_id: u._id,
|
_id: u._id,
|
||||||
|
@ -1881,10 +1890,16 @@ describe.each([
|
||||||
})),
|
})),
|
||||||
_id: expect.any(String),
|
_id: expect.any(String),
|
||||||
_rev: expect.any(String),
|
_rev: expect.any(String),
|
||||||
createdAt: timestamp,
|
id: isInternal ? undefined : expect.any(Number),
|
||||||
updatedAt: timestamp,
|
...defaultRowFields,
|
||||||
}))
|
}))
|
||||||
),
|
),
|
||||||
|
...(isInternal
|
||||||
|
? {}
|
||||||
|
: {
|
||||||
|
hasNextPage: false,
|
||||||
|
bookmark: null,
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { utils } from "@budibase/shared-core"
|
||||||
import { ExportRowsParams, ExportRowsResult } from "../search"
|
import { ExportRowsParams, ExportRowsResult } from "../search"
|
||||||
import { HTTPError, db } from "@budibase/backend-core"
|
import { HTTPError, db } from "@budibase/backend-core"
|
||||||
import pick from "lodash/pick"
|
import pick from "lodash/pick"
|
||||||
|
import { outputProcessing } from "../../../../utilities/rowProcessor"
|
||||||
|
|
||||||
export async function search(options: SearchParams) {
|
export async function search(options: SearchParams) {
|
||||||
const { tableId } = options
|
const { tableId } = options
|
||||||
|
@ -75,6 +76,9 @@ export async function search(options: SearchParams) {
|
||||||
rows = rows.map((r: any) => pick(r, fields))
|
rows = rows.map((r: any) => pick(r, fields))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const table = await sdk.tables.getTable(tableId)
|
||||||
|
rows = await outputProcessing(table, rows)
|
||||||
|
|
||||||
// need wrapper object for bookmarks etc when paginating
|
// need wrapper object for bookmarks etc when paginating
|
||||||
return { rows, hasNextPage, bookmark: bookmark && bookmark + 1 }
|
return { rows, hasNextPage, bookmark: bookmark && bookmark + 1 }
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
@ -166,9 +170,11 @@ export async function exportRows(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetch(tableId: string) {
|
export async function fetch(tableId: string) {
|
||||||
return handleRequest(Operation.READ, tableId, {
|
const response = await handleRequest(Operation.READ, tableId, {
|
||||||
includeSqlRelationships: IncludeRelationship.INCLUDE,
|
includeSqlRelationships: IncludeRelationship.INCLUDE,
|
||||||
})
|
})
|
||||||
|
const table = await sdk.tables.getTable(tableId)
|
||||||
|
return await outputProcessing(table, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchView(viewName: string) {
|
export async function fetchView(viewName: string) {
|
||||||
|
|
Loading…
Reference in New Issue