Use test api

This commit is contained in:
Adria Navarro 2023-09-13 10:13:54 +02:00
parent 4d12ee53da
commit cf74f19381
4 changed files with 46 additions and 30 deletions

View File

@ -16,6 +16,8 @@ import {
SearchParams,
GetRowResponse,
ValidateResponse,
ExportRowsRequest,
ExportRowsResponse,
} from "@budibase/types"
import * as utils from "./utils"
import { gridSocket } from "../../../websockets"
@ -239,7 +241,9 @@ export async function fetchEnrichedRow(ctx: any) {
)
}
export const exportRows = async (ctx: any) => {
export const exportRows = async (
ctx: Ctx<ExportRowsRequest, ExportRowsResponse>
) => {
const tableId = utils.getTableId(ctx)
const format = ctx.query.format

View File

@ -771,11 +771,10 @@ describe.each([
const queryUsage = await getQueryUsage()
// test basic enrichment
const resBasic = await request
.get(`/api/${linkedTable._id}/rows/${secondRow._id}`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
const resBasic = await config.api.row.get(
linkedTable._id!,
secondRow._id!
)
expect(resBasic.body.link.length).toBe(1)
expect(resBasic.body.link[0]).toEqual({
_id: firstRow._id,
@ -783,11 +782,10 @@ describe.each([
})
// test full enrichment
const resEnriched = await request
.get(`/api/${linkedTable._id}/${secondRow._id}/enrich`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
const resEnriched = await config.api.row.getEnriched(
linkedTable._id!,
secondRow._id!
)
expect(resEnriched.body.link.length).toBe(1)
expect(resEnriched.body.link[0]._id).toBe(firstRow._id)
expect(resEnriched.body.link[0].name).toBe("Test Contact")
@ -837,14 +835,9 @@ describe.each([
it("should allow exporting all columns", async () => {
const existing = await config.createRow()
const res = await request
.post(`/api/${table._id}/rows/exportRows?format=json`)
.set(config.defaultHeaders())
.send({
rows: [existing._id],
})
.expect("Content-Type", /json/)
.expect(200)
const res = await config.api.row.exportRows(table._id!, {
rows: [existing._id!],
})
const results = JSON.parse(res.text)
expect(results.length).toEqual(1)
const row = results[0]
@ -860,15 +853,10 @@ describe.each([
it("should allow exporting only certain columns", async () => {
const existing = await config.createRow()
const res = await request
.post(`/api/${table._id}/rows/exportRows?format=json`)
.set(config.defaultHeaders())
.send({
rows: [existing._id],
columns: ["_id"],
})
.expect("Content-Type", /json/)
.expect(200)
const res = await config.api.row.exportRows(table._id!, {
rows: [existing._id!],
columns: ["_id"],
})
const results = JSON.parse(res.text)
expect(results.length).toEqual(1)
const row = results[0]

View File

@ -3,6 +3,7 @@ import {
SaveRowRequest,
Row,
ValidateResponse,
ExportRowsRequest,
} from "@budibase/types"
import TestConfiguration from "../TestConfiguration"
import { TestAPI } from "./base"
@ -33,7 +34,7 @@ export class RowAPI extends TestAPI {
{ expectStatus } = { expectStatus: 200 }
) => {
const request = this.request
.get(`/api/${sourceId}/rows/${rowId}/enrich`)
.get(`/api/${sourceId}/${rowId}/enrich`)
.set(this.config.defaultHeaders())
.expect(expectStatus)
if (expectStatus !== 404) {
@ -107,4 +108,18 @@ export class RowAPI extends TestAPI {
return (await request).body
}
exportRows = async (
tableId: string,
body: ExportRowsRequest,
{ expectStatus } = { expectStatus: 200 }
) => {
const request = this.request
.post(`/api/${tableId}/rows/exportRows?format=json`)
.set(this.config.defaultHeaders())
.send(body)
.expect("Content-Type", /json/)
.expect(expectStatus)
return request
}
}

View File

@ -1,5 +1,6 @@
import { SearchParams } from "../../../sdk"
import { SearchFilters, SearchParams } from "../../../sdk"
import { Row } from "../../../documents"
import { ReadStream } from "fs"
export interface SaveRowRequest extends Row {}
@ -28,3 +29,11 @@ export interface SearchViewRowRequest
export interface SearchRowResponse {
rows: any[]
}
export interface ExportRowsRequest {
rows: string[]
columns?: string[]
query?: SearchFilters
}
export type ExportRowsResponse = ReadStream