Persist queries on crud views
This commit is contained in:
parent
6809bb4510
commit
ebd93eb109
|
@ -53,7 +53,9 @@ describe("/v2/views", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("can filter by table id", async () => {
|
it("can filter by table id", async () => {
|
||||||
const newTable = await config.createTable(priceTable())
|
const newTable = await config.createTable(priceTable(), {
|
||||||
|
skipReassigning: true,
|
||||||
|
})
|
||||||
const newViews = []
|
const newViews = []
|
||||||
for (let id = 0; id < 5; id++) {
|
for (let id = 0; id < 5; id++) {
|
||||||
newViews.push(await config.api.viewV2.create({ tableId: newTable._id }))
|
newViews.push(await config.api.viewV2.create({ tableId: newTable._id }))
|
||||||
|
@ -79,12 +81,32 @@ describe("/v2/views", () => {
|
||||||
|
|
||||||
expect(res.body.message).toBe("tableId type is not valid")
|
expect(res.body.message).toBe("tableId type is not valid")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("returns views with query info", async () => {
|
||||||
|
const newView = await config.api.viewV2.create({
|
||||||
|
query: { allOr: false, equal: { field: "value" } },
|
||||||
|
})
|
||||||
|
views.push(newView)
|
||||||
|
const res = await request
|
||||||
|
.get(`/api/v2/views?tableId=${config.table!._id}`)
|
||||||
|
.set(config.defaultHeaders())
|
||||||
|
.expect("Content-Type", /json/)
|
||||||
|
.expect(200)
|
||||||
|
|
||||||
|
expect(res.body.views.length).toBe(11)
|
||||||
|
expect(newView.query).toEqual({ allOr: false, equal: { field: "value" } })
|
||||||
|
expect(res.body.views).toEqual(
|
||||||
|
expect.arrayContaining([expect.objectContaining(newView)])
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("getView", () => {
|
describe("getView", () => {
|
||||||
let view: ViewV2
|
let view: ViewV2
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
view = await config.api.viewV2.create()
|
view = await config.api.viewV2.create({
|
||||||
|
query: { allOr: false, notEqual: { field: "value" } },
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("can fetch the expected view", async () => {
|
it("can fetch the expected view", async () => {
|
||||||
|
@ -123,6 +145,30 @@ describe("/v2/views", () => {
|
||||||
_rev: expect.any(String),
|
_rev: expect.any(String),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("can persist views with queries", async () => {
|
||||||
|
const query = { allOr: false, notContains: { name: ["a", "b"] } }
|
||||||
|
const newView: ViewV2 = {
|
||||||
|
name: generator.name(),
|
||||||
|
tableId: config.table!._id!,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
const res = await request
|
||||||
|
.post(`/api/v2/views`)
|
||||||
|
.send(newView)
|
||||||
|
.set(config.defaultHeaders())
|
||||||
|
.expect("Content-Type", /json/)
|
||||||
|
.expect(201)
|
||||||
|
|
||||||
|
expect(res.body).toEqual({
|
||||||
|
data: {
|
||||||
|
...newView,
|
||||||
|
query,
|
||||||
|
_id: expect.any(String),
|
||||||
|
_rev: expect.any(String),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("delete", () => {
|
describe("delete", () => {
|
||||||
|
|
|
@ -527,17 +527,23 @@ class TestConfiguration {
|
||||||
|
|
||||||
// TABLE
|
// TABLE
|
||||||
|
|
||||||
async updateTable(config?: any): Promise<Table> {
|
async updateTable(
|
||||||
|
config?: any,
|
||||||
|
{ skipReassigning } = { skipReassigning: false }
|
||||||
|
): Promise<Table> {
|
||||||
config = config || basicTable()
|
config = config || basicTable()
|
||||||
this.table = await this._req(config, null, controllers.table.save)
|
const response = await this._req(config, null, controllers.table.save)
|
||||||
return this.table!
|
if (!skipReassigning) {
|
||||||
|
this.table = response
|
||||||
|
}
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
async createTable(config?: Table) {
|
async createTable(config?: Table, options = { skipReassigning: false }) {
|
||||||
if (config != null && config._id) {
|
if (config != null && config._id) {
|
||||||
delete config._id
|
delete config._id
|
||||||
}
|
}
|
||||||
return this.updateTable(config)
|
return this.updateTable(config, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTable(tableId?: string) {
|
async getTable(tableId?: string) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { SearchFilters } from "../../sdk"
|
||||||
import { Document } from "../document"
|
import { Document } from "../document"
|
||||||
|
|
||||||
export interface View {
|
export interface View {
|
||||||
|
@ -15,6 +16,7 @@ export interface View {
|
||||||
export interface ViewV2 extends Document {
|
export interface ViewV2 extends Document {
|
||||||
name: string
|
name: string
|
||||||
tableId: string
|
tableId: string
|
||||||
|
query?: SearchFilters
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ViewSchema = ViewCountOrSumSchema | ViewStatisticsSchema
|
export type ViewSchema = ViewCountOrSumSchema | ViewStatisticsSchema
|
||||||
|
|
Loading…
Reference in New Issue