Fix tests
This commit is contained in:
parent
3d9a208bfb
commit
29503d1244
|
@ -18,7 +18,6 @@ import { utils } from "@budibase/backend-core"
|
|||
|
||||
const config = setup.getConfig()!
|
||||
|
||||
jest.unmock("node-fetch")
|
||||
jest.unmock("pg")
|
||||
|
||||
describe("row api - postgres", () => {
|
||||
|
@ -127,13 +126,11 @@ describe("row api - postgres", () => {
|
|||
await config.end()
|
||||
})
|
||||
|
||||
const randomInteger = () => generator.integer({ min: 0, max: 10000 })
|
||||
|
||||
function makeRandomRow() {
|
||||
return {
|
||||
name: generator.name(),
|
||||
description: generator.paragraph(),
|
||||
value: randomInteger(),
|
||||
value: generator.age(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,8 +242,6 @@ describe("row api - postgres", () => {
|
|||
...newRow,
|
||||
}
|
||||
|
||||
// TODO: check why this is being returned from the creation
|
||||
delete expected.linkedField
|
||||
expect(persistedRows).toEqual([expect.objectContaining(expected)])
|
||||
})
|
||||
|
||||
|
@ -275,16 +270,13 @@ describe("row api - postgres", () => {
|
|||
let { row } = _.sample(await populateRows(10))!
|
||||
|
||||
const newName = generator.name()
|
||||
const newValue = randomInteger()
|
||||
const newValue = generator.age()
|
||||
const updatedRow = {
|
||||
...row,
|
||||
name: newName,
|
||||
value: newValue,
|
||||
}
|
||||
|
||||
// TODO: check why this is being returned from the creation
|
||||
delete (updatedRow as any).linkedField
|
||||
|
||||
const res = await updateRow(postgresTable._id, updatedRow)
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
|
@ -383,11 +375,8 @@ describe("row api - postgres", () => {
|
|||
|
||||
expect(res.status).toBe(200)
|
||||
|
||||
const expected = { ...row }
|
||||
// TODO: check why this is being returned from the creation
|
||||
delete expected.linkedField
|
||||
expect(res.body).toEqual({
|
||||
...expected,
|
||||
...row,
|
||||
_id: expect.any(String),
|
||||
_rev: expect.any(String),
|
||||
})
|
||||
|
@ -450,12 +439,12 @@ describe("row api - postgres", () => {
|
|||
...Array(2).fill({
|
||||
name,
|
||||
description: generator.paragraph(),
|
||||
value: randomInteger(),
|
||||
value: generator.age(),
|
||||
}),
|
||||
...Array(2).fill({
|
||||
name: `${name}${utils.newid()}`,
|
||||
description: generator.paragraph(),
|
||||
value: randomInteger(),
|
||||
value: generator.age(),
|
||||
}),
|
||||
]
|
||||
|
||||
|
|
|
@ -89,13 +89,22 @@ function parseFilters(filters: SearchFilters | undefined): SearchFilters {
|
|||
|
||||
function generateSelectStatement(
|
||||
json: QueryJson,
|
||||
knex: Knex
|
||||
knex: Knex,
|
||||
excludeJoinColumns = false
|
||||
): (string | Knex.Raw)[] {
|
||||
const { resource, meta } = json
|
||||
const schema = meta?.table?.schema
|
||||
return resource!.fields.map(field => {
|
||||
|
||||
return resource!.fields.reduce<(string | Knex.Raw)[]>((p, field) => {
|
||||
const fieldNames = field.split(/\./g)
|
||||
const tableName = fieldNames[0]
|
||||
if (
|
||||
meta?.table?.name &&
|
||||
excludeJoinColumns &&
|
||||
tableName !== meta.table.name
|
||||
) {
|
||||
return p
|
||||
}
|
||||
const columnName = fieldNames[1]
|
||||
if (
|
||||
columnName &&
|
||||
|
@ -104,13 +113,18 @@ function generateSelectStatement(
|
|||
) {
|
||||
const externalType = schema[columnName].externalType
|
||||
if (externalType?.includes("money")) {
|
||||
return knex.raw(
|
||||
p.push(
|
||||
knex.raw(
|
||||
`"${tableName}"."${columnName}"::money::numeric as "${field}"`
|
||||
)
|
||||
)
|
||||
return p
|
||||
}
|
||||
}
|
||||
return `${field} as ${field}`
|
||||
})
|
||||
|
||||
p.push(`${field} as ${field}`)
|
||||
return p
|
||||
}, [])
|
||||
}
|
||||
|
||||
class InternalBuilder {
|
||||
|
@ -396,7 +410,9 @@ class InternalBuilder {
|
|||
if (opts.disableReturning) {
|
||||
return query.insert(parsedBody)
|
||||
} else {
|
||||
return query.insert(parsedBody).returning("*")
|
||||
return query
|
||||
.insert(parsedBody)
|
||||
.returning(generateSelectStatement(json, knex, true))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue