Requested changes

This commit is contained in:
Pedro Silva 2022-10-19 10:35:00 +01:00
parent 61a19dc55a
commit 9ee872c4ef
7 changed files with 61 additions and 64 deletions

View File

@ -49,4 +49,10 @@ export interface Table extends Document {
sourceId?: string sourceId?: string
relatedFormula?: string[] relatedFormula?: string[]
constrained?: string[] constrained?: string[]
_id?: string
_rev?: string
createdAt?: string
updatedAt?: string
indexes?: { [key: string]: any }
dataImport?: { [key: string]: any }
} }

View File

@ -2,16 +2,19 @@ import ApplicationApi from "./applications"
import AuthApi from "./auth" import AuthApi from "./auth"
import InternalAPIClient from "./InternalAPIClient" import InternalAPIClient from "./InternalAPIClient"
import TablesApi from "./tables" import TablesApi from "./tables"
import RowApi from "./rows"
export default class TestConfiguration<T> { export default class TestConfiguration<T> {
applications: ApplicationApi applications: ApplicationApi
auth: AuthApi auth: AuthApi
context: T context: T
tables: TablesApi tables: TablesApi
rows: RowApi
constructor(apiClient: InternalAPIClient) { constructor(apiClient: InternalAPIClient) {
this.applications = new ApplicationApi(apiClient) this.applications = new ApplicationApi(apiClient)
this.tables = new TablesApi(apiClient) this.tables = new TablesApi(apiClient)
this.rows = new RowApi(apiClient)
this.auth = new AuthApi(apiClient) this.auth = new AuthApi(apiClient)
this.context = <T>{} this.context = <T>{}
} }

View File

@ -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]
}
}

View File

@ -1,5 +1,5 @@
import { Response } from "node-fetch" import { Response } from "node-fetch"
import { Row, Table } from "@budibase/types" import { Table } from "@budibase/types"
import InternalAPIClient from "./InternalAPIClient" import InternalAPIClient from "./InternalAPIClient"
import { responseMessage } from "../fixtures/types/responseMessage" import { responseMessage } from "../fixtures/types/responseMessage"
@ -11,7 +11,7 @@ export default class TablesApi {
this.api = apiClient 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 response = await this.api.get(`/tables`)
const json = await response.json() const json = await response.json()
expect(response).toHaveStatusCode(200) expect(response).toHaveStatusCode(200)
@ -25,40 +25,16 @@ export default class TablesApi {
return [response, json] 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 response = await this.api.post(`/tables`, { body })
const json = await response.json() const json = await response.json()
return [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 response = await this.api.del(`/tables/${id}/${revId}`)
const json = await response.json() const json = await response.json()
return [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]
}
} }

View File

@ -0,0 +1,8 @@
import { Row } from "@budibase/types"
export const generateNewRowForTable = (tableId: string): Row => {
return {
TestColumn: "TestRow",
tableId: tableId
}
}

View File

