1
0
Fork 0
mirror of synced 2024-06-17 18:04:42 +12:00

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
relatedFormula?: 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 InternalAPIClient from "./InternalAPIClient"
import TablesApi from "./tables"
import RowApi from "./rows"
export default class TestConfiguration<T> {
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 = <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 { 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]
}
}

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"
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
}
}

View file

@ -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(<string>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(<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)
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(<string>addColumnData._id)
const [getRowResponse, getRowData] = await config.rows.getAll(<string>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(<string>addColumnData._id, rowToDelete)
const [deleteRowResponse, deleteRowData] = await config.rows.delete(<string>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(<string>addColumnData._id, <string>addColumnData._rev)
const [deleteTableResponse, deleteTable] = await config.tables.delete(<string>addColumnData._id, <string>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)
})
})