Use test api
This commit is contained in:
parent
4d12ee53da
commit
cf74f19381
|
@ -16,6 +16,8 @@ import {
|
||||||
SearchParams,
|
SearchParams,
|
||||||
GetRowResponse,
|
GetRowResponse,
|
||||||
ValidateResponse,
|
ValidateResponse,
|
||||||
|
ExportRowsRequest,
|
||||||
|
ExportRowsResponse,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import * as utils from "./utils"
|
import * as utils from "./utils"
|
||||||
import { gridSocket } from "../../../websockets"
|
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 tableId = utils.getTableId(ctx)
|
||||||
|
|
||||||
const format = ctx.query.format
|
const format = ctx.query.format
|
||||||
|
|
|
@ -771,11 +771,10 @@ describe.each([
|
||||||
const queryUsage = await getQueryUsage()
|
const queryUsage = await getQueryUsage()
|
||||||
|
|
||||||
// test basic enrichment
|
// test basic enrichment
|
||||||
const resBasic = await request
|
const resBasic = await config.api.row.get(
|
||||||
.get(`/api/${linkedTable._id}/rows/${secondRow._id}`)
|
linkedTable._id!,
|
||||||
.set(config.defaultHeaders())
|
secondRow._id!
|
||||||
.expect("Content-Type", /json/)
|
)
|
||||||
.expect(200)
|
|
||||||
expect(resBasic.body.link.length).toBe(1)
|
expect(resBasic.body.link.length).toBe(1)
|
||||||
expect(resBasic.body.link[0]).toEqual({
|
expect(resBasic.body.link[0]).toEqual({
|
||||||
_id: firstRow._id,
|
_id: firstRow._id,
|
||||||
|
@ -783,11 +782,10 @@ describe.each([
|
||||||
})
|
})
|
||||||
|
|
||||||
// test full enrichment
|
// test full enrichment
|
||||||
const resEnriched = await request
|
const resEnriched = await config.api.row.getEnriched(
|
||||||
.get(`/api/${linkedTable._id}/${secondRow._id}/enrich`)
|
linkedTable._id!,
|
||||||
.set(config.defaultHeaders())
|
secondRow._id!
|
||||||
.expect("Content-Type", /json/)
|
)
|
||||||
.expect(200)
|
|
||||||
expect(resEnriched.body.link.length).toBe(1)
|
expect(resEnriched.body.link.length).toBe(1)
|
||||||
expect(resEnriched.body.link[0]._id).toBe(firstRow._id)
|
expect(resEnriched.body.link[0]._id).toBe(firstRow._id)
|
||||||
expect(resEnriched.body.link[0].name).toBe("Test Contact")
|
expect(resEnriched.body.link[0].name).toBe("Test Contact")
|
||||||
|
@ -837,14 +835,9 @@ describe.each([
|
||||||
|
|
||||||
it("should allow exporting all columns", async () => {
|
it("should allow exporting all columns", async () => {
|
||||||
const existing = await config.createRow()
|
const existing = await config.createRow()
|
||||||
const res = await request
|
const res = await config.api.row.exportRows(table._id!, {
|
||||||
.post(`/api/${table._id}/rows/exportRows?format=json`)
|
rows: [existing._id!],
|
||||||
.set(config.defaultHeaders())
|
|
||||||
.send({
|
|
||||||
rows: [existing._id],
|
|
||||||
})
|
})
|
||||||
.expect("Content-Type", /json/)
|
|
||||||
.expect(200)
|
|
||||||
const results = JSON.parse(res.text)
|
const results = JSON.parse(res.text)
|
||||||
expect(results.length).toEqual(1)
|
expect(results.length).toEqual(1)
|
||||||
const row = results[0]
|
const row = results[0]
|
||||||
|
@ -860,15 +853,10 @@ describe.each([
|
||||||
|
|
||||||
it("should allow exporting only certain columns", async () => {
|
it("should allow exporting only certain columns", async () => {
|
||||||
const existing = await config.createRow()
|
const existing = await config.createRow()
|
||||||
const res = await request
|
const res = await config.api.row.exportRows(table._id!, {
|
||||||
.post(`/api/${table._id}/rows/exportRows?format=json`)
|
rows: [existing._id!],
|
||||||
.set(config.defaultHeaders())
|
|
||||||
.send({
|
|
||||||
rows: [existing._id],
|
|
||||||
columns: ["_id"],
|
columns: ["_id"],
|
||||||
})
|
})
|
||||||
.expect("Content-Type", /json/)
|
|
||||||
.expect(200)
|
|
||||||
const results = JSON.parse(res.text)
|
const results = JSON.parse(res.text)
|
||||||
expect(results.length).toEqual(1)
|
expect(results.length).toEqual(1)
|
||||||
const row = results[0]
|
const row = results[0]
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
SaveRowRequest,
|
SaveRowRequest,
|
||||||
Row,
|
Row,
|
||||||
ValidateResponse,
|
ValidateResponse,
|
||||||
|
ExportRowsRequest,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import TestConfiguration from "../TestConfiguration"
|
import TestConfiguration from "../TestConfiguration"
|
||||||
import { TestAPI } from "./base"
|
import { TestAPI } from "./base"
|
||||||
|
@ -33,7 +34,7 @@ export class RowAPI extends TestAPI {
|
||||||
{ expectStatus } = { expectStatus: 200 }
|
{ expectStatus } = { expectStatus: 200 }
|
||||||
) => {
|
) => {
|
||||||
const request = this.request
|
const request = this.request
|
||||||
.get(`/api/${sourceId}/rows/${rowId}/enrich`)
|
.get(`/api/${sourceId}/${rowId}/enrich`)
|
||||||
.set(this.config.defaultHeaders())
|
.set(this.config.defaultHeaders())
|
||||||
.expect(expectStatus)
|
.expect(expectStatus)
|
||||||
if (expectStatus !== 404) {
|
if (expectStatus !== 404) {
|
||||||
|
@ -107,4 +108,18 @@ export class RowAPI extends TestAPI {
|
||||||
|
|
||||||
return (await request).body
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { SearchParams } from "../../../sdk"
|
import { SearchFilters, SearchParams } from "../../../sdk"
|
||||||
import { Row } from "../../../documents"
|
import { Row } from "../../../documents"
|
||||||
|
import { ReadStream } from "fs"
|
||||||
|
|
||||||
export interface SaveRowRequest extends Row {}
|
export interface SaveRowRequest extends Row {}
|
||||||
|
|
||||||
|
@ -28,3 +29,11 @@ export interface SearchViewRowRequest
|
||||||
export interface SearchRowResponse {
|
export interface SearchRowResponse {
|
||||||
rows: any[]
|
rows: any[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ExportRowsRequest {
|
||||||
|
rows: string[]
|
||||||
|
columns?: string[]
|
||||||
|
query?: SearchFilters
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ExportRowsResponse = ReadStream
|
||||||
|
|
Loading…
Reference in New Issue