From 4f65306c4fdf71deb90fe9283585c446a7b6c318 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 25 Jul 2024 17:20:10 +0200 Subject: [PATCH] Add basic validateNewTableImport test --- .../server/src/api/routes/tests/table.spec.ts | 33 +++++++++++++++++++ .../server/src/tests/utilities/api/table.ts | 22 ++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/routes/tests/table.spec.ts b/packages/server/src/api/routes/tests/table.spec.ts index a2cff7b395..b32983b8ad 100644 --- a/packages/server/src/api/routes/tests/table.spec.ts +++ b/packages/server/src/api/routes/tests/table.spec.ts @@ -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, + }, + }) + }) + }) + }) }) diff --git a/packages/server/src/tests/utilities/api/table.ts b/packages/server/src/tests/utilities/api/table.ts index d918ba8b9a..c42247dc59 100644 --- a/packages/server/src/tests/utilities/api/table.ts +++ b/packages/server/src/tests/utilities/api/table.ts @@ -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 => { - return await this._delete(`/api/tables/${tableId}/${revId}`, { + return await this._delete(`/api/tables/${tableId}/${revId}`, { expectations, }) } + + validateNewTableImport = async ( + rows: Row[], + schema: TableSchema, + expectations?: Expectations + ): Promise => { + return await this._post( + `/api/tables/validateNewTableImport`, + { + body: { + rows, + schema, + }, + expectations, + } + ) + } }