Many to many tests

This commit is contained in:
Adria Navarro 2024-08-16 10:03:15 +02:00
parent 27c618d263
commit 07fe8c6c1f
1 changed files with 222 additions and 160 deletions

View File

@ -319,6 +319,7 @@ describe("query utils", () => {
})
describe("nested relationship", () => {
describe("one-to-many", () => {
let table: Table, aux1: Table, aux2: Table
beforeAll(async () => {
@ -497,5 +498,66 @@ describe("query utils", () => {
])
})
})
describe("many-to-many", () => {
let table: Table, aux: Table
beforeAll(async () => {
const { _id: auxId } = await config.api.table.save({
...structures.basicTable(),
name: "auxTable",
schema: {
title: { name: "title", type: FieldType.STRING },
},
})
const { _id: tableId } = await config.api.table.save({
...structures.basicTable(),
schema: {
name: { name: "name", type: FieldType.STRING },
aux: {
name: "aux",
type: FieldType.LINK,
tableId: auxId!,
relationshipType: RelationshipType.MANY_TO_MANY,
fieldName: "table",
},
},
})
// We need to refech them to get the updated foreign keys
aux = await config.api.table.get(auxId!)
table = await config.api.table.get(tableId!)
})
it("includes nested relationship fields from main table", async () => {
const result = await config.doInContext(config.appId, () => {
return getQueryableFields(Object.keys(table.schema), table)
})
expect(result).toEqual([
"_id",
"name",
// deep 1 aux primitive props
"aux.title",
"auxTable.title",
])
})
it("includes nested relationship fields from aux table", async () => {
const result = await config.doInContext(config.appId, () => {
return getQueryableFields(Object.keys(aux.schema), aux)
})
expect(result).toEqual([
"_id",
"title",
// deep 1 dependency primitive props
"table.name",
"TestTable.name",
])
})
})
})
})
})