1
0
Fork 0
mirror of synced 2024-10-02 10:08:09 +13:00

Improvements on apps and tables

This commit is contained in:
Pedro Silva 2022-12-23 16:03:02 +00:00
parent 61433b4b5f
commit 3aec3df36d
5 changed files with 134 additions and 3 deletions

View file

@ -153,4 +153,27 @@ export default class AppApi {
expect(response).toHaveStatusCode(204)
return [response]
}
async unlock(appId: string): Promise<[Response, responseMessage]> {
const response = await this.api.del(`/dev/${appId}/lock`)
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.message).toEqual("Lock released successfully.")
return [response, json]
}
async updateIcon(appId: string): Promise<[Response, Application]> {
const body = {
icon: {
name: "ConversionFunnel",
color: "var(--spectrum-global-color-red-400)"
}
}
const response = await this.api.put(`/applications/${appId}`, { body })
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.icon.name).toEqual(body.icon.name)
expect(json.icon.color).toEqual(body.icon.color)
return [response, json]
}
}

View file

@ -15,7 +15,7 @@ export default class RowsApi {
const json = await response.json()
if (this.rowAdded) {
expect(response).toHaveStatusCode(200)
expect(json.length).toEqual(1)
expect(json.length).toBeGreaterThanOrEqual(1)
}
return [response, json]
}
@ -36,4 +36,22 @@ export default class RowsApi {
expect(response).toHaveStatusCode(200)
return [response, json]
}
async searchSinglePage(tableId: string, body: any): Promise<[Response, Row[]]> {
const response = await this.api.post(`/${tableId}/search`, { body })
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.rows.length).toBeLessThanOrEqual(9)
expect(json.hasNextPage).toEqual(false)
return [response, json.rows]
}
async searchMultiPage(tableId: string, body: any): Promise<[Response, Row[]]> {
const response = await this.api.post(`/${tableId}/search`, { body })
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.hasNextPage).toEqual(true)
expect(json.rows.length).toEqual(10)
return [response, json.rows]
}
}

View file

@ -6,3 +6,27 @@ export const generateNewRowForTable = (tableId: string): Row => {
tableId: tableId,
}
}
export const searchBody = (primaryDisplay: string): any => {
return {
bookmark: null,
limit: 10,
paginate: true,
query: {
contains: {},
containsAny: {},
empty: {},
equal: {},
fuzzy: {},
notContains: {},
notEmpty: {},
notEqual: {},
oneOf: {},
range: {},
string: {},
},
sort: primaryDisplay,
sortOrder: "ascending",
sortType: "string"
}
}

View file

@ -104,6 +104,14 @@ describe("Internal API - Application creation, update, publish and delete", () =
})
})
it("Update the icon and color of an application", async () => {
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
await config.applications.updateIcon(<string>app.appId)
})
it("POST - Revert Changes without changes", async () => {
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
@ -124,6 +132,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
// // Revert the app to published state
await config.applications.revertPublished(<string>app.appId)
await config.applications.unlock(<string>app.appId)
// Check screen is removed
await config.applications.getRoutes()
})

View file

@ -6,9 +6,9 @@ import {
generateTable,
generateNewColumnForTable,
} from "../../../config/internal-api/fixtures/table"
import { generateNewRowForTable } from "../../../config/internal-api/fixtures/rows"
import { generateNewRowForTable, searchBody } from "../../../config/internal-api/fixtures/rows"
describe("Internal API - Application creation, update, publish and delete", () => {
describe("Internal API - Table Operations", () => {
const api = new InternalAPIClient()
const config = new TestConfiguration<Application>(api)
@ -86,4 +86,61 @@ describe("Internal API - Application creation, update, publish and delete", () =
//Table was deleted
await config.tables.getAll(2)
})
it("Search and pagination", async () => {
// create the app
const appName = generator.word()
const app = await createAppFromTemplate()
config.applications.api.appId = app.appId
// Get current tables: expect 2 in this template
await config.tables.getAll(2)
// Add new table
const [createdTableResponse, createdTableData] = await config.tables.save(
generateTable()
)
//Table was added
await config.tables.getAll(3)
//Get information about the table
await config.tables.getTableById(<string>createdTableData._id)
//Add Column to table
const newColumn = generateNewColumnForTable(createdTableData)
const [addColumnResponse, addColumnData] = await config.tables.save(
newColumn,
true
)
//Add Row to table
let newRow = generateNewRowForTable(<string>addColumnData._id)
await config.rows.add(<string>addColumnData._id, newRow)
//Search single row
await config.rows.searchSinglePage(<string>createdTableData._id, searchBody(<string>createdTableData.primaryDisplay))
//Add 10 more rows
for (let i = 0; i < 10; i++) {
let newRow = generateNewRowForTable(<string>addColumnData._id)
await config.rows.add(<string>addColumnData._id, newRow)
}
//Search multiple rows
const [allRowsResponse, allRowsJson] = await config.rows.searchMultiPage(<string>createdTableData._id, searchBody(<string>createdTableData.primaryDisplay))
//Delete Rows from table
const rowToDelete = {
rows: [allRowsJson],
}
const [deleteRowResponse, deleteRowData] = await config.rows.delete(
<string>addColumnData._id,
rowToDelete
)
//Search single row
await config.rows.searchSinglePage(<string>createdTableData._id, searchBody(<string>createdTableData.primaryDisplay))
})
})