Merge pull request #9188 from Budibase/api-tests-extend-coverage
Extend Coverage of API tests to replace Cypress tests
This commit is contained in:
commit
82cc1ac22b
|
@ -117,7 +117,7 @@ export default class AppApi {
|
|||
return [response, json]
|
||||
}
|
||||
|
||||
async update(
|
||||
async rename(
|
||||
appId: string,
|
||||
oldName: string,
|
||||
body: any
|
||||
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,27 @@ export default class RowsApi {
|
|||
expect(response).toHaveStatusCode(200)
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async searchNoPagination(
|
||||
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(false)
|
||||
return [response, json.rows]
|
||||
}
|
||||
|
||||
async searchWithPagination(
|
||||
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]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
|
|||
await config.applications.unpublish(<string>app.appId)
|
||||
})
|
||||
|
||||
it("POST - Sync application before deployment", async () => {
|
||||
it("Sync application before deployment", async () => {
|
||||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
|
@ -81,7 +81,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
|
|||
})
|
||||
})
|
||||
|
||||
it("POST - Sync application after deployment", async () => {
|
||||
it("Sync application after deployment", async () => {
|
||||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
|
@ -96,24 +96,32 @@ describe("Internal API - Application creation, update, publish and delete", () =
|
|||
})
|
||||
})
|
||||
|
||||
it("PUT - Update an application", async () => {
|
||||
it("Rename an application", async () => {
|
||||
const app = await config.applications.create(generateApp())
|
||||
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
await config.applications.update(<string>app.appId, <string>app.name, {
|
||||
await config.applications.rename(<string>app.appId, <string>app.name, {
|
||||
name: generator.word(),
|
||||
})
|
||||
})
|
||||
|
||||
it("POST - Revert Changes without changes", async () => {
|
||||
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("Revert Changes without changes", async () => {
|
||||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
await config.applications.revertUnpublished(<string>app.appId)
|
||||
})
|
||||
|
||||
it("POST - Revert Changes", async () => {
|
||||
it("Revert Changes", async () => {
|
||||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
|
@ -126,11 +134,12 @@ 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()
|
||||
})
|
||||
|
||||
it("DELETE - Delete an application", async () => {
|
||||
it("Delete an application", async () => {
|
||||
const app = await config.applications.create(generateApp())
|
||||
|
||||
await config.applications.delete(<string>app.appId)
|
||||
|
|
|
@ -21,7 +21,7 @@ describe("Internal API - /screens endpoints", () => {
|
|||
await config.afterAll()
|
||||
})
|
||||
|
||||
it("POST - Create a screen with each role type", async () => {
|
||||
it("Create a screen with each role type", async () => {
|
||||
// Create app
|
||||
const app = await appConfig.applications.create(generateApp())
|
||||
|
||||
|
@ -35,7 +35,7 @@ describe("Internal API - /screens endpoints", () => {
|
|||
}
|
||||
})
|
||||
|
||||
it("GET - Fetch screens", async () => {
|
||||
it("Get screens", async () => {
|
||||
// Create app
|
||||
const app = await appConfig.applications.create(generateApp())
|
||||
|
||||
|
@ -47,7 +47,7 @@ describe("Internal API - /screens endpoints", () => {
|
|||
await appConfig.applications.getRoutes(true)
|
||||
})
|
||||
|
||||
it("DELETE - Delete a screen", async () => {
|
||||
it("Delete a screen", async () => {
|
||||
// Create app
|
||||
const app = await appConfig.applications.create(generateApp())
|
||||
|
||||
|
|
|
@ -6,9 +6,12 @@ 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)
|
||||
|
||||
|
@ -31,7 +34,7 @@ describe("Internal API - Application creation, update, publish and delete", () =
|
|||
})
|
||||
}
|
||||
|
||||
it("Operations on Tables", async () => {
|
||||
it("Create and delete table, columns and rows", async () => {
|
||||
// create the app
|
||||
const appName = generator.word()
|
||||
const app = await createAppFromTemplate()
|
||||
|
@ -86,4 +89,70 @@ 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.searchNoPagination(
|
||||
<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 rows with pagination
|
||||
const [allRowsResponse, allRowsJson] =
|
||||
await config.rows.searchWithPagination(
|
||||
<string>createdTableData._id,
|
||||
searchBody(<string>createdTableData.primaryDisplay)
|
||||
)
|
||||
|
||||
//Delete Rows from table
|
||||
const rowToDelete = {
|
||||
rows: [allRowsJson],
|
||||
}
|
||||
const [deleteRowResponse, deleteRowData] = await config.rows.delete(
|
||||
<string>createdTableData._id,
|
||||
rowToDelete
|
||||
)
|
||||
|
||||
//Search single row
|
||||
await config.rows.searchWithPagination(
|
||||
<string>createdTableData._id,
|
||||
searchBody(<string>createdTableData.primaryDisplay)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -28,9 +28,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
})
|
||||
|
||||
it("Add BASIC user to app", async () => {
|
||||
// Create a user with BASIC role and check if it was created successfully
|
||||
const appUser = generateUser()
|
||||
expect(appUser[0].builder?.global).toEqual(false)
|
||||
expect(appUser[0].admin?.global).toEqual(false)
|
||||
|
||||
// Add the user to the tenant.
|
||||
const [createUserResponse, createUserJson] = await config.users.addMultiple(
|
||||
appUser
|
||||
)
|
||||
|
@ -38,9 +41,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
const app = await config.applications.create(appFromTemplate())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
// Get all the information from the create user
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
||||
createUserJson.created.successful[0]._id
|
||||
)
|
||||
|
||||
// Create the body with the information from the user and add the role to the app
|
||||
const body: User = {
|
||||
...userInfoJson,
|
||||
roles: {
|
||||
|
@ -49,6 +55,7 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
}
|
||||
await config.users.updateInfo(body)
|
||||
|
||||
// Get the user information again and check if the role was added
|
||||
const [changedUserInfoResponse, changedUserInfoJson] =
|
||||
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
||||
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
||||
|
@ -56,6 +63,7 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
})
|
||||
|
||||
it("Add ADMIN user to app", async () => {
|
||||
// Create a user with ADMIN role and check if it was created successfully
|
||||
const adminUser = generateUser(1, "admin")
|
||||
expect(adminUser[0].builder?.global).toEqual(true)
|
||||
expect(adminUser[0].admin?.global).toEqual(true)
|
||||
|
@ -63,15 +71,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
adminUser
|
||||
)
|
||||
|
||||
//const app = await config.applications.create(generateApp())
|
||||
//config.applications.api.appId = app.appId
|
||||
|
||||
const app = await config.applications.create(appFromTemplate())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
// Get all the information from the create user
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
||||
createUserJson.created.successful[0]._id
|
||||
)
|
||||
|
||||
// Create the body with the information from the user and add the role to the app
|
||||
const body: User = {
|
||||
...userInfoJson,
|
||||
roles: {
|
||||
|
@ -80,6 +88,7 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
}
|
||||
await config.users.updateInfo(body)
|
||||
|
||||
// Get the user information again and check if the role was added
|
||||
const [changedUserInfoResponse, changedUserInfoJson] =
|
||||
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
||||
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
||||
|
@ -93,9 +102,9 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
})
|
||||
|
||||
it("Add POWER user to app", async () => {
|
||||
// Create a user with POWER role and check if it was created successfully
|
||||
const powerUser = generateUser(1, "developer")
|
||||
expect(powerUser[0].builder?.global).toEqual(true)
|
||||
|
||||
const [createUserResponse, createUserJson] = await config.users.addMultiple(
|
||||
powerUser
|
||||
)
|
||||
|
@ -103,9 +112,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
// Get all the information from the create user
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
||||
createUserJson.created.successful[0]._id
|
||||
)
|
||||
|
||||
// Create the body with the information from the user and add the role to the app
|
||||
const body: User = {
|
||||
...userInfoJson,
|
||||
roles: {
|
||||
|
@ -114,6 +126,7 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
}
|
||||
await config.users.updateInfo(body)
|
||||
|
||||
// Get the user information again and check if the role was added
|
||||
const [changedUserInfoResponse, changedUserInfoJson] =
|
||||
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
||||
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
||||
|
@ -122,6 +135,7 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
|
||||
describe("Check Access for default roles", () => {
|
||||
it("Check Table access for app user", async () => {
|
||||
// Create a user with BASIC role and check if it was created successfully
|
||||
const appUser = generateUser()
|
||||
expect(appUser[0].builder?.global).toEqual(false)
|
||||
expect(appUser[0].admin?.global).toEqual(false)
|
||||
|
@ -131,9 +145,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
// Get all the information from the create user
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
||||
createUserJson.created.successful[0]._id
|
||||
)
|
||||
|
||||
// Create the body with the information from the user and add the role to the app
|
||||
const body: User = {
|
||||
...userInfoJson,
|
||||
roles: {
|
||||
|
@ -142,14 +159,18 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
}
|
||||
await config.users.updateInfo(body)
|
||||
|
||||
// Get the user information again and check if the role was added
|
||||
const [changedUserInfoResponse, changedUserInfoJson] =
|
||||
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
||||
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
||||
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("BASIC")
|
||||
|
||||
// Create a table
|
||||
const [createdTableResponse, createdTableData] = await config.tables.save(
|
||||
generateTable()
|
||||
)
|
||||
|
||||
// Login with the user created and try to create a column
|
||||
await config.login(<string>appUser[0].email, <string>appUser[0].password)
|
||||
const newColumn = generateNewColumnForTable(createdTableData)
|
||||
await config.tables.forbiddenSave(newColumn)
|
||||
|
@ -157,6 +178,7 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
})
|
||||
|
||||
it("Check Table access for developer", async () => {
|
||||
// Create a user with POWER role and check if it was created successfully
|
||||
const developer = generateUser(1, "developer")
|
||||
expect(developer[0].builder?.global).toEqual(true)
|
||||
|
||||
|
@ -166,9 +188,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
// Get all the information from the create user
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
||||
createUserJson.created.successful[0]._id
|
||||
)
|
||||
|
||||
// Create the body with the information from the user and add the role to the app
|
||||
const body: User = {
|
||||
...userInfoJson,
|
||||
roles: {
|
||||
|
@ -177,14 +202,18 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
}
|
||||
await config.users.updateInfo(body)
|
||||
|
||||
// Get the user information again and check if the role was added
|
||||
const [changedUserInfoResponse, changedUserInfoJson] =
|
||||
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
||||
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
||||
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("POWER")
|
||||
|
||||
// Create a table
|
||||
const [createdTableResponse, createdTableData] = await config.tables.save(
|
||||
generateTable()
|
||||
)
|
||||
|
||||
// Login with the user created and try to create a column
|
||||
await config.login(
|
||||
<string>developer[0].email,
|
||||
<string>developer[0].password
|
||||
|
@ -197,6 +226,7 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
})
|
||||
|
||||
it("Check Table access for admin", async () => {
|
||||
// Create a user with ADMIN role and check if it was created successfully
|
||||
const adminUser = generateUser(1, "admin")
|
||||
expect(adminUser[0].builder?.global).toEqual(true)
|
||||
expect(adminUser[0].admin?.global).toEqual(true)
|
||||
|
@ -206,9 +236,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
// Get all the information from the create user
|
||||
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
||||
createUserJson.created.successful[0]._id
|
||||
)
|
||||
|
||||
// Create the body with the information from the user and add the role to the app
|
||||
const body: User = {
|
||||
...userInfoJson,
|
||||
roles: {
|
||||
|
@ -217,11 +250,13 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|||
}
|
||||
await config.users.updateInfo(body)
|
||||
|
||||
// Get the user information again and check if the role was added
|
||||
const [changedUserInfoResponse, changedUserInfoJson] =
|
||||
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
||||
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
||||
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("ADMIN")
|
||||
|
||||
// Login with the created user and create a table
|
||||
await config.login(
|
||||
<string>adminUser[0].email,
|
||||
<string>adminUser[0].password
|
||||
|
|
|
@ -18,9 +18,13 @@ describe("Internal API - User Management & Permissions", () => {
|
|||
})
|
||||
|
||||
it("Add Users with different roles", async () => {
|
||||
// Get all users
|
||||
await config.users.search()
|
||||
|
||||
// Get all roles
|
||||
await config.users.getRoles()
|
||||
|
||||
// Add users with each role
|
||||
const admin = generateUser(1, "admin")
|
||||
expect(admin[0].builder?.global).toEqual(true)
|
||||
expect(admin[0].admin?.global).toEqual(true)
|
||||
|
@ -34,6 +38,7 @@ describe("Internal API - User Management & Permissions", () => {
|
|||
|
||||
await config.users.addMultiple(userList)
|
||||
|
||||
// Check users are added
|
||||
const [allUsersResponse, allUsersJson] = await config.users.getAll()
|
||||
expect(allUsersJson.length).toBeGreaterThan(0)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue