1
0
Fork 0
mirror of synced 2024-07-15 11:15:59 +12:00

Fix fetch

This commit is contained in:
Adria Navarro 2023-07-12 16:49:50 +02:00
parent 4a5a3e2c33
commit f395b79cac
3 changed files with 17 additions and 20 deletions

View file

@ -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,
}
} }

View file

@ -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),
})
}) })
}) })
}) })

View file

@ -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) {