Dry tests
This commit is contained in:
parent
6a1589ba64
commit
ac9ad71a11
|
@ -6,8 +6,11 @@ import {
|
|||
|
||||
import * as setup from "../api/routes/tests/utilities"
|
||||
import { Datasource, FieldType, SourceName, Table } from "@budibase/types"
|
||||
import _ from "lodash"
|
||||
|
||||
const config = setup.getConfig()
|
||||
|
||||
describe("row api - postgres", () => {
|
||||
let apiKey,
|
||||
makeRequest: MakeRequestResponse,
|
||||
postgresDatasource: Datasource,
|
||||
|
@ -70,9 +73,22 @@ function createRandomRow() {
|
|||
}
|
||||
}
|
||||
|
||||
describe("row api", () => {
|
||||
async function populateRows(count: number) {
|
||||
return await Promise.all(
|
||||
Array(count)
|
||||
.fill({})
|
||||
.map(async () => {
|
||||
const rowData = createRandomRow()
|
||||
return {
|
||||
rowData,
|
||||
row: await config.createRow(rowData),
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
describe("create a row", () => {
|
||||
test("Given than no row exists, adding a new rows persists it", async () => {
|
||||
test("Given than no row exists, adding a new row persists it", async () => {
|
||||
const newRow = createRandomRow()
|
||||
|
||||
const res = await makeRequest(
|
||||
|
@ -114,10 +130,9 @@ describe("row api", () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe("Retrieve a row", () => {
|
||||
describe("retrieve a row", () => {
|
||||
test("Given than a table have a single row, the row can be retrieved successfully", async () => {
|
||||
const rowData = createRandomRow()
|
||||
const row = await config.createRow(rowData)
|
||||
const [{ rowData, row }] = await populateRows(1)
|
||||
|
||||
const res = await makeRequest(
|
||||
"get",
|
||||
|
@ -130,10 +145,8 @@ describe("row api", () => {
|
|||
})
|
||||
|
||||
test("Given than a table have a multiple rows, a single row can be retrieved successfully", async () => {
|
||||
await Promise.all(Array(5).map(() => config.createRow(createRandomRow())))
|
||||
const rowData = createRandomRow()
|
||||
const row = await config.createRow(rowData)
|
||||
await Promise.all(Array(2).map(() => config.createRow(createRandomRow())))
|
||||
const rows = await populateRows(10)
|
||||
const { rowData, row } = _.sample(rows)!
|
||||
|
||||
const res = await makeRequest(
|
||||
"get",
|
||||
|
|
Loading…
Reference in New Issue