Fix fetch
This commit is contained in:
parent
4a5a3e2c33
commit
f395b79cac
3 changed files with 17 additions and 20 deletions
|
@ -7,5 +7,9 @@ export async function fetch(ctx: Ctx) {
|
||||||
|
|
||||||
export async function save(ctx: Ctx<ViewV2>) {
|
export async function save(ctx: Ctx<ViewV2>) {
|
||||||
const view = ctx.request.body
|
const view = ctx.request.body
|
||||||
ctx.body = await sdk.views.save(view)
|
const result = await sdk.views.save(view)
|
||||||
|
ctx.body = {
|
||||||
|
...view,
|
||||||
|
...result,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ import * as setup from "./utilities"
|
||||||
import { FieldType, Table, ViewV2 } from "@budibase/types"
|
import { FieldType, Table, ViewV2 } from "@budibase/types"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import sdk from "../../../sdk"
|
import sdk from "../../../sdk"
|
||||||
import { context } from "@budibase/backend-core"
|
|
||||||
|
|
||||||
function priceTable(): Table {
|
function priceTable(): Table {
|
||||||
return {
|
return {
|
||||||
|
@ -57,17 +56,13 @@ describe("/views/v2", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
const views = []
|
const views: any[] = []
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
table = await config.createTable(priceTable())
|
table = await config.createTable(priceTable())
|
||||||
|
|
||||||
for (let id = 0; id < 10; id++) {
|
for (let id = 0; id < 10; id++) {
|
||||||
const view = createView()
|
const res = await saveView(createView())
|
||||||
const res = await saveView(view)
|
views.push(res.body)
|
||||||
await context.doInAppContext(config.appId, async () => {
|
|
||||||
views.push(await sdk.views.get(res.body._id))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -79,7 +74,9 @@ describe("/views/v2", () => {
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(res.body.views.length).toBe(10)
|
expect(res.body.views.length).toBe(10)
|
||||||
expect(res.body.views).toEqual(expect.arrayContaining([]))
|
expect(res.body.views).toEqual(
|
||||||
|
expect.arrayContaining(views.map(v => expect.objectContaining(v)))
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -90,15 +87,10 @@ describe("/views/v2", () => {
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(res.body._id).toBeDefined()
|
expect(res.body._id).toBeDefined()
|
||||||
|
|
||||||
await context.doInAppContext(config.appId, async () => {
|
expect(res.body).toEqual({
|
||||||
const persisted = await sdk.views.get(res.body._id)
|
...view,
|
||||||
expect(persisted).toEqual({
|
_id: expect.any(String),
|
||||||
_id: res.body._id,
|
_rev: expect.any(String),
|
||||||
_rev: res.body._rev,
|
|
||||||
...view,
|
|
||||||
createdAt: expect.any(String),
|
|
||||||
updatedAt: expect.any(String),
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,9 +14,10 @@ export async function fetch() {
|
||||||
const response = await db.allDocs({
|
const response = await db.allDocs({
|
||||||
startkey: startKey,
|
startkey: startKey,
|
||||||
endkey: `${startKey}${UNICODE_MAX}`,
|
endkey: `${startKey}${UNICODE_MAX}`,
|
||||||
|
include_docs: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
return response.rows
|
return response.rows.map(r => r.doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get(viewId: string) {
|
export async function get(viewId: string) {
|
||||||
|
|
Loading…
Reference in a new issue