1
0
Fork 0
mirror of synced 2024-09-10 14:35:47 +12:00

Cleanup test

This commit is contained in:
Adria Navarro 2023-09-13 11:00:53 +02:00
parent 47899c669d
commit c7e41eacc7

View file

@ -181,32 +181,16 @@ describe("postgres integrations", () => {
let { rowData } = opts as any let { rowData } = opts as any
let foreignRows: ForeignRowsInfo[] = [] let foreignRows: ForeignRowsInfo[] = []
async function createForeignRow(tableInfo: ForeignTableInfo) {
const foreignKey = `fk_${tableInfo.table.name}_${tableInfo.fieldName}`
const foreignRow = await config.createRow({
tableId: tableInfo.table._id,
title: generator.name(),
})
rowData = {
...rowData,
[foreignKey]: foreignRow.id,
}
foreignRows.push({
row: foreignRow,
relationshipType: tableInfo.relationshipType,
})
}
if (opts?.createForeignRows?.createOneToMany) { if (opts?.createForeignRows?.createOneToMany) {
const foreignKey = `fk_${oneToManyRelationshipInfo.table.name}_${oneToManyRelationshipInfo.fieldName}` const foreignKey = `fk_${oneToManyRelationshipInfo.table.name}_${oneToManyRelationshipInfo.fieldName}`
const foreignRow = await config.createRow({ const foreignRow = await config.api.row.save(
tableId: oneToManyRelationshipInfo.table._id, oneToManyRelationshipInfo.table._id!,
title: generator.name(), {
}) tableId: oneToManyRelationshipInfo.table._id,
title: generator.name(),
}
)
rowData = { rowData = {
...rowData, ...rowData,
@ -219,10 +203,13 @@ describe("postgres integrations", () => {
} }
for (let i = 0; i < (opts?.createForeignRows?.createManyToOne || 0); i++) { for (let i = 0; i < (opts?.createForeignRows?.createManyToOne || 0); i++) {
const foreignRow = await config.createRow({ const foreignRow = await config.api.row.save(
tableId: manyToOneRelationshipInfo.table._id, manyToOneRelationshipInfo.table._id!,
title: generator.name(), {
}) tableId: manyToOneRelationshipInfo.table._id,
title: generator.name(),
}
)
rowData = { rowData = {
...rowData, ...rowData,
@ -237,10 +224,13 @@ describe("postgres integrations", () => {
} }
for (let i = 0; i < (opts?.createForeignRows?.createManyToMany || 0); i++) { for (let i = 0; i < (opts?.createForeignRows?.createManyToMany || 0); i++) {
const foreignRow = await config.createRow({ const foreignRow = await config.api.row.save(
tableId: manyToManyRelationshipInfo.table._id, manyToManyRelationshipInfo.table._id!,
title: generator.name(), {
}) tableId: manyToManyRelationshipInfo.table._id,
title: generator.name(),
}
)
rowData = { rowData = {
...rowData, ...rowData,
@ -254,7 +244,7 @@ describe("postgres integrations", () => {
}) })
} }
const row = await config.createRow({ const row = await config.api.row.save(primaryPostgresTable._id!, {
tableId: primaryPostgresTable._id, tableId: primaryPostgresTable._id,
...rowData, ...rowData,
}) })
@ -277,6 +267,14 @@ describe("postgres integrations", () => {
}) })
} }
const createRandomTableWithRows = async () => {
const tableId = (await createDefaultPgTable())._id!
return await config.api.row.save(tableId, {
tableId,
title: generator.name(),
})
}
async function populatePrimaryRows( async function populatePrimaryRows(
count: number, count: number,
opts?: { opts?: {
@ -685,12 +683,6 @@ describe("postgres integrations", () => {
describe("given than multiple tables have multiple rows", () => { describe("given than multiple tables have multiple rows", () => {
const rowsCount = 6 const rowsCount = 6
beforeEach(async () => { beforeEach(async () => {
const createRandomTableWithRows = async () =>
await config.createRow({
tableId: (await createDefaultPgTable())._id,
title: generator.name(),
})
await createRandomTableWithRows() await createRandomTableWithRows()
await createRandomTableWithRows() await createRandomTableWithRows()
@ -978,12 +970,6 @@ describe("postgres integrations", () => {
const rowsCount = 6 const rowsCount = 6
beforeEach(async () => { beforeEach(async () => {
const createRandomTableWithRows = async () =>
await config.createRow({
tableId: (await createDefaultPgTable())._id,
title: generator.name(),
})
await createRandomTableWithRows() await createRandomTableWithRows()
await populatePrimaryRows(rowsCount) await populatePrimaryRows(rowsCount)
await createRandomTableWithRows() await createRandomTableWithRows()