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", () => {
|
describe("fetchEnrichedRows", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
table = await config.api.table.save(defaultTable())
|
table = await config.api.table.save(defaultTable())
|
||||||
|
|
|
@ -3,12 +3,15 @@ import * as setup from "./utilities"
|
||||||
import {
|
import {
|
||||||
FieldType,
|
FieldType,
|
||||||
INTERNAL_TABLE_SOURCE_ID,
|
INTERNAL_TABLE_SOURCE_ID,
|
||||||
|
QuotaUsageType,
|
||||||
SaveTableRequest,
|
SaveTableRequest,
|
||||||
|
StaticQuotaName,
|
||||||
Table,
|
Table,
|
||||||
TableSourceType,
|
TableSourceType,
|
||||||
View,
|
View,
|
||||||
ViewCalculation,
|
ViewCalculation,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
import { quotas } from "@budibase/pro"
|
||||||
|
|
||||||
const priceTable: SaveTableRequest = {
|
const priceTable: SaveTableRequest = {
|
||||||
name: "table",
|
name: "table",
|
||||||
|
@ -57,6 +60,18 @@ describe("/views", () => {
|
||||||
return config.api.legacyView.save(viewToSave)
|
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", () => {
|
describe("create", () => {
|
||||||
it("returns a success message when the view is successfully created", async () => {
|
it("returns a success message when the view is successfully created", async () => {
|
||||||
const res = await saveView()
|
const res = await saveView()
|
||||||
|
@ -265,6 +280,41 @@ describe("/views", () => {
|
||||||
expect(views.length).toBe(1)
|
expect(views.length).toBe(1)
|
||||||
expect(views.find(({ name }) => name === "TestView")).toBeDefined()
|
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", () => {
|
describe("query", () => {
|
||||||
|
|
Loading…
Reference in New Issue