Legacy views tests
This commit is contained in:
parent
93e9b1b8b4
commit
9e799c6b93
|
@ -710,55 +710,62 @@ describe.each([
|
|||
})
|
||||
})
|
||||
|
||||
describe("fetchView", () => {
|
||||
it("should be able to fetch tables contents via 'view'", async () => {
|
||||
const row = await config.createRow()
|
||||
const rowUsage = await getRowUsage()
|
||||
const queryUsage = await getQueryUsage()
|
||||
// Legacy views are not available for external
|
||||
isInternal &&
|
||||
describe("fetchView", () => {
|
||||
it("should be able to fetch tables contents via 'view'", async () => {
|
||||
const row = await createRow()
|
||||
const rowUsage = await getRowUsage()
|
||||
const queryUsage = await getQueryUsage()
|
||||
|
||||
const res = await request
|
||||
.get(`/api/views/${table._id}`)
|
||||
.set(config.defaultHeaders())
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(200)
|
||||
expect(res.body.length).toEqual(1)
|
||||
expect(res.body[0]._id).toEqual(row._id)
|
||||
await assertRowUsage(rowUsage)
|
||||
await assertQueryUsage(queryUsage + 1)
|
||||
const res = await request
|
||||
.get(`/api/views/${table._id}`)
|
||||
.set(config.defaultHeaders())
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(200)
|
||||
expect(res.body.length).toEqual(1)
|
||||
expect(res.body[0]._id).toEqual(row._id)
|
||||
await assertRowUsage(rowUsage)
|
||||
await assertQueryUsage(queryUsage + 1)
|
||||
})
|
||||
|
||||
it("should throw an error if view doesn't exist", async () => {
|
||||
const rowUsage = await getRowUsage()
|
||||
const queryUsage = await getQueryUsage()
|
||||
|
||||
await request
|
||||
.get(`/api/views/derp`)
|
||||
.set(config.defaultHeaders())
|
||||
.expect(404)
|
||||
|
||||
await assertRowUsage(rowUsage)
|
||||
await assertQueryUsage(queryUsage)
|
||||
})
|
||||
|
||||
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 createRow()
|
||||
const rowUsage = await getRowUsage()
|
||||
const queryUsage = await getQueryUsage()
|
||||
|
||||
const res = await request
|
||||
.get(`/api/views/${view.name}`)
|
||||
.set(config.defaultHeaders())
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(200)
|
||||
expect(res.body.length).toEqual(1)
|
||||
expect(res.body[0]._id).toEqual(row._id)
|
||||
|
||||
await assertRowUsage(rowUsage)
|
||||
await assertQueryUsage(queryUsage + 1)
|
||||
})
|
||||
})
|
||||
|
||||
it("should throw an error if view doesn't exist", async () => {
|
||||
const rowUsage = await getRowUsage()
|
||||
const queryUsage = await getQueryUsage()
|
||||
|
||||
await request
|
||||
.get(`/api/views/derp`)
|
||||
.set(config.defaultHeaders())
|
||||
.expect(404)
|
||||
|
||||
await assertRowUsage(rowUsage)
|
||||
await assertQueryUsage(queryUsage)
|
||||
})
|
||||
|
||||
it("should be able to run on a view", async () => {
|
||||
const view = await config.createLegacyView()
|
||||
const row = await config.createRow()
|
||||
const rowUsage = await getRowUsage()
|
||||
const queryUsage = await getQueryUsage()
|
||||
|
||||
const res = await request
|
||||
.get(`/api/views/${view.name}`)
|
||||
.set(config.defaultHeaders())
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(200)
|
||||
expect(res.body.length).toEqual(1)
|
||||
expect(res.body[0]._id).toEqual(row._id)
|
||||
|
||||
await assertRowUsage(rowUsage)
|
||||
await assertQueryUsage(queryUsage + 1)
|
||||
})
|
||||
})
|
||||
|
||||
describe("fetchEnrichedRows", () => {
|
||||
it("should allow enriching some linked rows", async () => {
|
||||
const { table, firstRow, secondRow } = await tenancy.doInTenant(
|
||||
|
|
|
@ -50,6 +50,7 @@ import {
|
|||
SearchFilters,
|
||||
UserRoles,
|
||||
Automation,
|
||||
View,
|
||||
} from "@budibase/types"
|
||||
|
||||
import API from "./api"
|
||||
|
@ -629,12 +630,12 @@ class TestConfiguration {
|
|||
|
||||
// VIEW
|
||||
|
||||
async createLegacyView(config?: any) {
|
||||
if (!this.table) {
|
||||
async createLegacyView(config?: View) {
|
||||
if (!this.table && !config) {
|
||||
throw "Test requires table to be configured."
|
||||
}
|
||||
const view = config || {
|
||||
tableId: this.table._id,
|
||||
tableId: this.table!._id,
|
||||
name: "ViewTest",
|
||||
}
|
||||
return this._req(view, null, controllers.view.v1.save)
|
||||
|
|
Loading…
Reference in New Issue