1
0
Fork 0
mirror of synced 2024-09-20 19:33:10 +12:00

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