Add describe
This commit is contained in:
parent
96bddbb545
commit
e23753ac61
|
@ -34,224 +34,238 @@ describe("buildSqlFieldList", () => {
|
|||
},
|
||||
}
|
||||
|
||||
it("extracts fields from table schema", async () => {
|
||||
const result = await buildSqlFieldList(basicTable, {})
|
||||
expect(result).toEqual(["table.name", "table.description", "table.amount"])
|
||||
})
|
||||
|
||||
it("excludes hidden fields", async () => {
|
||||
const table = cloneDeep(basicTable)
|
||||
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,
|
||||
describe("table", () => {
|
||||
it("extracts fields from table schema", async () => {
|
||||
const result = await buildSqlFieldList(basicTable, {})
|
||||
expect(result).toEqual([
|
||||
"table.name",
|
||||
"table.description",
|
||||
"table.amount",
|
||||
])
|
||||
})
|
||||
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,
|
||||
it("excludes hidden fields", async () => {
|
||||
const table = cloneDeep(basicTable)
|
||||
table.schema.description.visible = false
|
||||
const result = await buildSqlFieldList(table, {})
|
||||
expect(result).toEqual(["table.name", "table.amount"])
|
||||
})
|
||||
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",
|
||||
}
|
||||
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 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,
|
||||
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 () => {
|
||||
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