Add calculation tests
This commit is contained in:
parent
9396292c4a
commit
92e791f9a7
|
@ -1,10 +1,12 @@
|
||||||
import {
|
import {
|
||||||
AIOperationEnum,
|
AIOperationEnum,
|
||||||
|
CalculationType,
|
||||||
FieldType,
|
FieldType,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
SourceName,
|
SourceName,
|
||||||
Table,
|
Table,
|
||||||
ViewV2,
|
ViewV2,
|
||||||
|
ViewV2Type,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { buildSqlFieldList } from "../sqlUtils"
|
import { buildSqlFieldList } from "../sqlUtils"
|
||||||
import { structures } from "../../../../routes/tests/utilities"
|
import { structures } from "../../../../routes/tests/utilities"
|
||||||
|
@ -166,6 +168,21 @@ describe("buildSqlFieldList", () => {
|
||||||
return this
|
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() {
|
create() {
|
||||||
getTableMock.mockResolvedValueOnce(this._table)
|
getTableMock.mockResolvedValueOnce(this._table)
|
||||||
return cloneDeep(this._view)
|
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"])
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue