Move more view tests out of row.spec.ts
This commit is contained in:
parent
850fb3d4ec
commit
3b68873fc4
|
@ -719,49 +719,6 @@ describe.each([
|
|||
})
|
||||
})
|
||||
|
||||
// Legacy views are not available for external
|
||||
isInternal &&
|
||||
describe("fetchView", () => {
|
||||
beforeEach(async () => {
|
||||
table = await config.api.table.save(defaultTable())
|
||||
})
|
||||
|
||||
it("should be able to fetch tables contents via 'view'", async () => {
|
||||
const row = await config.api.row.save(table._id!, {})
|
||||
const rowUsage = await getRowUsage()
|
||||
|
||||
const rows = await config.api.legacyView.get(table._id!)
|
||||
expect(rows.length).toEqual(1)
|
||||
expect(rows[0]._id).toEqual(row._id)
|
||||
await assertRowUsage(rowUsage)
|
||||
})
|
||||
|
||||
it("should throw an error if view doesn't exist", async () => {
|
||||
const rowUsage = await getRowUsage()
|
||||
|
||||
await config.api.legacyView.get("derp", undefined, { status: 404 })
|
||||
|
||||
await assertRowUsage(rowUsage)
|
||||
})
|
||||
|
||||
it("should be able to run on a view", async () => {
|
||||
const view = await config.createLegacyView({
|
||||
tableId: table._id!,
|
||||
name: "ViewTest",
|
||||
filters: [],
|
||||
schema: {},
|
||||
})
|
||||
const row = await config.api.row.save(table._id!, {})
|
||||
const rowUsage = await getRowUsage()
|
||||
|
||||
const rows = await config.api.legacyView.get(view.name)
|
||||
expect(rows.length).toEqual(1)
|
||||
expect(rows[0]._id).toEqual(row._id)
|
||||
|
||||
await assertRowUsage(rowUsage)
|
||||
})
|
||||
})
|
||||
|
||||
describe("fetchEnrichedRows", () => {
|
||||
beforeAll(async () => {
|
||||
table = await config.api.table.save(defaultTable())
|
||||
|
|
|
@ -3,12 +3,15 @@ import * as setup from "./utilities"
|
|||
import {
|
||||
FieldType,
|
||||
INTERNAL_TABLE_SOURCE_ID,
|
||||
QuotaUsageType,
|
||||
SaveTableRequest,
|
||||
StaticQuotaName,
|
||||
Table,
|
||||
TableSourceType,
|
||||
View,
|
||||
ViewCalculation,
|
||||
} from "@budibase/types"
|
||||
import { quotas } from "@budibase/pro"
|
||||
|
||||
const priceTable: SaveTableRequest = {
|
||||
name: "table",
|
||||
|
@ -57,6 +60,18 @@ describe("/views", () => {
|
|||
return config.api.legacyView.save(viewToSave)
|
||||
}
|
||||
|
||||
const getRowUsage = async () => {
|
||||
const { total } = await config.doInContext(undefined, () =>
|
||||
quotas.getCurrentUsageValues(QuotaUsageType.STATIC, StaticQuotaName.ROWS)
|
||||
)
|
||||
return total
|
||||
}
|
||||
|
||||
const assertRowUsage = async (expected: number) => {
|
||||
const usage = await getRowUsage()
|
||||
expect(usage).toBe(expected)
|
||||
}
|
||||
|
||||
describe("create", () => {
|
||||
it("returns a success message when the view is successfully created", async () => {
|
||||
const res = await saveView()
|
||||
|
@ -265,6 +280,41 @@ describe("/views", () => {
|
|||
expect(views.length).toBe(1)
|
||||
expect(views.find(({ name }) => name === "TestView")).toBeDefined()
|
||||
})
|
||||
|
||||
it("should be able to fetch tables contents via 'view'", async () => {
|
||||
const row = await config.api.row.save(table._id!, {})
|
||||
const rowUsage = await getRowUsage()
|
||||
|
||||
const rows = await config.api.legacyView.get(table._id!)
|
||||
expect(rows.length).toEqual(1)
|
||||
expect(rows[0]._id).toEqual(row._id)
|
||||
await assertRowUsage(rowUsage)
|
||||
})
|
||||
|
||||
it("should throw an error if view doesn't exist", async () => {
|
||||
const rowUsage = await getRowUsage()
|
||||
|
||||
await config.api.legacyView.get("derp", undefined, { status: 404 })
|
||||
|
||||
await assertRowUsage(rowUsage)
|
||||
})
|
||||
|
||||
it("should be able to run on a view", async () => {
|
||||
const view = await config.api.legacyView.save({
|
||||
tableId: table._id!,
|
||||
name: "ViewTest",
|
||||
filters: [],
|
||||
schema: {},
|
||||
})
|
||||
const row = await config.api.row.save(table._id!, {})
|
||||
const rowUsage = await getRowUsage()
|
||||
|
||||
const rows = await config.api.legacyView.get(view.name!)
|
||||
expect(rows.length).toEqual(1)
|
||||
expect(rows[0]._id).toEqual(row._id)
|
||||
|
||||
await assertRowUsage(rowUsage)
|
||||
})
|
||||
})
|
||||
|
||||
describe("query", () => {
|
||||
|
|
Loading…
Reference in New Issue