@ -1,23 +1,4 @@
import { Row } from "@budibase/types" import { Table } 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 }
}
export const generateTable = (): Table => { export const generateTable = (): Table => {
return { return {
@ -52,9 +33,3 @@ export const generateNewColumnForTable = (tableData: any): Table => {
return newColumn return newColumn
} }
export const generateNewRowForTable = (tableId: string): Row => {
return {
TestColumn: "TestRow",
tableId: tableId
}
}

View File

@ -5,7 +5,8 @@ import InternalAPIClient from "../../../config/internal-api/TestConfiguration/In
import generateApp from "../../../config/internal-api/fixtures/applications" import generateApp from "../../../config/internal-api/fixtures/applications"
import generator from "../../../config/generator" import generator from "../../../config/generator"
import generateScreen from "../../../config/internal-api/fixtures/screens" 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", () => { describe("Internal API - /applications endpoints", () => {
const api = new InternalAPIClient() const api = new InternalAPIClient()
@ -184,16 +185,16 @@ describe("Internal API - /applications endpoints", () => {
config.applications.api.appId = app.appId config.applications.api.appId = app.appId
// Get current tables: expect 2 in this template // Get current tables: expect 2 in this template
await config.tables.getTables(2) await config.tables.getAll(2)
// Add new table // Add new table
const [createdTableResponse, createdTableData] = await config.tables.create(generateTable()) const [createdTableResponse, createdTableData] = await config.tables.save(generateTable())
expect(createdTableResponse).toHaveStatusCode(200) expect(createdTableResponse).toHaveStatusCode(200)
expect(createdTableData._id).toBeDefined() expect(createdTableData._id).toBeDefined()
expect(createdTableData._rev).toBeDefined() expect(createdTableData._rev).toBeDefined()
//Table was added //Table was added
await config.tables.getTables(3) await config.tables.getAll(3)
//Get information about the table //Get information about the table
const [tableInfoResponse, tableInfo] = await config.tables.getTableById(<string>createdTableData._id) const [tableInfoResponse, tableInfo] = await config.tables.getTableById(<string>createdTableData._id)
@ -202,14 +203,14 @@ describe("Internal API - /applications endpoints", () => {
//Add Column to table //Add Column to table
const newColumn = generateNewColumnForTable(createdTableData) 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(addColumnResponse).toHaveStatusCode(200)
expect(addColumnData._id).toEqual(createdTableData._id) expect(addColumnData._id).toEqual(createdTableData._id)
expect(addColumnData.schema.TestColumn).toBeDefined() expect(addColumnData.schema.TestColumn).toBeDefined()
//Add Row to table //Add Row to table
const newRow = generateNewRowForTable(<string>addColumnData._id) const newRow = generateNewRowForTable(<string>addColumnData._id)
const [addRowResponse, addRowData] = await config.tables.addRow(<string>addColumnData._id, newRow) const [addRowResponse, addRowData] = await config.rows.add(<string>addColumnData._id, newRow)
console.log(addRowData) console.log(addRowData)
expect(addRowResponse).toHaveStatusCode(200) expect(addRowResponse).toHaveStatusCode(200)
expect(addRowData._id).toBeDefined() expect(addRowData._id).toBeDefined()
@ -217,7 +218,7 @@ describe("Internal API - /applications endpoints", () => {
expect(addRowData.tableId).toEqual(addColumnData._id) expect(addRowData.tableId).toEqual(addColumnData._id)
//Get Row from table //Get Row from table
const [getRowResponse, getRowData] = await config.tables.getRows(<string>addColumnData._id) const [getRowResponse, getRowData] = await config.rows.getAll(<string>addColumnData._id)
expect(getRowResponse).toHaveStatusCode(200) expect(getRowResponse).toHaveStatusCode(200)
expect(getRowData.length).toEqual(1) expect(getRowData.length).toEqual(1)
@ -227,16 +228,16 @@ describe("Internal API - /applications endpoints", () => {
getRowData[0] getRowData[0]
] ]
} }
const [deleteRowResponse, deleteRowData] = await config.tables.deleteRow(<string>addColumnData._id, rowToDelete) const [deleteRowResponse, deleteRowData] = await config.rows.delete(<string>addColumnData._id, rowToDelete)
expect(deleteRowResponse).toHaveStatusCode(200) expect(deleteRowResponse).toHaveStatusCode(200)
expect(deleteRowData[0]._id).toEqual(getRowData[0]._id) expect(deleteRowData[0]._id).toEqual(getRowData[0]._id)
//Delete the table //Delete the table
const [deleteTableResponse, deleteTable] = await config.tables.deleteTable(<string>addColumnData._id, <string>addColumnData._rev) const [deleteTableResponse, deleteTable] = await config.tables.delete(<string>addColumnData._id, <string>addColumnData._rev)
expect(deleteTableResponse).toHaveStatusCode(200) expect(deleteTableResponse).toHaveStatusCode(200)
expect(deleteTable.message).toEqual(`Table ${createdTableData._id} deleted.`) expect(deleteTable.message).toEqual(`Table ${createdTableData._id} deleted.`)
//Table was deleted //Table was deleted
await config.tables.getTables(2) await config.tables.getAll(2)
}) })
}) })