Many to many tests
This commit is contained in:
parent
27c618d263
commit
07fe8c6c1f
|
@ -319,182 +319,244 @@ describe("query utils", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("nested relationship", () => {
|
describe("nested relationship", () => {
|
||||||
let table: Table, aux1: Table, aux2: Table
|
describe("one-to-many", () => {
|
||||||
|
let table: Table, aux1: Table, aux2: Table
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const { _id: aux1Id } = await config.api.table.save({
|
const { _id: aux1Id } = await config.api.table.save({
|
||||||
...structures.basicTable(),
|
...structures.basicTable(),
|
||||||
name: "aux1Table",
|
name: "aux1Table",
|
||||||
schema: {
|
schema: {
|
||||||
name: { name: "name", type: FieldType.STRING },
|
name: { name: "name", type: FieldType.STRING },
|
||||||
},
|
|
||||||
})
|
|
||||||
const { _id: aux2Id } = await config.api.table.save({
|
|
||||||
...structures.basicTable(),
|
|
||||||
name: "aux2Table",
|
|
||||||
schema: {
|
|
||||||
title: { name: "title", type: FieldType.STRING },
|
|
||||||
aux1_1: {
|
|
||||||
name: "aux1_1",
|
|
||||||
type: FieldType.LINK,
|
|
||||||
tableId: aux1Id!,
|
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
|
||||||
fieldName: "aux2_1",
|
|
||||||
},
|
},
|
||||||
aux1_2: {
|
})
|
||||||
name: "aux1_2",
|
const { _id: aux2Id } = await config.api.table.save({
|
||||||
type: FieldType.LINK,
|
...structures.basicTable(),
|
||||||
tableId: aux1Id!,
|
name: "aux2Table",
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
schema: {
|
||||||
fieldName: "aux2_2",
|
title: { name: "title", type: FieldType.STRING },
|
||||||
|
aux1_1: {
|
||||||
|
name: "aux1_1",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
tableId: aux1Id!,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
fieldName: "aux2_1",
|
||||||
|
},
|
||||||
|
aux1_2: {
|
||||||
|
name: "aux1_2",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
tableId: aux1Id!,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
fieldName: "aux2_2",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
})
|
||||||
|
|
||||||
|
const { _id: tableId } = await config.api.table.save({
|
||||||
|
...structures.basicTable(),
|
||||||
|
schema: {
|
||||||
|
name: { name: "name", type: FieldType.STRING },
|
||||||
|
aux1: {
|
||||||
|
name: "aux1",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
tableId: aux1Id!,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
fieldName: "table",
|
||||||
|
},
|
||||||
|
aux2: {
|
||||||
|
name: "aux2",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
tableId: aux2Id!,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
fieldName: "table",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// We need to refech them to get the updated foreign keys
|
||||||
|
aux1 = await config.api.table.get(aux1Id!)
|
||||||
|
aux2 = await config.api.table.get(aux2Id!)
|
||||||
|
table = await config.api.table.get(tableId!)
|
||||||
})
|
})
|
||||||
|
|
||||||
const { _id: tableId } = await config.api.table.save({
|
it("includes nested relationship fields from main table", async () => {
|
||||||
...structures.basicTable(),
|
const result = await config.doInContext(config.appId, () => {
|
||||||
schema: {
|
return getQueryableFields(Object.keys(table.schema), table)
|
||||||
name: { name: "name", type: FieldType.STRING },
|
})
|
||||||
aux1: {
|
expect(result).toEqual([
|
||||||
name: "aux1",
|
"_id",
|
||||||
type: FieldType.LINK,
|
"name",
|
||||||
tableId: aux1Id!,
|
// deep 1 aux1 primitive props
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
"aux1.name",
|
||||||
fieldName: "table",
|
"aux1Table.name",
|
||||||
},
|
|
||||||
aux2: {
|
// deep 2 aux1 primitive props
|
||||||
name: "aux2",
|
"aux1.aux2_1.title",
|
||||||
type: FieldType.LINK,
|
"aux1Table.aux2_1.title",
|
||||||
tableId: aux2Id!,
|
"aux1.aux2Table.title",
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
"aux1Table.aux2Table.title",
|
||||||
fieldName: "table",
|
|
||||||
},
|
// deep 2 aux2 primitive props
|
||||||
},
|
"aux1.aux2_2.title",
|
||||||
|
"aux1Table.aux2_2.title",
|
||||||
|
"aux1.aux2Table.title",
|
||||||
|
"aux1Table.aux2Table.title",
|
||||||
|
|
||||||
|
// deep 1 aux2 primitive props
|
||||||
|
"aux2.title",
|
||||||
|
"aux2Table.title",
|
||||||
|
|
||||||
|
// deep 2 aux2 primitive props
|
||||||
|
"aux2.aux1_1.name",
|
||||||
|
"aux2Table.aux1_1.name",
|
||||||
|
"aux2.aux1Table.name",
|
||||||
|
"aux2Table.aux1Table.name",
|
||||||
|
"aux2.aux1_2.name",
|
||||||
|
"aux2Table.aux1_2.name",
|
||||||
|
"aux2.aux1Table.name",
|
||||||
|
"aux2Table.aux1Table.name",
|
||||||
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
// We need to refech them to get the updated foreign keys
|
it("includes nested relationship fields from aux 1 table", async () => {
|
||||||
aux1 = await config.api.table.get(aux1Id!)
|
const result = await config.doInContext(config.appId, () => {
|
||||||
aux2 = await config.api.table.get(aux2Id!)
|
return getQueryableFields(Object.keys(aux1.schema), aux1)
|
||||||
table = await config.api.table.get(tableId!)
|
})
|
||||||
|
expect(result).toEqual([
|
||||||
|
"_id",
|
||||||
|
"name",
|
||||||
|
|
||||||
|
// deep 1 aux2_1 primitive props
|
||||||
|
"aux2_1.title",
|
||||||
|
"aux2Table.title",
|
||||||
|
|
||||||
|
// deep 2 aux2_1 primitive props
|
||||||
|
"aux2_1.table.name",
|
||||||
|
"aux2Table.table.name",
|
||||||
|
"aux2_1.TestTable.name",
|
||||||
|
"aux2Table.TestTable.name",
|
||||||
|
|
||||||
|
// deep 1 aux2_2 primitive props
|
||||||
|
"aux2_2.title",
|
||||||
|
"aux2Table.title",
|
||||||
|
|
||||||
|
// deep 2 aux2_2 primitive props
|
||||||
|
"aux2_2.table.name",
|
||||||
|
"aux2Table.table.name",
|
||||||
|
"aux2_2.TestTable.name",
|
||||||
|
"aux2Table.TestTable.name",
|
||||||
|
|
||||||
|
// deep 1 table primitive props
|
||||||
|
"table.name",
|
||||||
|
"TestTable.name",
|
||||||
|
|
||||||
|
// deep 2 table primitive props
|
||||||
|
"table.aux2.title",
|
||||||
|
"TestTable.aux2.title",
|
||||||
|
"table.aux2Table.title",
|
||||||
|
"TestTable.aux2Table.title",
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("includes nested relationship fields from aux 2 table", async () => {
|
||||||
|
const result = await config.doInContext(config.appId, () => {
|
||||||
|
return getQueryableFields(Object.keys(aux2.schema), aux2)
|
||||||
|
})
|
||||||
|
expect(result).toEqual([
|
||||||
|
"_id",
|
||||||
|
"title",
|
||||||
|
|
||||||
|
// deep 1 aux1_1 primitive props
|
||||||
|
"aux1_1.name",
|
||||||
|
"aux1Table.name",
|
||||||
|
|
||||||
|
// deep 2 aux1_1 primitive props
|
||||||
|
"aux1_1.table.name",
|
||||||
|
"aux1Table.table.name",
|
||||||
|
"aux1_1.TestTable.name",
|
||||||
|
"aux1Table.TestTable.name",
|
||||||
|
|
||||||
|
// deep 1 aux1_2 primitive props
|
||||||
|
"aux1_2.name",
|
||||||
|
"aux1Table.name",
|
||||||
|
|
||||||
|
// deep 2 aux1_2 primitive props
|
||||||
|
"aux1_2.table.name",
|
||||||
|
"aux1Table.table.name",
|
||||||
|
"aux1_2.TestTable.name",
|
||||||
|
"aux1Table.TestTable.name",
|
||||||
|
|
||||||
|
// deep 1 table primitive props
|
||||||
|
"table.name",
|
||||||
|
"TestTable.name",
|
||||||
|
|
||||||
|
// deep 2 table primitive props
|
||||||
|
"table.aux1.name",
|
||||||
|
"TestTable.aux1.name",
|
||||||
|
"table.aux1Table.name",
|
||||||
|
"TestTable.aux1Table.name",
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("includes nested relationship fields from main table", async () => {
|
describe("many-to-many", () => {
|
||||||
const result = await config.doInContext(config.appId, () => {
|
let table: Table, aux: Table
|
||||||
return getQueryableFields(Object.keys(table.schema), 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!)
|
||||||
})
|
})
|
||||||
expect(result).toEqual([
|
|
||||||
"_id",
|
|
||||||
"name",
|
|
||||||
// deep 1 aux1 primitive props
|
|
||||||
"aux1.name",
|
|
||||||
"aux1Table.name",
|
|
||||||
|
|
||||||
// deep 2 aux1 primitive props
|
it("includes nested relationship fields from main table", async () => {
|
||||||
"aux1.aux2_1.title",
|
const result = await config.doInContext(config.appId, () => {
|
||||||
"aux1Table.aux2_1.title",
|
return getQueryableFields(Object.keys(table.schema), table)
|
||||||
"aux1.aux2Table.title",
|
})
|
||||||
"aux1Table.aux2Table.title",
|
expect(result).toEqual([
|
||||||
|
"_id",
|
||||||
|
"name",
|
||||||
|
|
||||||
// deep 2 aux2 primitive props
|
// deep 1 aux primitive props
|
||||||
"aux1.aux2_2.title",
|
"aux.title",
|
||||||
"aux1Table.aux2_2.title",
|
"auxTable.title",
|
||||||
"aux1.aux2Table.title",
|
])
|
||||||
"aux1Table.aux2Table.title",
|
|
||||||
|
|
||||||
// deep 1 aux2 primitive props
|
|
||||||
"aux2.title",
|
|
||||||
"aux2Table.title",
|
|
||||||
|
|
||||||
// deep 2 aux2 primitive props
|
|
||||||
"aux2.aux1_1.name",
|
|
||||||
"aux2Table.aux1_1.name",
|
|
||||||
"aux2.aux1Table.name",
|
|
||||||
"aux2Table.aux1Table.name",
|
|
||||||
"aux2.aux1_2.name",
|
|
||||||
"aux2Table.aux1_2.name",
|
|
||||||
"aux2.aux1Table.name",
|
|
||||||
"aux2Table.aux1Table.name",
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("includes nested relationship fields from aux 1 table", async () => {
|
|
||||||
const result = await config.doInContext(config.appId, () => {
|
|
||||||
return getQueryableFields(Object.keys(aux1.schema), aux1)
|
|
||||||
})
|
})
|
||||||
expect(result).toEqual([
|
|
||||||
"_id",
|
|
||||||
"name",
|
|
||||||
|
|
||||||
// deep 1 aux2_1 primitive props
|
it("includes nested relationship fields from aux table", async () => {
|
||||||
"aux2_1.title",
|
const result = await config.doInContext(config.appId, () => {
|
||||||
"aux2Table.title",
|
return getQueryableFields(Object.keys(aux.schema), aux)
|
||||||
|
})
|
||||||
|
expect(result).toEqual([
|
||||||
|
"_id",
|
||||||
|
"title",
|
||||||
|
|
||||||
// deep 2 aux2_1 primitive props
|
// deep 1 dependency primitive props
|
||||||
"aux2_1.table.name",
|
"table.name",
|
||||||
"aux2Table.table.name",
|
"TestTable.name",
|
||||||
"aux2_1.TestTable.name",
|
])
|
||||||
"aux2Table.TestTable.name",
|
|
||||||
|
|
||||||
// deep 1 aux2_2 primitive props
|
|
||||||
"aux2_2.title",
|
|
||||||
"aux2Table.title",
|
|
||||||
|
|
||||||
// deep 2 aux2_2 primitive props
|
|
||||||
"aux2_2.table.name",
|
|
||||||
"aux2Table.table.name",
|
|
||||||
"aux2_2.TestTable.name",
|
|
||||||
"aux2Table.TestTable.name",
|
|
||||||
|
|
||||||
// deep 1 table primitive props
|
|
||||||
"table.name",
|
|
||||||
"TestTable.name",
|
|
||||||
|
|
||||||
// deep 2 table primitive props
|
|
||||||
"table.aux2.title",
|
|
||||||
"TestTable.aux2.title",
|
|
||||||
"table.aux2Table.title",
|
|
||||||
"TestTable.aux2Table.title",
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("includes nested relationship fields from aux 2 table", async () => {
|
|
||||||
const result = await config.doInContext(config.appId, () => {
|
|
||||||
return getQueryableFields(Object.keys(aux2.schema), aux2)
|
|
||||||
})
|
})
|
||||||
expect(result).toEqual([
|
|
||||||
"_id",
|
|
||||||
"title",
|
|
||||||
|
|
||||||
// deep 1 aux1_1 primitive props
|
|
||||||
"aux1_1.name",
|
|
||||||
"aux1Table.name",
|
|
||||||
|
|
||||||
// deep 2 aux1_1 primitive props
|
|
||||||
"aux1_1.table.name",
|
|
||||||
"aux1Table.table.name",
|
|
||||||
"aux1_1.TestTable.name",
|
|
||||||
"aux1Table.TestTable.name",
|
|
||||||
|
|
||||||
// deep 1 aux1_2 primitive props
|
|
||||||
"aux1_2.name",
|
|
||||||
"aux1Table.name",
|
|
||||||
|
|
||||||
// deep 2 aux1_2 primitive props
|
|
||||||
"aux1_2.table.name",
|
|
||||||
"aux1Table.table.name",
|
|
||||||
"aux1_2.TestTable.name",
|
|
||||||
"aux1Table.TestTable.name",
|
|
||||||
|
|
||||||
// deep 1 table primitive props
|
|
||||||
"table.name",
|
|
||||||
"TestTable.name",
|
|
||||||
|
|
||||||
// deep 2 table primitive props
|
|
||||||
"table.aux1.name",
|
|
||||||
"TestTable.aux1.name",
|
|
||||||
"table.aux1Table.name",
|
|
||||||
"TestTable.aux1Table.name",
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue