From eff22c4e74b251f6062dc973c2fb22de440f4a9c Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Wed, 17 May 2023 21:32:50 +0100 Subject: [PATCH] Remove type casting any from test methods --- packages/types/src/documents/app/screen.ts | 1 + qa-core/src/internal-api/api/apis/AppAPI.ts | 14 ++++---- .../internal-api/api/apis/DatasourcesAPI.ts | 31 ++++-------------- .../src/internal-api/api/apis/QueriesAPI.ts | 4 +-- qa-core/src/internal-api/api/apis/RowAPI.ts | 8 ++--- .../src/internal-api/api/apis/ScreenAPI.ts | 5 +-- .../src/internal-api/fixtures/datasources.ts | 9 +++--- qa-core/src/internal-api/fixtures/queries.ts | 2 +- qa-core/src/internal-api/fixtures/screens.ts | 4 +-- .../tests/dataSources/mariaDB.spec.ts | 2 +- .../tests/dataSources/mongoDB.spec.ts | 2 +- .../tests/dataSources/postgresSQL.spec.ts | 2 +- .../tests/dataSources/restAPI.spec.ts | 2 +- qa-core/src/types/datasources.ts | 22 +++++++++++++ qa-core/src/types/index.ts | 4 +-- qa-core/src/types/screens.ts | 32 +++++++++++++++++++ 16 files changed, 92 insertions(+), 52 deletions(-) create mode 100644 qa-core/src/types/datasources.ts create mode 100644 qa-core/src/types/screens.ts diff --git a/packages/types/src/documents/app/screen.ts b/packages/types/src/documents/app/screen.ts index 5f79620ae4..58c00ef3d6 100644 --- a/packages/types/src/documents/app/screen.ts +++ b/packages/types/src/documents/app/screen.ts @@ -21,4 +21,5 @@ export interface Screen extends Document { width?: string routing: ScreenRouting props: ScreenProps + name?: string } diff --git a/qa-core/src/internal-api/api/apis/AppAPI.ts b/qa-core/src/internal-api/api/apis/AppAPI.ts index 6a7d5cd99a..a9f9a6a841 100644 --- a/qa-core/src/internal-api/api/apis/AppAPI.ts +++ b/qa-core/src/internal-api/api/apis/AppAPI.ts @@ -5,10 +5,15 @@ import { AppPackageResponse, DeployConfig, MessageResponse, + CreateAppRequest, } from "../../../types" import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient" import BaseAPI from "./BaseAPI" +interface RenameAppBody { + name: string +} + export default class AppAPI extends BaseAPI { constructor(client: BudibaseInternalAPIClient) { super(client) @@ -46,7 +51,7 @@ export default class AppAPI extends BaseAPI { return [response, json] } - async create(body: any): Promise { + async create(body: CreateAppRequest): Promise { const [response, json] = await this.post(`/applications`, body) expect(json._id).toBeDefined() return json @@ -100,18 +105,13 @@ export default class AppAPI extends BaseAPI { async rename( appId: string, oldName: string, - body: any + body: RenameAppBody ): Promise<[Response, App]> { const [response, json] = await this.put(`/applications/${appId}`, body) expect(json.name).not.toEqual(oldName) return [response, json] } - async addScreentoApp(body: any): Promise<[Response, App]> { - const [response, json] = await this.post(`/screens`, body) - return [response, json] - } - async getRoutes(screenExists?: boolean): Promise<[Response, RouteConfig]> { const [response, json] = await this.get(`/routing`) if (screenExists) { diff --git a/qa-core/src/internal-api/api/apis/DatasourcesAPI.ts b/qa-core/src/internal-api/api/apis/DatasourcesAPI.ts index 3fec8e8189..9067ed4ab4 100644 --- a/qa-core/src/internal-api/api/apis/DatasourcesAPI.ts +++ b/qa-core/src/internal-api/api/apis/DatasourcesAPI.ts @@ -6,6 +6,7 @@ import { } from "@budibase/types" import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient" import BaseAPI from "./BaseAPI" +import { DatasourceRequest } from "../../../types" export default class DatasourcesAPI extends BaseAPI { constructor(client: BudibaseInternalAPIClient) { @@ -31,7 +32,9 @@ export default class DatasourcesAPI extends BaseAPI { return [response, json] } - async add(body: any): Promise<[Response, CreateDatasourceResponse]> { + async add( + body: DatasourceRequest + ): Promise<[Response, CreateDatasourceResponse]> { const [response, json] = await this.post(`/datasources`, body) expect(json.datasource._id).toBeDefined() expect(json.datasource._rev).toBeDefined() @@ -39,7 +42,9 @@ export default class DatasourcesAPI extends BaseAPI { return [response, json] } - async update(body: any): Promise<[Response, UpdateDatasourceResponse]> { + async update( + body: Datasource + ): Promise<[Response, UpdateDatasourceResponse]> { const [response, json] = await this.put(`/datasources/${body._id}`, body) expect(json.datasource._id).toBeDefined() expect(json.datasource._rev).toBeDefined() @@ -47,28 +52,6 @@ export default class DatasourcesAPI extends BaseAPI { return [response, json] } - async previewQuery(body: any): Promise<[Response, any]> { - const [response, json] = await this.post(`/queries/preview`, body) - return [response, json] - } - - async saveQuery(body: any): Promise<[Response, any]> { - const [response, json] = await this.post(`/queries`, body) - return [response, json] - } - - async getQuery(queryId: string): Promise<[Response, any]> { - const [response, json] = await this.get(`/queries/${queryId}`) - - return [response, json] - } - - async getQueryPermissions(queryId: string): Promise<[Response, any]> { - const [response, json] = await this.get(`/permissions/${queryId}`) - - return [response, json] - } - async delete(dataSourceId: string, revId: string): Promise { const [response, json] = await this.del( `/datasources/${dataSourceId}/${revId}` diff --git a/qa-core/src/internal-api/api/apis/QueriesAPI.ts b/qa-core/src/internal-api/api/apis/QueriesAPI.ts index b47c379191..e3b9d1e474 100644 --- a/qa-core/src/internal-api/api/apis/QueriesAPI.ts +++ b/qa-core/src/internal-api/api/apis/QueriesAPI.ts @@ -3,7 +3,7 @@ import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient" import { PreviewQueryRequest, Query } from "@budibase/types" import BaseAPI from "./BaseAPI" -export default class DatasourcesAPI extends BaseAPI { +export default class QueriesAPI extends BaseAPI { constructor(client: BudibaseInternalAPIClient) { super(client) } @@ -18,7 +18,7 @@ export default class DatasourcesAPI extends BaseAPI { return [response, json] } - async get(queryId: string): Promise<[Response, any]> { + async getQuery(queryId: string): Promise<[Response, any]> { const [response, json] = await this.get(`/queries/${queryId}`) return [response, json] } diff --git a/qa-core/src/internal-api/api/apis/RowAPI.ts b/qa-core/src/internal-api/api/apis/RowAPI.ts index c557a22291..18c4874157 100644 --- a/qa-core/src/internal-api/api/apis/RowAPI.ts +++ b/qa-core/src/internal-api/api/apis/RowAPI.ts @@ -18,7 +18,7 @@ export default class RowAPI extends BaseAPI { } return [response, json] } - async add(tableId: string, body: any): Promise<[Response, Row]> { + async add(tableId: string, body: Row): Promise<[Response, Row]> { const [response, json] = await this.post(`/${tableId}/rows`, body) expect(json._id).toBeDefined() expect(json._rev).toBeDefined() @@ -27,7 +27,7 @@ export default class RowAPI extends BaseAPI { return [response, json] } - async delete(tableId: string, body: any): Promise<[Response, Row[]]> { + async delete(tableId: string, body: Row): Promise<[Response, Row[]]> { const [response, json] = await this.del( `/${tableId}/rows/`, undefined, @@ -38,7 +38,7 @@ export default class RowAPI extends BaseAPI { async searchNoPagination( tableId: string, - body: any + body: string ): Promise<[Response, Row[]]> { const [response, json] = await this.post(`/${tableId}/search`, body) expect(json.hasNextPage).toEqual(false) @@ -47,7 +47,7 @@ export default class RowAPI extends BaseAPI { async searchWithPagination( tableId: string, - body: any + body: string ): Promise<[Response, Row[]]> { const [response, json] = await this.post(`/${tableId}/search`, body) expect(json.hasNextPage).toEqual(true) diff --git a/qa-core/src/internal-api/api/apis/ScreenAPI.ts b/qa-core/src/internal-api/api/apis/ScreenAPI.ts index a5f5859820..df3d699cbd 100644 --- a/qa-core/src/internal-api/api/apis/ScreenAPI.ts +++ b/qa-core/src/internal-api/api/apis/ScreenAPI.ts @@ -1,5 +1,6 @@ -import { Screen } from "@budibase/types" import { Response } from "node-fetch" +import { Screen } from "@budibase/types" +import { ScreenRequest } from "../../../types/screens" import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient" import BaseAPI from "./BaseAPI" @@ -8,7 +9,7 @@ export default class ScreenAPI extends BaseAPI { super(client) } - async create(body: any): Promise<[Response, Screen]> { + async create(body: ScreenRequest): Promise<[Response, Screen]> { const [response, json] = await this.post(`/screens`, body) expect(json._id).toBeDefined() expect(json.routing.roleId).toBe(body.routing.roleId) diff --git a/qa-core/src/internal-api/fixtures/datasources.ts b/qa-core/src/internal-api/fixtures/datasources.ts index dcf6af824a..4797f86631 100644 --- a/qa-core/src/internal-api/fixtures/datasources.ts +++ b/qa-core/src/internal-api/fixtures/datasources.ts @@ -1,5 +1,6 @@ +import { DatasourceRequest } from "../../types" // Add information about the data source to the fixtures file from 1password -export const mongoDB = () => { +export const mongoDB = (): DatasourceRequest => { return { datasource: { name: "MongoDB", @@ -15,7 +16,7 @@ export const mongoDB = () => { } } -export const postgresSQL = () => { +export const postgresSQL = (): DatasourceRequest => { return { datasource: { name: "PostgresSQL", @@ -34,7 +35,7 @@ export const postgresSQL = () => { fetchSchema: true, } } -export const mariaDB = () => { +export const mariaDB = (): DatasourceRequest => { return { datasource: { name: "MariaDB", @@ -54,7 +55,7 @@ export const mariaDB = () => { } } -export const restAPI = () => { +export const restAPI = (): DatasourceRequest => { return { datasource: { name: "RestAPI", diff --git a/qa-core/src/internal-api/fixtures/queries.ts b/qa-core/src/internal-api/fixtures/queries.ts index 83839a0b41..0a28c23ab7 100644 --- a/qa-core/src/internal-api/fixtures/queries.ts +++ b/qa-core/src/internal-api/fixtures/queries.ts @@ -57,7 +57,7 @@ export const expectedSchemaFields = { running_time_secs: "number", title: "string", year: "number", - _id: "json", + _id: "string", }, postgres: { address: "string", diff --git a/qa-core/src/internal-api/fixtures/screens.ts b/qa-core/src/internal-api/fixtures/screens.ts index 97010cc8b6..d07b3bd3ba 100644 --- a/qa-core/src/internal-api/fixtures/screens.ts +++ b/qa-core/src/internal-api/fixtures/screens.ts @@ -1,8 +1,8 @@ import { generator } from "../../shared" - +import { ScreenRequest } from "../../types" const randomId = generator.guid() -export const generateScreen = (roleId: string): any => ({ +export const generateScreen = (roleId: string): ScreenRequest => ({ showNavigation: true, width: "Large", name: randomId, diff --git a/qa-core/src/internal-api/tests/dataSources/mariaDB.spec.ts b/qa-core/src/internal-api/tests/dataSources/mariaDB.spec.ts index 44c2c03c8b..3f479136f6 100644 --- a/qa-core/src/internal-api/tests/dataSources/mariaDB.spec.ts +++ b/qa-core/src/internal-api/tests/dataSources/mariaDB.spec.ts @@ -52,7 +52,7 @@ describe("Internal API - Data Sources: MariaDB", () => { datasourcetoSave ) // Get Query - const [getQueryResponse, getQueryJson] = await config.api.queries.get( + const [getQueryResponse, getQueryJson] = await config.api.queries.getQuery( saveQueryJson._id ) diff --git a/qa-core/src/internal-api/tests/dataSources/mongoDB.spec.ts b/qa-core/src/internal-api/tests/dataSources/mongoDB.spec.ts index ed5178b57c..27fc143554 100644 --- a/qa-core/src/internal-api/tests/dataSources/mongoDB.spec.ts +++ b/qa-core/src/internal-api/tests/dataSources/mongoDB.spec.ts @@ -52,7 +52,7 @@ describe("Internal API - Data Sources: MongoDB", () => { datasourcetoSave ) // Get Query - const [getQueryResponse, getQueryJson] = await config.api.queries.get( + const [getQueryResponse, getQueryJson] = await config.api.queries.getQuery( saveQueryJson._id ) diff --git a/qa-core/src/internal-api/tests/dataSources/postgresSQL.spec.ts b/qa-core/src/internal-api/tests/dataSources/postgresSQL.spec.ts index bc8d86b862..ccfcce6f55 100644 --- a/qa-core/src/internal-api/tests/dataSources/postgresSQL.spec.ts +++ b/qa-core/src/internal-api/tests/dataSources/postgresSQL.spec.ts @@ -52,7 +52,7 @@ describe("Internal API - Data Sources: PostgresSQL", () => { datasourcetoSave ) // Get Query - const [getQueryResponse, getQueryJson] = await config.api.queries.get( + const [getQueryResponse, getQueryJson] = await config.api.queries.getQuery( saveQueryJson._id! ) diff --git a/qa-core/src/internal-api/tests/dataSources/restAPI.spec.ts b/qa-core/src/internal-api/tests/dataSources/restAPI.spec.ts index d7b75db514..649e21db78 100644 --- a/qa-core/src/internal-api/tests/dataSources/restAPI.spec.ts +++ b/qa-core/src/internal-api/tests/dataSources/restAPI.spec.ts @@ -52,7 +52,7 @@ describe("Internal API - Data Sources: REST API", () => { datasourcetoSave ) // Get Query - const [getQueryResponse, getQueryJson] = await config.api.queries.get( + const [getQueryResponse, getQueryJson] = await config.api.queries.getQuery( saveQueryJson._id! ) diff --git a/qa-core/src/types/datasources.ts b/qa-core/src/types/datasources.ts new file mode 100644 index 0000000000..f919e4435f --- /dev/null +++ b/qa-core/src/types/datasources.ts @@ -0,0 +1,22 @@ +export interface DatasourceRequest { + datasource: { + name: string + plus?: boolean + source: string + type: string + config: { + connectionString?: string + db?: string + database?: string + host?: string + password?: string + port?: string + schema?: string + user?: string + defaultHeaders?: {} + rejectUnauthorized?: boolean + url?: string + } + } + fetchSchema: boolean +} diff --git a/qa-core/src/types/index.ts b/qa-core/src/types/index.ts index 6c3740200c..9bde46c66e 100644 --- a/qa-core/src/types/index.ts +++ b/qa-core/src/types/index.ts @@ -8,7 +8,7 @@ export * from "./responseMessage" export * from "./routing" export * from "./state" export * from "./unpublishAppResponse" -export * from "./addedDatasource" - +export * from "./screens" +export * from "./datasources" // re-export public api types export * from "@budibase/server/api/controllers/public/mapping/types" diff --git a/qa-core/src/types/screens.ts b/qa-core/src/types/screens.ts new file mode 100644 index 0000000000..fae65e64fa --- /dev/null +++ b/qa-core/src/types/screens.ts @@ -0,0 +1,32 @@ +export interface ScreenRequest { + showNavigation: boolean + width: string + name: string + template: string + props: ScreenProps + routing: ScreenRouting +} + +interface ScreenProps { + _id: string + _component: string + _styles: { + normal: {} + hover: {} + active: {} + selected: {} + } + _children: [] + _instanceName: string + direction: string + hAlign: string + vAlign: string + size: string + gap: string +} + +interface ScreenRouting { + route: string + roleId: string + homeScreen: boolean +}