Adding test case for tables with spaces.

This commit is contained in:
mike12345567 2024-12-12 15:55:39 +00:00
parent 635049ab0f
commit 7f62f32adc
1 changed files with 52 additions and 7 deletions

View File

@ -71,18 +71,27 @@ if (descriptions.length) {
let tableOrViewId: string let tableOrViewId: string
let rows: Row[] let rows: Row[]
async function basicRelationshipTables(type: RelationshipType) { async function basicRelationshipTables(
type: RelationshipType,
opts?: {
tableName?: string
primaryColumn?: string
otherColumn?: string
}
) {
const relatedTable = await createTable({ const relatedTable = await createTable({
name: { name: "name", type: FieldType.STRING }, name: { name: opts?.tableName || "name", type: FieldType.STRING },
}) })
const columnName = opts?.primaryColumn || "productCat"
//@ts-ignore - API accepts this structure, will build out rest of definition
const tableId = await createTable({ const tableId = await createTable({
name: { name: "name", type: FieldType.STRING }, name: { name: opts?.tableName || "name", type: FieldType.STRING },
//@ts-ignore - API accepts this structure, will build out rest of definition [columnName]: {
productCat: {
type: FieldType.LINK, type: FieldType.LINK,
relationshipType: type, relationshipType: type,
name: "productCat", name: columnName,
fieldName: "product", fieldName: opts?.otherColumn || "product",
tableId: relatedTable, tableId: relatedTable,
constraints: { constraints: {
type: "array", type: "array",
@ -2776,6 +2785,42 @@ if (descriptions.length) {
}) })
}) })
isSql &&
describe("relationship - table with spaces", () => {
let primaryTable: Table, row: Row
beforeAll(async () => {
const { relatedTable, tableId } =
await basicRelationshipTables(
RelationshipType.ONE_TO_MANY,
{
tableName: "table with spaces",
primaryColumn: "related",
otherColumn: "related",
}
)
tableOrViewId = tableId
primaryTable = relatedTable
row = await config.api.row.save(primaryTable._id!, {
name: "foo",
})
await config.api.row.save(tableOrViewId, {
name: "foo",
related: [row._id],
})
})
it("should be able to search by table name with spaces", async () => {
await expectQuery({
equal: {
["table with spaces.name"]: "foo",
},
}).toContain([{ name: "foo" }])
})
})
isSql && isSql &&
describe.each([ describe.each([
RelationshipType.MANY_TO_ONE, RelationshipType.MANY_TO_ONE,