Fix for tests - row.spec.ts needs to pick correct table create.
This commit is contained in:
parent
d0f989597a
commit
983091e901
|
@ -138,14 +138,22 @@ describe.each([
|
||||||
}
|
}
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
beforeAll(async () => {
|
async function createTable(
|
||||||
const tableConfig = generateTableConfig()
|
cfg: Omit<SaveTableRequest, "sourceId" | "sourceType">,
|
||||||
|
opts?: { skipReassigning: boolean }
|
||||||
|
) {
|
||||||
let table
|
let table
|
||||||
if (dsProvider) {
|
if (dsProvider) {
|
||||||
table = await config.createExternalTable(tableConfig)
|
table = await config.createExternalTable(cfg, opts)
|
||||||
} else {
|
} else {
|
||||||
table = await config.createTable(tableConfig)
|
table = await config.createTable(cfg, opts)
|
||||||
}
|
}
|
||||||
|
return table
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
const tableConfig = generateTableConfig()
|
||||||
|
let table = await createTable(tableConfig)
|
||||||
tableId = table._id!
|
tableId = table._id!
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -174,7 +182,7 @@ describe.each([
|
||||||
const queryUsage = await getQueryUsage()
|
const queryUsage = await getQueryUsage()
|
||||||
|
|
||||||
const tableConfig = generateTableConfig()
|
const tableConfig = generateTableConfig()
|
||||||
const newTable = await config.createTable(
|
const newTable = await createTable(
|
||||||
{
|
{
|
||||||
...tableConfig,
|
...tableConfig,
|
||||||
name: "TestTableAuto",
|
name: "TestTableAuto",
|
||||||
|
@ -251,7 +259,7 @@ describe.each([
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should list all rows for given tableId", async () => {
|
it("should list all rows for given tableId", async () => {
|
||||||
const table = await config.createTable(generateTableConfig(), {
|
const table = await createTable(generateTableConfig(), {
|
||||||
skipReassigning: true,
|
skipReassigning: true,
|
||||||
})
|
})
|
||||||
const tableId = table._id!
|
const tableId = table._id!
|
||||||
|
@ -332,7 +340,7 @@ describe.each([
|
||||||
inclusion: ["Alpha", "Beta", "Gamma"],
|
inclusion: ["Alpha", "Beta", "Gamma"],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const table = await config.createTable({
|
const table = await createTable({
|
||||||
name: "TestTable2",
|
name: "TestTable2",
|
||||||
type: "table",
|
type: "table",
|
||||||
schema: {
|
schema: {
|
||||||
|
@ -447,7 +455,7 @@ describe.each([
|
||||||
|
|
||||||
describe("view save", () => {
|
describe("view save", () => {
|
||||||
it("views have extra data trimmed", async () => {
|
it("views have extra data trimmed", async () => {
|
||||||
const table = await config.createTable({
|
const table = await createTable({
|
||||||
type: "table",
|
type: "table",
|
||||||
name: "orders",
|
name: "orders",
|
||||||
primary: ["OrderID"],
|
primary: ["OrderID"],
|
||||||
|
@ -504,7 +512,7 @@ describe.each([
|
||||||
describe("patch", () => {
|
describe("patch", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const tableConfig = generateTableConfig()
|
const tableConfig = generateTableConfig()
|
||||||
table = await config.createTable(tableConfig)
|
table = await createTable(tableConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should update only the fields that are supplied", async () => {
|
it("should update only the fields that are supplied", async () => {
|
||||||
|
@ -558,7 +566,7 @@ describe.each([
|
||||||
describe("destroy", () => {
|
describe("destroy", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const tableConfig = generateTableConfig()
|
const tableConfig = generateTableConfig()
|
||||||
table = await config.createTable(tableConfig)
|
table = await createTable(tableConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should be able to delete a row", async () => {
|
it("should be able to delete a row", async () => {
|
||||||
|
@ -576,7 +584,7 @@ describe.each([
|
||||||
describe("validate", () => {
|
describe("validate", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const tableConfig = generateTableConfig()
|
const tableConfig = generateTableConfig()
|
||||||
table = await config.createTable(tableConfig)
|
table = await createTable(tableConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return no errors on valid row", async () => {
|
it("should return no errors on valid row", async () => {
|
||||||
|
@ -613,7 +621,7 @@ describe.each([
|
||||||
describe("bulkDelete", () => {
|
describe("bulkDelete", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const tableConfig = generateTableConfig()
|
const tableConfig = generateTableConfig()
|
||||||
table = await config.createTable(tableConfig)
|
table = await createTable(tableConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should be able to delete a bulk set of rows", async () => {
|
it("should be able to delete a bulk set of rows", async () => {
|
||||||
|
@ -697,7 +705,7 @@ describe.each([
|
||||||
describe("fetchView", () => {
|
describe("fetchView", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const tableConfig = generateTableConfig()
|
const tableConfig = generateTableConfig()
|
||||||
table = await config.createTable(tableConfig)
|
table = await createTable(tableConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should be able to fetch tables contents via 'view'", async () => {
|
it("should be able to fetch tables contents via 'view'", async () => {
|
||||||
|
@ -745,7 +753,7 @@ describe.each([
|
||||||
describe("fetchEnrichedRows", () => {
|
describe("fetchEnrichedRows", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const tableConfig = generateTableConfig()
|
const tableConfig = generateTableConfig()
|
||||||
table = await config.createTable(tableConfig)
|
table = await createTable(tableConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should allow enriching some linked rows", async () => {
|
it("should allow enriching some linked rows", async () => {
|
||||||
|
@ -818,7 +826,7 @@ describe.each([
|
||||||
describe("attachments", () => {
|
describe("attachments", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const tableConfig = generateTableConfig()
|
const tableConfig = generateTableConfig()
|
||||||
table = await config.createTable(tableConfig)
|
table = await createTable(tableConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should allow enriching attachment rows", async () => {
|
it("should allow enriching attachment rows", async () => {
|
||||||
|
@ -849,7 +857,7 @@ describe.each([
|
||||||
describe("exportData", () => {
|
describe("exportData", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const tableConfig = generateTableConfig()
|
const tableConfig = generateTableConfig()
|
||||||
table = await config.createTable(tableConfig)
|
table = await createTable(tableConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should allow exporting all columns", async () => {
|
it("should allow exporting all columns", async () => {
|
||||||
|
@ -937,7 +945,7 @@ describe.each([
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
it("should persist a new row with only the provided view fields", async () => {
|
it("should persist a new row with only the provided view fields", async () => {
|
||||||
const table = await config.createTable(await userTable())
|
const table = await createTable(await userTable())
|
||||||
const view = await config.createView({
|
const view = await config.createView({
|
||||||
schema: {
|
schema: {
|
||||||
name: { visible: true },
|
name: { visible: true },
|
||||||
|
@ -972,7 +980,7 @@ describe.each([
|
||||||
|
|
||||||
describe("patch", () => {
|
describe("patch", () => {
|
||||||
it("should update only the view fields for a row", async () => {
|
it("should update only the view fields for a row", async () => {
|
||||||
const table = await config.createTable(await userTable())
|
const table = await createTable(await userTable())
|
||||||
const tableId = table._id!
|
const tableId = table._id!
|
||||||
const view = await config.createView({
|
const view = await config.createView({
|
||||||
schema: {
|
schema: {
|
||||||
|
@ -1013,7 +1021,7 @@ describe.each([
|
||||||
|
|
||||||
describe("destroy", () => {
|
describe("destroy", () => {
|
||||||
it("should be able to delete a row", async () => {
|
it("should be able to delete a row", async () => {
|
||||||
const table = await config.createTable(await userTable())
|
const table = await createTable(await userTable())
|
||||||
const tableId = table._id!
|
const tableId = table._id!
|
||||||
const view = await config.createView({
|
const view = await config.createView({
|
||||||
schema: {
|
schema: {
|
||||||
|
@ -1037,7 +1045,7 @@ describe.each([
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should be able to delete multiple rows", async () => {
|
it("should be able to delete multiple rows", async () => {
|
||||||
const table = await config.createTable(await userTable())
|
const table = await createTable(await userTable())
|
||||||
const tableId = table._id!
|
const tableId = table._id!
|
||||||
const view = await config.createView({
|
const view = await config.createView({
|
||||||
schema: {
|
schema: {
|
||||||
|
@ -1102,7 +1110,7 @@ describe.each([
|
||||||
}
|
}
|
||||||
|
|
||||||
it("returns empty rows from view when no schema is passed", async () => {
|
it("returns empty rows from view when no schema is passed", async () => {
|
||||||
const table = await config.createTable(await userTable())
|
const table = await createTable(await userTable())
|
||||||
const rows = await Promise.all(
|
const rows = await Promise.all(
|
||||||
Array.from({ length: 10 }, () =>
|
Array.from({ length: 10 }, () =>
|
||||||
config.api.row.save(table._id!, { tableId: table._id })
|
config.api.row.save(table._id!, { tableId: table._id })
|
||||||
|
@ -1133,7 +1141,7 @@ describe.each([
|
||||||
})
|
})
|
||||||
|
|
||||||
it("searching respects the view filters", async () => {
|
it("searching respects the view filters", async () => {
|
||||||
const table = await config.createTable(await userTable())
|
const table = await createTable(await userTable())
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Array.from({ length: 10 }, () =>
|
Array.from({ length: 10 }, () =>
|
||||||
|
@ -1257,7 +1265,7 @@ describe.each([
|
||||||
|
|
||||||
describe("sorting", () => {
|
describe("sorting", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const table = await config.createTable(await userTable())
|
const table = await createTable(await userTable())
|
||||||
const users = [
|
const users = [
|
||||||
{ name: "Alice", age: 25 },
|
{ name: "Alice", age: 25 },
|
||||||
{ name: "Bob", age: 30 },
|
{ name: "Bob", age: 30 },
|
||||||
|
@ -1324,7 +1332,7 @@ describe.each([
|
||||||
})
|
})
|
||||||
|
|
||||||
it("when schema is defined, defined columns and row attributes are returned", async () => {
|
it("when schema is defined, defined columns and row attributes are returned", async () => {
|
||||||
const table = await config.createTable(await userTable())
|
const table = await createTable(await userTable())
|
||||||
const rows = await Promise.all(
|
const rows = await Promise.all(
|
||||||
Array.from({ length: 10 }, () =>
|
Array.from({ length: 10 }, () =>
|
||||||
config.api.row.save(table._id!, {
|
config.api.row.save(table._id!, {
|
||||||
|
@ -1355,7 +1363,7 @@ describe.each([
|
||||||
})
|
})
|
||||||
|
|
||||||
it("views without data can be returned", async () => {
|
it("views without data can be returned", async () => {
|
||||||
const table = await config.createTable(await userTable())
|
const table = await createTable(await userTable())
|
||||||
|
|
||||||
const createViewResponse = await config.createView()
|
const createViewResponse = await config.createView()
|
||||||
const response = await config.api.viewV2.search(createViewResponse.id)
|
const response = await config.api.viewV2.search(createViewResponse.id)
|
||||||
|
@ -1364,7 +1372,7 @@ describe.each([
|
||||||
})
|
})
|
||||||
|
|
||||||
it("respects the limit parameter", async () => {
|
it("respects the limit parameter", async () => {
|
||||||
await config.createTable(await userTable())
|
await createTable(await userTable())
|
||||||
await Promise.all(Array.from({ length: 10 }, () => config.createRow()))
|
await Promise.all(Array.from({ length: 10 }, () => config.createRow()))
|
||||||
|
|
||||||
const limit = generator.integer({ min: 1, max: 8 })
|
const limit = generator.integer({ min: 1, max: 8 })
|
||||||
|
@ -1379,7 +1387,7 @@ describe.each([
|
||||||
})
|
})
|
||||||
|
|
||||||
it("can handle pagination", async () => {
|
it("can handle pagination", async () => {
|
||||||
await config.createTable(await userTable())
|
await createTable(await userTable())
|
||||||
await Promise.all(Array.from({ length: 10 }, () => config.createRow()))
|
await Promise.all(Array.from({ length: 10 }, () => config.createRow()))
|
||||||
|
|
||||||
const createViewResponse = await config.createView()
|
const createViewResponse = await config.createView()
|
||||||
|
@ -1457,7 +1465,7 @@ describe.each([
|
||||||
let tableId: string
|
let tableId: string
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await config.createTable(await userTable())
|
await createTable(await userTable())
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Array.from({ length: 10 }, () => config.createRow())
|
Array.from({ length: 10 }, () => config.createRow())
|
||||||
)
|
)
|
||||||
|
@ -1535,13 +1543,13 @@ describe.each([
|
||||||
let o2mTable: Table
|
let o2mTable: Table
|
||||||
let m2mTable: Table
|
let m2mTable: Table
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
o2mTable = await config.createTable(
|
o2mTable = await createTable(
|
||||||
{ ...generateTableConfig(), name: "o2m" },
|
{ ...generateTableConfig(), name: "o2m" },
|
||||||
{
|
{
|
||||||
skipReassigning: true,
|
skipReassigning: true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
m2mTable = await config.createTable(
|
m2mTable = await createTable(
|
||||||
{ ...generateTableConfig(), name: "m2m" },
|
{ ...generateTableConfig(), name: "m2m" },
|
||||||
{
|
{
|
||||||
skipReassigning: true,
|
skipReassigning: true,
|
||||||
|
|
|
@ -71,7 +71,7 @@ type DefaultUserValues = {
|
||||||
csrfToken: string
|
csrfToken: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TableToBuild extends Omit<Table, "sourceId" | "sourceType"> {
|
export interface TableToBuild extends Omit<Table, "sourceId" | "sourceType"> {
|
||||||
sourceId?: string
|
sourceId?: string
|
||||||
sourceType?: TableSourceType
|
sourceType?: TableSourceType
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue