Add calculation tests

This commit is contained in:
Adria Navarro 2024-12-19 12:48:33 +01:00
parent 9396292c4a
commit 92e791f9a7
1 changed files with 41 additions and 0 deletions

View File

@ -1,10 +1,12 @@
import {
AIOperationEnum,
CalculationType,
FieldType,
RelationshipType,
SourceName,
Table,
ViewV2,
ViewV2Type,
} from "@budibase/types"
import { buildSqlFieldList } from "../sqlUtils"
import { structures } from "../../../../routes/tests/utilities"
@ -166,6 +168,21 @@ describe("buildSqlFieldList", () => {
return this
}
withCalculation(
name: string,
field: string,
calculationType: CalculationType
) {
this._view.type = ViewV2Type.CALCULATION
this._view.schema ??= {}
this._view.schema[name] = {
field,
calculationType,
visible: true,
}
return this
}
create() {
getTableMock.mockResolvedValueOnce(this._table)
return cloneDeep(this._view)
@ -471,4 +488,28 @@ describe("buildSqlFieldList", () => {
])
})
})
describe("calculation view", () => {
it("does not include calculation fields", async () => {
const view = new ViewConfig(new TableConfig("table").create())
.withCalculation("average", "amount", CalculationType.AVG)
.create()
const result = await buildSqlFieldList(view, {})
expect(result).toEqual([])
})
it("includes visible fields calculation fields", async () => {
const view = new ViewConfig(new TableConfig("table").create())
.withCalculation("average", "amount", CalculationType.AVG)
.withHidden("name")
.withVisible("amount")
.create()
const result = await buildSqlFieldList(view, {})
expect(result).toEqual(["table.amount"])
})
})
})