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