Add basic validateNewTableImport test

This commit is contained in:
Adria Navarro 2024-07-25 17:20:10 +02:00
parent 543d0e1ce6
commit 4f65306c4f
2 changed files with 54 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import {
Row, Row,
SaveTableRequest, SaveTableRequest,
Table, Table,
TableSchema,
TableSourceType, TableSourceType,
User, User,
ViewCalculation, ViewCalculation,
@ -1022,4 +1023,36 @@ describe.each([
}) })
}) })
}) })
describe("import validation", () => {
const basicSchema: TableSchema = {
id: {
type: FieldType.NUMBER,
name: "id",
},
name: {
type: FieldType.STRING,
name: "name",
},
}
describe("validateNewTableImport", () => {
it("can validate basic imports", async () => {
const result = await config.api.table.validateNewTableImport(
[{ id: generator.natural(), name: generator.first() }],
basicSchema
)
expect(result).toEqual({
allValid: true,
errors: {},
invalidColumns: [],
schemaValidation: {
id: true,
name: true,
},
})
})
})
})
}) })

View File

@ -3,9 +3,12 @@ import {
BulkImportResponse, BulkImportResponse,
MigrateRequest, MigrateRequest,
MigrateResponse, MigrateResponse,
Row,
SaveTableRequest, SaveTableRequest,
SaveTableResponse, SaveTableResponse,
Table, Table,
TableSchema,
ValidateTableImportResponse,
} from "@budibase/types" } from "@budibase/types"
import { Expectations, TestAPI } from "./base" import { Expectations, TestAPI } from "./base"
@ -61,8 +64,25 @@ export class TableAPI extends TestAPI {
revId: string, revId: string,
expectations?: Expectations expectations?: Expectations
): Promise<void> => { ): Promise<void> => {
return await this._delete<void>(`/api/tables/${tableId}/${revId}`, { return await this._delete(`/api/tables/${tableId}/${revId}`, {
expectations, expectations,
}) })
} }
validateNewTableImport = async (
rows: Row[],
schema: TableSchema,
expectations?: Expectations
): Promise<ValidateTableImportResponse> => {
return await this._post<ValidateTableImportResponse>(
`/api/tables/validateNewTableImport`,
{
body: {
rows,
schema,
},
expectations,
}
)
}
} }