Clean tests

This commit is contained in:
Adria Navarro 2023-09-27 17:35:16 +02:00
parent d7cbd2dcbc
commit e22c770bad
1 changed files with 18 additions and 18 deletions

View File

@ -18,6 +18,7 @@ import {
SortType, SortType,
StaticQuotaName, StaticQuotaName,
Table, Table,
User,
} from "@budibase/types" } from "@budibase/types"
import { import {
expectAnyExternalColsAttributes, expectAnyExternalColsAttributes,
@ -26,6 +27,7 @@ import {
mocks, mocks,
structures, structures,
} from "@budibase/backend-core/tests" } from "@budibase/backend-core/tests"
import _ from "lodash"
const timestamp = new Date("2023-01-26T11:48:57.597Z").toISOString() const timestamp = new Date("2023-01-26T11:48:57.597Z").toISOString()
tk.freeze(timestamp) tk.freeze(timestamp)
@ -35,7 +37,7 @@ const { basicRow } = setup.structures
describe.each([ describe.each([
["internal", undefined], ["internal", undefined],
["postgres", databaseTestProviders.postgres], ["postgres", databaseTestProviders.postgres],
])("/rows (%s)", (_, dsProvider) => { ])("/rows (%s)", (__, dsProvider) => {
const isInternal = !dsProvider const isInternal = !dsProvider
const request = setup.getRequest() const request = setup.getRequest()
@ -1515,6 +1517,7 @@ describe.each([
describe("bb reference fields", () => { describe("bb reference fields", () => {
let tableId: string let tableId: string
let users: User[]
beforeAll(async () => { beforeAll(async () => {
const tableConfig = generateTableConfig() const tableConfig = generateTableConfig()
const table = await config.api.table.create({ const table = await config.api.table.create({
@ -1536,6 +1539,13 @@ describe.each([
}, },
}) })
tableId = table._id! tableId = table._id!
users = [
await config.createUser(),
await config.createUser(),
await config.createUser(),
await config.createUser(),
]
}) })
it("can save a row when BB reference fields are empty", async () => { it("can save a row when BB reference fields are empty", async () => {
@ -1557,7 +1567,7 @@ describe.each([
}) })
it("can save a row with a single BB reference field", async () => { it("can save a row with a single BB reference field", async () => {
const user = await config.createUser() const user = _.sample(users)!
const rowData = { const rowData = {
...basicRow(tableId), ...basicRow(tableId),
name: generator.name(), name: generator.name(),
@ -1586,12 +1596,12 @@ describe.each([
}) })
it("can save a row with a multiple BB reference field", async () => { it("can save a row with a multiple BB reference field", async () => {
const users = [await config.createUser(), await config.createUser()] const selectedUsers = _.sampleSize(users, 2)
const rowData = { const rowData = {
...basicRow(tableId), ...basicRow(tableId),
name: generator.name(), name: generator.name(),
description: generator.name(), description: generator.name(),
users: users, users: selectedUsers,
} }
const row = await config.api.row.save(tableId, rowData) const row = await config.api.row.save(tableId, rowData)
@ -1600,7 +1610,7 @@ describe.each([
description: rowData.description, description: rowData.description,
type: "row", type: "row",
tableId, tableId,
users: users.map(u => ({ users: selectedUsers.map(u => ({
_id: u._id, _id: u._id,
email: u.email, email: u.email,
firstName: u.firstName, firstName: u.firstName,
@ -1636,10 +1646,7 @@ describe.each([
}) })
it("can retrieve rows with populated BB references", async () => { it("can retrieve rows with populated BB references", async () => {
const [user1, user2] = [ const [user1, user2] = _.sampleSize(users, 2)
await config.createUser(),
await config.createUser(),
]
const rowData = { const rowData = {
...basicRow(tableId), ...basicRow(tableId),
@ -1678,11 +1685,7 @@ describe.each([
}) })
it("can update an existing populated row", async () => { it("can update an existing populated row", async () => {
const [user1, user2, user3] = [ const [user1, user2, user3] = _.sampleSize(users, 3)
await config.createUser(),
await config.createUser(),
await config.createUser(),
]
const rowData = { const rowData = {
...basicRow(tableId), ...basicRow(tableId),
@ -1724,10 +1727,7 @@ describe.each([
}) })
it("can wipe an existing populated BB references in row", async () => { it("can wipe an existing populated BB references in row", async () => {
const [user1, user2] = [ const [user1, user2] = _.sampleSize(users, 2)
await config.createUser(),
await config.createUser(),
]
const rowData = { const rowData = {
...basicRow(tableId), ...basicRow(tableId),