From 9ee872c4ef214eee5b540447ff214140f86d8bc3 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Wed, 19 Oct 2022 10:35:00 +0100 Subject: [PATCH] Requested changes --- packages/types/src/documents/app/table.ts | 6 ++++ .../internal-api/TestConfiguration/index.ts | 3 ++ .../internal-api/TestConfiguration/rows.ts | 28 ++++++++++++++++ .../internal-api/TestConfiguration/tables.ts | 32 +++---------------- .../src/config/internal-api/fixtures/rows.ts | 8 +++++ .../src/config/internal-api/fixtures/table.ts | 27 +--------------- .../internal-api/applications/create.spec.ts | 21 ++++++------ 7 files changed, 61 insertions(+), 64 deletions(-) create mode 100644 qa-core/src/config/internal-api/TestConfiguration/rows.ts create mode 100644 qa-core/src/config/internal-api/fixtures/rows.ts diff --git a/packages/types/src/documents/app/table.ts b/packages/types/src/documents/app/table.ts index 72cff4f056..8d5e956495 100644 --- a/packages/types/src/documents/app/table.ts +++ b/packages/types/src/documents/app/table.ts @@ -49,4 +49,10 @@ export interface Table extends Document { sourceId?: string relatedFormula?: string[] constrained?: string[] + _id?: string + _rev?: string + createdAt?: string + updatedAt?: string + indexes?: { [key: string]: any } + dataImport?: { [key: string]: any } } diff --git a/qa-core/src/config/internal-api/TestConfiguration/index.ts b/qa-core/src/config/internal-api/TestConfiguration/index.ts index 2e88316b4f..f1fbb5228e 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/index.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/index.ts @@ -2,16 +2,19 @@ import ApplicationApi from "./applications" import AuthApi from "./auth" import InternalAPIClient from "./InternalAPIClient" import TablesApi from "./tables" +import RowApi from "./rows" export default class TestConfiguration { applications: ApplicationApi auth: AuthApi context: T tables: TablesApi + rows: RowApi constructor(apiClient: InternalAPIClient) { this.applications = new ApplicationApi(apiClient) this.tables = new TablesApi(apiClient) + this.rows = new RowApi(apiClient) this.auth = new AuthApi(apiClient) this.context = {} } diff --git a/qa-core/src/config/internal-api/TestConfiguration/rows.ts b/qa-core/src/config/internal-api/TestConfiguration/rows.ts new file mode 100644 index 0000000000..a439334294 --- /dev/null +++ b/qa-core/src/config/internal-api/TestConfiguration/rows.ts @@ -0,0 +1,28 @@ +import { Response } from "node-fetch" +import { Row } from "@budibase/types" +import InternalAPIClient from "./InternalAPIClient" + +export default class RowsApi { + api: InternalAPIClient + + constructor(apiClient: InternalAPIClient) { + this.api = apiClient + } + + async getAll(id: string): Promise<[Response, Row[]]> { + const response = await this.api.get(`/${id}/rows`) + const json = await response.json() + return [response, json] + } + async add(id: string, body: any): Promise<[Response, Row]> { + const response = await this.api.post(`/${id}/rows`, { body }) + const json = await response.json() + return [response, json] + } + + async delete(id: string, body: any): Promise<[Response, Row[]]> { + const response = await this.api.del(`/${id}/rows/`, { body }) + const json = await response.json() + return [response, json] + } +} \ No newline at end of file diff --git a/qa-core/src/config/internal-api/TestConfiguration/tables.ts b/qa-core/src/config/internal-api/TestConfiguration/tables.ts index 041e909532..0061291524 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/tables.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/tables.ts @@ -1,5 +1,5 @@ import { Response } from "node-fetch" -import { Row, Table } from "@budibase/types" +import { Table } from "@budibase/types" import InternalAPIClient from "./InternalAPIClient" import { responseMessage } from "../fixtures/types/responseMessage" @@ -11,7 +11,7 @@ export default class TablesApi { this.api = apiClient } - async getTables(expectedNumber: Number): Promise<[Response, Table[]]> { + async getAll(expectedNumber: Number): Promise<[Response, Table[]]> { const response = await this.api.get(`/tables`) const json = await response.json() expect(response).toHaveStatusCode(200) @@ -25,40 +25,16 @@ export default class TablesApi { return [response, json] } - async create(body: any): Promise<[Response, Table]> { + async save(body: any): Promise<[Response, Table]> { const response = await this.api.post(`/tables`, { body }) const json = await response.json() return [response, json] } - async deleteTable(id: string, revId: string): Promise<[Response, responseMessage]> { + async delete(id: string, revId: string): Promise<[Response, responseMessage]> { const response = await this.api.del(`/tables/${id}/${revId}`) const json = await response.json() return [response, json] } - async update(body: any): Promise<[Response, Table]> { - const response = await this.api.put(`/tables`, { body }) - const json = await response.json() - return [response, json] - } - - async getRows(id: string): Promise<[Response, Row[]]> { - const response = await this.api.get(`/${id}/rows`) - const json = await response.json() - return [response, json] - } - async addRow(id: string, body: any): Promise<[Response, Row]> { - const response = await this.api.post(`/${id}/rows`, { body }) - const json = await response.json() - return [response, json] - } - - async deleteRow(id: string, body: any): Promise<[Response, Row[]]> { - const response = await this.api.del(`/${id}/rows/`, { body }) - const json = await response.json() - return [response, json] - } - - } \ No newline at end of file diff --git a/qa-core/src/config/internal-api/fixtures/rows.ts b/qa-core/src/config/internal-api/fixtures/rows.ts new file mode 100644 index 0000000000..fa071221a4 --- /dev/null +++ b/qa-core/src/config/internal-api/fixtures/rows.ts @@ -0,0 +1,8 @@ +import { Row } from "@budibase/types" + +export const generateNewRowForTable = (tableId: string): Row => { + return { + TestColumn: "TestRow", + tableId: tableId + } +} \ No newline at end of file diff --git a/qa-core/src/config/internal-api/fixtures/table.ts b/qa-core/src/config/internal-api/fixtures/table.ts index 68f3e79555..b7bfbd6ff6 100644 --- a/qa-core/src/config/internal-api/fixtures/table.ts +++ b/qa-core/src/config/internal-api/fixtures/table.ts @@ -1,23 +1,4 @@ -import { Row } from "@budibase/types" - -type Table = { - type?: string - views?: { [key: string]: any } - name: string - primary?: string[] - schema: { [key: string]: any } - primaryDisplay?: string - sourceId?: string - relatedFormula?: string[] - constrained?: string[] - _id?: string - _rev?: string - createdAt?: string - updatedAt?: string - indexes?: { [key: string]: any } - dataImport?: { [key: string]: any } - -} +import { Table } from "@budibase/types" export const generateTable = (): Table => { return { @@ -52,9 +33,3 @@ export const generateNewColumnForTable = (tableData: any): Table => { return newColumn } -export const generateNewRowForTable = (tableId: string): Row => { - return { - TestColumn: "TestRow", - tableId: tableId - } -} diff --git a/qa-core/src/tests/internal-api/applications/create.spec.ts b/qa-core/src/tests/internal-api/applications/create.spec.ts index ff57629458..588652e446 100644 --- a/qa-core/src/tests/internal-api/applications/create.spec.ts +++ b/qa-core/src/tests/internal-api/applications/create.spec.ts @@ -5,7 +5,8 @@ import InternalAPIClient from "../../../config/internal-api/TestConfiguration/In import generateApp from "../../../config/internal-api/fixtures/applications" import generator from "../../../config/generator" import generateScreen from "../../../config/internal-api/fixtures/screens" -import { generateTable, generateNewColumnForTable, generateNewRowForTable } from "../../../config/internal-api/fixtures/table" +import { generateTable, generateNewColumnForTable } from "../../../config/internal-api/fixtures/table" +import { generateNewRowForTable } from "../../../config/internal-api/fixtures/rows" describe("Internal API - /applications endpoints", () => { const api = new InternalAPIClient() @@ -184,16 +185,16 @@ describe("Internal API - /applications endpoints", () => { config.applications.api.appId = app.appId // Get current tables: expect 2 in this template - await config.tables.getTables(2) + await config.tables.getAll(2) // Add new table - const [createdTableResponse, createdTableData] = await config.tables.create(generateTable()) + const [createdTableResponse, createdTableData] = await config.tables.save(generateTable()) expect(createdTableResponse).toHaveStatusCode(200) expect(createdTableData._id).toBeDefined() expect(createdTableData._rev).toBeDefined() //Table was added - await config.tables.getTables(3) + await config.tables.getAll(3) //Get information about the table const [tableInfoResponse, tableInfo] = await config.tables.getTableById(createdTableData._id) @@ -202,14 +203,14 @@ describe("Internal API - /applications endpoints", () => { //Add Column to table const newColumn = generateNewColumnForTable(createdTableData) - const [addColumnResponse, addColumnData] = await config.tables.create(newColumn) + const [addColumnResponse, addColumnData] = await config.tables.save(newColumn) expect(addColumnResponse).toHaveStatusCode(200) expect(addColumnData._id).toEqual(createdTableData._id) expect(addColumnData.schema.TestColumn).toBeDefined() //Add Row to table const newRow = generateNewRowForTable(addColumnData._id) - const [addRowResponse, addRowData] = await config.tables.addRow(addColumnData._id, newRow) + const [addRowResponse, addRowData] = await config.rows.add(addColumnData._id, newRow) console.log(addRowData) expect(addRowResponse).toHaveStatusCode(200) expect(addRowData._id).toBeDefined() @@ -217,7 +218,7 @@ describe("Internal API - /applications endpoints", () => { expect(addRowData.tableId).toEqual(addColumnData._id) //Get Row from table - const [getRowResponse, getRowData] = await config.tables.getRows(addColumnData._id) + const [getRowResponse, getRowData] = await config.rows.getAll(addColumnData._id) expect(getRowResponse).toHaveStatusCode(200) expect(getRowData.length).toEqual(1) @@ -227,16 +228,16 @@ describe("Internal API - /applications endpoints", () => { getRowData[0] ] } - const [deleteRowResponse, deleteRowData] = await config.tables.deleteRow(addColumnData._id, rowToDelete) + const [deleteRowResponse, deleteRowData] = await config.rows.delete(addColumnData._id, rowToDelete) expect(deleteRowResponse).toHaveStatusCode(200) expect(deleteRowData[0]._id).toEqual(getRowData[0]._id) //Delete the table - const [deleteTableResponse, deleteTable] = await config.tables.deleteTable(addColumnData._id, addColumnData._rev) + const [deleteTableResponse, deleteTable] = await config.tables.delete(addColumnData._id, addColumnData._rev) expect(deleteTableResponse).toHaveStatusCode(200) expect(deleteTable.message).toEqual(`Table ${createdTableData._id} deleted.`) //Table was deleted - await config.tables.getTables(2) + await config.tables.getAll(2) }) })