Add describe
This commit is contained in:
parent
96bddbb545
commit
e23753ac61
|
@ -34,224 +34,238 @@ describe("buildSqlFieldList", () => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
it("extracts fields from table schema", async () => {
|
describe("table", () => {
|
||||||
const result = await buildSqlFieldList(basicTable, {})
|
it("extracts fields from table schema", async () => {
|
||||||
expect(result).toEqual(["table.name", "table.description", "table.amount"])
|
const result = await buildSqlFieldList(basicTable, {})
|
||||||
})
|
expect(result).toEqual([
|
||||||
|
"table.name",
|
||||||
it("excludes hidden fields", async () => {
|
"table.description",
|
||||||
const table = cloneDeep(basicTable)
|
"table.amount",
|
||||||
table.schema.description.visible = false
|
])
|
||||||
const result = await buildSqlFieldList(table, {})
|
|
||||||
expect(result).toEqual(["table.name", "table.amount"])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("excludes non-sql fields fields", async () => {
|
|
||||||
const table = cloneDeep(basicTable)
|
|
||||||
table.schema.formula = {
|
|
||||||
name: "formula",
|
|
||||||
type: FieldType.FORMULA,
|
|
||||||
formula: "any",
|
|
||||||
}
|
|
||||||
table.schema.ai = {
|
|
||||||
name: "ai",
|
|
||||||
type: FieldType.AI,
|
|
||||||
operation: AIOperationEnum.PROMPT,
|
|
||||||
}
|
|
||||||
table.schema.link = {
|
|
||||||
name: "link",
|
|
||||||
type: FieldType.LINK,
|
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
|
||||||
fieldName: "link",
|
|
||||||
tableId: "otherTableId",
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await buildSqlFieldList(table, {})
|
|
||||||
expect(result).toEqual(["table.name", "table.description", "table.amount"])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("includes hidden fields if there is a formula column", async () => {
|
|
||||||
const table = cloneDeep(basicTable)
|
|
||||||
table.schema.description.visible = false
|
|
||||||
table.schema.formula = {
|
|
||||||
name: "formula",
|
|
||||||
type: FieldType.FORMULA,
|
|
||||||
formula: "any",
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await buildSqlFieldList(table, {})
|
|
||||||
expect(result).toEqual(["table.name", "table.description", "table.amount"])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("includes relationships fields when flag", async () => {
|
|
||||||
const table = cloneDeep(basicTable)
|
|
||||||
table.schema.link = {
|
|
||||||
name: "link",
|
|
||||||
type: FieldType.LINK,
|
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
|
||||||
fieldName: "link",
|
|
||||||
tableId: sql.utils.buildExternalTableId("ds_id", "otherTableId"),
|
|
||||||
}
|
|
||||||
|
|
||||||
const otherTable: Table = {
|
|
||||||
...cloneDeep(basicTable),
|
|
||||||
name: "linkedTable",
|
|
||||||
primary: ["id"],
|
|
||||||
primaryDisplay: "name",
|
|
||||||
schema: {
|
|
||||||
...cloneDeep(basicTable).schema,
|
|
||||||
id: {
|
|
||||||
name: "id",
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const allTables: Record<string, Table> = {
|
|
||||||
otherTableId: otherTable,
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await buildSqlFieldList(table, allTables, {
|
|
||||||
relationships: true,
|
|
||||||
})
|
})
|
||||||
expect(result).toEqual([
|
|
||||||
"table.name",
|
|
||||||
"table.description",
|
|
||||||
"table.amount",
|
|
||||||
"linkedTable.id",
|
|
||||||
"linkedTable.name",
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("includes all relationship fields if there is a formula column", async () => {
|
it("excludes hidden fields", async () => {
|
||||||
const table = cloneDeep(basicTable)
|
const table = cloneDeep(basicTable)
|
||||||
table.schema.link = {
|
table.schema.description.visible = false
|
||||||
name: "link",
|
const result = await buildSqlFieldList(table, {})
|
||||||
type: FieldType.LINK,
|
expect(result).toEqual(["table.name", "table.amount"])
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
|
||||||
fieldName: "link",
|
|
||||||
tableId: sql.utils.buildExternalTableId("ds_id", "otherTableId"),
|
|
||||||
}
|
|
||||||
table.schema.formula = {
|
|
||||||
name: "formula",
|
|
||||||
type: FieldType.FORMULA,
|
|
||||||
formula: "any",
|
|
||||||
}
|
|
||||||
|
|
||||||
const otherTable: Table = {
|
|
||||||
...cloneDeep(basicTable),
|
|
||||||
name: "linkedTable",
|
|
||||||
schema: {
|
|
||||||
...cloneDeep(basicTable).schema,
|
|
||||||
id: {
|
|
||||||
name: "id",
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
},
|
|
||||||
hidden: {
|
|
||||||
name: "other",
|
|
||||||
type: FieldType.STRING,
|
|
||||||
visible: false,
|
|
||||||
},
|
|
||||||
formula: {
|
|
||||||
name: "formula",
|
|
||||||
type: FieldType.FORMULA,
|
|
||||||
formula: "any",
|
|
||||||
},
|
|
||||||
ai: {
|
|
||||||
name: "ai",
|
|
||||||
type: FieldType.AI,
|
|
||||||
operation: AIOperationEnum.PROMPT,
|
|
||||||
},
|
|
||||||
link: {
|
|
||||||
name: "link",
|
|
||||||
type: FieldType.LINK,
|
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
|
||||||
fieldName: "link",
|
|
||||||
tableId: "otherTableId",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const allTables: Record<string, Table> = {
|
|
||||||
otherTableId: otherTable,
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await buildSqlFieldList(table, allTables, {
|
|
||||||
relationships: true,
|
|
||||||
})
|
})
|
||||||
expect(result).toEqual([
|
|
||||||
"table.name",
|
|
||||||
"table.description",
|
|
||||||
"table.amount",
|
|
||||||
"linkedTable.name",
|
|
||||||
"linkedTable.description",
|
|
||||||
"linkedTable.amount",
|
|
||||||
"linkedTable.id",
|
|
||||||
"linkedTable.hidden",
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("never includes non-sql columns from relationships", async () => {
|
it("excludes non-sql fields fields", async () => {
|
||||||
const table = cloneDeep(basicTable)
|
const table = cloneDeep(basicTable)
|
||||||
table.schema.link = {
|
table.schema.formula = {
|
||||||
name: "link",
|
name: "formula",
|
||||||
type: FieldType.LINK,
|
type: FieldType.FORMULA,
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
formula: "any",
|
||||||
fieldName: "link",
|
}
|
||||||
tableId: sql.utils.buildExternalTableId("ds_id", "otherTableId"),
|
table.schema.ai = {
|
||||||
}
|
name: "ai",
|
||||||
table.schema.formula = {
|
type: FieldType.AI,
|
||||||
name: "formula",
|
operation: AIOperationEnum.PROMPT,
|
||||||
type: FieldType.FORMULA,
|
}
|
||||||
formula: "any",
|
table.schema.link = {
|
||||||
}
|
name: "link",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
fieldName: "link",
|
||||||
|
tableId: "otherTableId",
|
||||||
|
}
|
||||||
|
|
||||||
const otherTable: Table = {
|
const result = await buildSqlFieldList(table, {})
|
||||||
...cloneDeep(basicTable),
|
expect(result).toEqual([
|
||||||
name: "linkedTable",
|
"table.name",
|
||||||
schema: {
|
"table.description",
|
||||||
id: {
|
"table.amount",
|
||||||
name: "id",
|
])
|
||||||
type: FieldType.NUMBER,
|
})
|
||||||
},
|
|
||||||
hidden: {
|
it("includes hidden fields if there is a formula column", async () => {
|
||||||
name: "other",
|
const table = cloneDeep(basicTable)
|
||||||
type: FieldType.STRING,
|
table.schema.description.visible = false
|
||||||
visible: false,
|
table.schema.formula = {
|
||||||
},
|
name: "formula",
|
||||||
formula: {
|
type: FieldType.FORMULA,
|
||||||
name: "formula",
|
formula: "any",
|
||||||
type: FieldType.FORMULA,
|
}
|
||||||
formula: "any",
|
|
||||||
},
|
const result = await buildSqlFieldList(table, {})
|
||||||
ai: {
|
expect(result).toEqual([
|
||||||
name: "ai",
|
"table.name",
|
||||||
type: FieldType.AI,
|
"table.description",
|
||||||
operation: AIOperationEnum.PROMPT,
|
"table.amount",
|
||||||
},
|
])
|
||||||
link: {
|
})
|
||||||
name: "link",
|
|
||||||
type: FieldType.LINK,
|
it("includes relationships fields when flag", async () => {
|
||||||
relationshipType: RelationshipType.ONE_TO_MANY,
|
const table = cloneDeep(basicTable)
|
||||||
fieldName: "link",
|
table.schema.link = {
|
||||||
tableId: "otherTableId",
|
name: "link",
|
||||||
},
|
type: FieldType.LINK,
|
||||||
},
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
}
|
fieldName: "link",
|
||||||
|
tableId: sql.utils.buildExternalTableId("ds_id", "otherTableId"),
|
||||||
const allTables: Record<string, Table> = {
|
}
|
||||||
otherTableId: otherTable,
|
|
||||||
}
|
const otherTable: Table = {
|
||||||
|
...cloneDeep(basicTable),
|
||||||
const result = await buildSqlFieldList(table, allTables, {
|
name: "linkedTable",
|
||||||
relationships: true,
|
primary: ["id"],
|
||||||
|
primaryDisplay: "name",
|
||||||
|
schema: {
|
||||||
|
...cloneDeep(basicTable).schema,
|
||||||
|
id: {
|
||||||
|
name: "id",
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const allTables: Record<string, Table> = {
|
||||||
|
otherTableId: otherTable,
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await buildSqlFieldList(table, allTables, {
|
||||||
|
relationships: true,
|
||||||
|
})
|
||||||
|
expect(result).toEqual([
|
||||||
|
"table.name",
|
||||||
|
"table.description",
|
||||||
|
"table.amount",
|
||||||
|
"linkedTable.id",
|
||||||
|
"linkedTable.name",
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("includes all relationship fields if there is a formula column", async () => {
|
||||||
|
const table = cloneDeep(basicTable)
|
||||||
|
table.schema.link = {
|
||||||
|
name: "link",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
fieldName: "link",
|
||||||
|
tableId: sql.utils.buildExternalTableId("ds_id", "otherTableId"),
|
||||||
|
}
|
||||||
|
table.schema.formula = {
|
||||||
|
name: "formula",
|
||||||
|
type: FieldType.FORMULA,
|
||||||
|
formula: "any",
|
||||||
|
}
|
||||||
|
|
||||||
|
const otherTable: Table = {
|
||||||
|
...cloneDeep(basicTable),
|
||||||
|
name: "linkedTable",
|
||||||
|
schema: {
|
||||||
|
...cloneDeep(basicTable).schema,
|
||||||
|
id: {
|
||||||
|
name: "id",
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
},
|
||||||
|
hidden: {
|
||||||
|
name: "other",
|
||||||
|
type: FieldType.STRING,
|
||||||
|
visible: false,
|
||||||
|
},
|
||||||
|
formula: {
|
||||||
|
name: "formula",
|
||||||
|
type: FieldType.FORMULA,
|
||||||
|
formula: "any",
|
||||||
|
},
|
||||||
|
ai: {
|
||||||
|
name: "ai",
|
||||||
|
type: FieldType.AI,
|
||||||
|
operation: AIOperationEnum.PROMPT,
|
||||||
|
},
|
||||||
|
link: {
|
||||||
|
name: "link",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
fieldName: "link",
|
||||||
|
tableId: "otherTableId",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const allTables: Record<string, Table> = {
|
||||||
|
otherTableId: otherTable,
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await buildSqlFieldList(table, allTables, {
|
||||||
|
relationships: true,
|
||||||
|
})
|
||||||
|
expect(result).toEqual([
|
||||||
|
"table.name",
|
||||||
|
"table.description",
|
||||||
|
"table.amount",
|
||||||
|
"linkedTable.name",
|
||||||
|
"linkedTable.description",
|
||||||
|
"linkedTable.amount",
|
||||||
|
"linkedTable.id",
|
||||||
|
"linkedTable.hidden",
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("never includes non-sql columns from relationships", async () => {
|
||||||
|
const table = cloneDeep(basicTable)
|
||||||
|
table.schema.link = {
|
||||||
|
name: "link",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
fieldName: "link",
|
||||||
|
tableId: sql.utils.buildExternalTableId("ds_id", "otherTableId"),
|
||||||
|
}
|
||||||
|
table.schema.formula = {
|
||||||
|
name: "formula",
|
||||||
|
type: FieldType.FORMULA,
|
||||||
|
formula: "any",
|
||||||
|
}
|
||||||
|
|
||||||
|
const otherTable: Table = {
|
||||||
|
...cloneDeep(basicTable),
|
||||||
|
name: "linkedTable",
|
||||||
|
schema: {
|
||||||
|
id: {
|
||||||
|
name: "id",
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
},
|
||||||
|
hidden: {
|
||||||
|
name: "other",
|
||||||
|
type: FieldType.STRING,
|
||||||
|
visible: false,
|
||||||
|
},
|
||||||
|
formula: {
|
||||||
|
name: "formula",
|
||||||
|
type: FieldType.FORMULA,
|
||||||
|
formula: "any",
|
||||||
|
},
|
||||||
|
ai: {
|
||||||
|
name: "ai",
|
||||||
|
type: FieldType.AI,
|
||||||
|
operation: AIOperationEnum.PROMPT,
|
||||||
|
},
|
||||||
|
link: {
|
||||||
|
name: "link",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
fieldName: "link",
|
||||||
|
tableId: "otherTableId",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const allTables: Record<string, Table> = {
|
||||||
|
otherTableId: otherTable,
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await buildSqlFieldList(table, allTables, {
|
||||||
|
relationships: true,
|
||||||
|
})
|
||||||
|
expect(result).toEqual([
|
||||||
|
"table.name",
|
||||||
|
"table.description",
|
||||||
|
"table.amount",
|
||||||
|
"linkedTable.id",
|
||||||
|
"linkedTable.hidden",
|
||||||
|
])
|
||||||
})
|
})
|
||||||
expect(result).toEqual([
|
|
||||||
"table.name",
|
|
||||||
"table.description",
|
|
||||||
"table.amount",
|
|
||||||
"linkedTable.id",
|
|
||||||
"linkedTable.hidden",
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue