This commit is contained in:
mike12345567 2023-01-06 16:46:50 +00:00
parent 1e046b9d7f
commit 60371d828e
9 changed files with 902 additions and 822 deletions

View File

@ -45,7 +45,7 @@
"dev:server": "yarn run kill-server && lerna run --parallel dev:builder --concurrency 1 --scope @budibase/backend-core --scope @budibase/worker --scope @budibase/server",
"test": "lerna run test && yarn test:pro",
"test:pro": "bash scripts/pro/test.sh",
"lint:eslint": "eslint packages",
"lint:eslint": "eslint packages && eslint qa-core",
"lint:prettier": "prettier --check \"packages/**/*.{js,ts,svelte}\"",
"lint": "yarn run lint:eslint && yarn run lint:prettier",
"lint:fix:eslint": "eslint --fix packages qa-core",

View File

@ -38,8 +38,8 @@ export default class UserManagementApi {
const body = {
create: {
users: userList,
groups: []
}
groups: [],
},
}
const response = await this.api.post(`/global/users/bulk`, { body })
const json = await response.json()
@ -52,10 +52,8 @@ export default class UserManagementApi {
async deleteMultiple(userId: string[]): Promise<[Response, responseMessage]> {
const body = {
delete: {
userIds: [
userId
]
}
userIds: [userId],
},
}
const response = await this.api.post(`/global/users/bulk`, { body })
const json = await response.json()

View File

@ -13,13 +13,12 @@ export const generateApp = (
// Applications type doesn't work here, save to add useTemplate parameter?
export const appFromTemplate = (): any => {
return ({
return {
name: generator.word(),
url: `/${generator.word()}`,
useTemplate: "true",
templateName: "Near Miss Register",
templateKey: "app/near-miss-register",
templateFile: undefined,
})
}
}

View File

@ -1,79 +1,81 @@
import generator from "../../generator";
import { User } from "@budibase/types";
import generator from "../../generator"
import { User } from "@budibase/types"
const generateDeveloper = (): Partial<User> => {
const randomId = generator.guid();
return ({
const randomId = generator.guid()
return {
email: `pedro+${randomId}@budibase.com`,
password: randomId,
roles: {},
forceResetPassword: true,
builder: {
global: true
global: true,
},
}
})
}
const generateAdmin = (): Partial<User> => {
const randomId = generator.guid();
return ({
const randomId = generator.guid()
return {
email: `pedro+${randomId}@budibase.com`,
password: randomId,
roles: {},
forceResetPassword: true,
admin: {
global: true
global: true,
},
builder: {
global: true
global: true,
},
}
})
}
const generateAppUser = (): Partial<User> => {
const randomId = generator.guid();
return ({
const randomId = generator.guid()
return {
email: `pedro+${randomId}@budibase.com`,
password: randomId,
roles: {},
forceResetPassword: true,
admin: {
global: false
global: false,
},
builder: {
global: false
global: false,
},
}
})
}
export const generateInviteUser = (): Object[] => {
const randomId = generator.guid();
return [{
const randomId = generator.guid()
return [
{
email: `pedro+${randomId}@budibase.com`,
userInfo: {
userGroups: []
}
}]
userGroups: [],
},
},
]
}
export const generateUser = (amount: number = 1, role?: string): Partial<User>[] => {
const userList: Partial<User>[] = [];
export const generateUser = (
amount: number = 1,
role?: string
): Partial<User>[] => {
const userList: Partial<User>[] = []
for (let i = 0; i < amount; i++) {
switch (role) {
case "admin":
userList.push(generateAdmin());
break;
userList.push(generateAdmin())
break
case "developer":
userList.push(generateDeveloper());
break;
userList.push(generateDeveloper())
break
case "appUser":
userList.push(generateAppUser());
break;
userList.push(generateAppUser())
break
default:
userList.push(generateAppUser());
break;
userList.push(generateAppUser())
break
}
}
return userList

View File

@ -2,7 +2,10 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration"
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
import { db } from "@budibase/backend-core"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
import { generateApp, appFromTemplate } from "../../../config/internal-api/fixtures/applications"
import {
generateApp,
appFromTemplate,
} from "../../../config/internal-api/fixtures/applications"
import generator from "../../../config/generator"
import generateScreen from "../../../config/internal-api/fixtures/screens"
@ -18,7 +21,6 @@ describe("Internal API - Application creation, update, publish and delete", () =
await config.afterAll()
})
it("Get applications without applications", async () => {
await config.applications.fetchEmptyAppList()
})

View File

@ -1,7 +1,10 @@
import TestConfiguration from "../../../config/internal-api/TestConfiguration"
import { App } from "@budibase/types"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
import { generateApp, appFromTemplate } from "../../../config/internal-api/fixtures/applications"
import {
generateApp,
appFromTemplate,
} from "../../../config/internal-api/fixtures/applications"
import { Screen } from "@budibase/types"
import generateScreen from "../../../config/internal-api/fixtures/screens"

View File

@ -1,10 +1,16 @@
import TestConfiguration from "../../../config/internal-api/TestConfiguration"
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
import { generateApp, appFromTemplate } from "../../../config/internal-api/fixtures/applications"
import {
generateApp,
appFromTemplate,
} from "../../../config/internal-api/fixtures/applications"
import { generateUser } from "../../../config/internal-api/fixtures/userManagement"
import { User } from "@budibase/types"
import { generateNewColumnForTable, generateTable } from "../../../config/internal-api/fixtures/table"
import {
generateNewColumnForTable,
generateTable,
} from "../../../config/internal-api/fixtures/table"
import generateScreen from "../../../config/internal-api/fixtures/screens"
import { db } from "@budibase/backend-core"
@ -25,31 +31,37 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] = await config.users.addMultiple(
appUser
)
const app = await config.applications.create(appFromTemplate())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
roles: {
[<string>app.appId]: "BASIC",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
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")
})
it("Add ADMIN user to app", async () => {
const adminUser = generateUser(1, "admin")
expect(adminUser[0].builder?.global).toEqual(true)
expect(adminUser[0].admin?.global).toEqual(true)
const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser)
const [createUserResponse, createUserJson] = await config.users.addMultiple(
adminUser
)
//const app = await config.applications.create(generateApp())
//config.applications.api.appId = app.appId
@ -57,16 +69,19 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const app = await config.applications.create(appFromTemplate())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
roles: {
[<string>app.appId]: "ADMIN",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
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")
@ -75,31 +90,34 @@ describe("Internal API - App Specific Roles & Permissions", () => {
// check published app renders
config.applications.api.appId = db.getProdAppID(app.appId!)
await config.applications.canRender()
})
it("Add POWER user to app", async () => {
const powerUser = generateUser(1, 'developer')
const powerUser = generateUser(1, "developer")
expect(powerUser[0].builder?.global).toEqual(true)
const [createUserResponse, createUserJson] = await config.users.addMultiple(powerUser)
const [createUserResponse, createUserJson] = await config.users.addMultiple(
powerUser
)
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
roles: {
[<string>app.appId]: "POWER",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
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")
})
describe("Check Access for default roles", () => {
@ -107,21 +125,25 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
roles: {
[<string>app.appId]: "BASIC",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
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")
@ -130,37 +152,43 @@ describe("Internal API - App Specific Roles & Permissions", () => {
)
await config.login(<string>appUser[0].email, <string>appUser[0].password)
const newColumn = generateNewColumnForTable(createdTableData)
await config.tables.forbiddenSave(
newColumn)
await config.tables.forbiddenSave(newColumn)
await config.tables.forbiddenSave(generateTable())
})
it("Check Table access for developer", async () => {
const developer = generateUser(1, 'developer')
const developer = generateUser(1, "developer")
expect(developer[0].builder?.global).toEqual(true)
const [createUserResponse, createUserJson] = await config.users.addMultiple(developer)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(developer)
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
roles: {
[<string>app.appId]: "POWER",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
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")
const [createdTableResponse, createdTableData] = await config.tables.save(
generateTable()
)
await config.login(<string>developer[0].email, <string>developer[0].password)
await config.login(
<string>developer[0].email,
<string>developer[0].password
)
const newColumn = generateNewColumnForTable(createdTableData)
const [addColumnResponse, addColumnData] = await config.tables.save(
newColumn,
@ -172,25 +200,32 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const adminUser = generateUser(1, "admin")
expect(adminUser[0].builder?.global).toEqual(true)
expect(adminUser[0].admin?.global).toEqual(true)
const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(adminUser)
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
roles: {
[<string>app.appId]: "ADMIN",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
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")
await config.login(<string>adminUser[0].email, <string>adminUser[0].password)
await config.login(
<string>adminUser[0].email,
<string>adminUser[0].password
)
const [createdTableResponse, createdTableData] = await config.tables.save(
generateTable()
)
@ -208,14 +243,17 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -223,11 +261,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: "BASIC",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual("BASIC")
@ -236,7 +275,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -245,7 +285,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(1)
expect(appPackageJson.screens[0].routing.roleId).toEqual("BASIC")
@ -256,14 +297,17 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -271,11 +315,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: "POWER",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual("POWER")
@ -284,7 +329,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -293,7 +339,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(2)
})
@ -303,14 +350,17 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
config.applications.api.appId = app.appId
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -318,11 +368,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: "ADMIN",
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual("ADMIN")
@ -331,7 +382,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -340,7 +392,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(3)
})
@ -351,7 +404,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
@ -361,14 +415,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const role = {
inherits: "BASIC",
permissionId: "public",
name: "level 1"
name: "level 1",
}
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
const [createRoleResponse, createRoleJson] =
await config.users.createRole(role)
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -376,11 +431,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: createRoleJson._id,
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
@ -389,7 +445,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -398,15 +455,18 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(1)
})
it("Custom role access for level 2 permissions", async () => {// Set up user
it("Custom role access for level 2 permissions", async () => {
// Set up user
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
@ -416,14 +476,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const role = {
inherits: "BASIC",
permissionId: "read_only",
name: "level 2"
name: "level 2",
}
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
const [createRoleResponse, createRoleJson] =
await config.users.createRole(role)
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -431,11 +492,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: createRoleJson._id,
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
@ -444,7 +506,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -453,7 +516,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(1)
})
@ -461,7 +525,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
@ -471,14 +536,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const role = {
inherits: "BASIC",
permissionId: "write",
name: "level 3"
name: "level 3",
}
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
const [createRoleResponse, createRoleJson] =
await config.users.createRole(role)
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -486,11 +552,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: createRoleJson._id,
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
@ -499,7 +566,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -508,7 +576,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(1)
})
@ -516,7 +585,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
@ -526,14 +596,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const role = {
inherits: "BASIC",
permissionId: "power",
name: "level 4"
name: "level 4",
}
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
const [createRoleResponse, createRoleJson] =
await config.users.createRole(role)
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -541,11 +612,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: createRoleJson._id,
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
@ -554,7 +626,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -563,7 +636,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(1)
})
@ -571,7 +645,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const appUser = generateUser()
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
const [createUserResponse, createUserJson] =
await config.users.addMultiple(appUser)
// Create App
const app = await config.applications.create(generateApp())
@ -581,14 +656,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const role = {
inherits: "BASIC",
permissionId: "admin",
name: "level 5"
name: "level 5",
}
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
const [createRoleResponse, createRoleJson] =
await config.users.createRole(role)
// Update user roles
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
createUserJson.created.successful[0]._id
)
const prodAppId = db.getProdAppID(app.appId!)
// Roles must always be set with prod appID
@ -596,11 +672,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
...userInfoJson,
roles: {
[prodAppId]: createRoleJson._id,
}
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(createUserJson.created.successful[0]._id)
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
@ -609,7 +686,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
await config.screen.create(generateScreen("ADMIN"))
await config.applications.publish(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
const [firstappPackageResponse, firstappPackageJson] =
await config.applications.getAppPackage(<string>app.appId)
expect(firstappPackageJson.screens).toBeDefined()
expect(firstappPackageJson.screens.length).toEqual(3)
@ -618,10 +696,10 @@ describe("Internal API - App Specific Roles & Permissions", () => {
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
// fetch app package
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
const [appPackageResponse, appPackageJson] =
await config.applications.getAppPackage(app.appId!)
expect(appPackageJson.screens).toBeDefined()
expect(appPackageJson.screens.length).toEqual(1)
})
})
})

View File

@ -36,9 +36,6 @@ describe("Internal API - User Management & Permissions", () => {
const [allUsersResponse, allUsersJson] = await config.users.getAll()
expect(allUsersJson.length).toBeGreaterThan(0)
})
it("Delete User", async () => {
@ -55,11 +52,12 @@ describe("Internal API - User Management & Permissions", () => {
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [userResponse, userJson] = await config.users.addMultiple(appUser)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
userJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
password: "newPassword"
password: "newPassword",
}
await config.users.forcePasswordReset(body)
})
@ -69,22 +67,22 @@ describe("Internal API - User Management & Permissions", () => {
expect(appUser[0].builder?.global).toEqual(false)
expect(appUser[0].admin?.global).toEqual(false)
const [userResponse, userJson] = await config.users.addMultiple(appUser)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id)
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
userJson.created.successful[0]._id
)
const body: User = {
...userInfoJson,
firstName: "newFirstName",
lastName: "newLastName",
builder: {
global: true
}
global: true,
},
}
await config.users.updateInfo(body)
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id)
const [changedUserInfoResponse, changedUserInfoJson] =
await config.users.getInfo(userJson.created.successful[0]._id)
expect(changedUserInfoJson.builder?.global).toBeDefined()
expect(changedUserInfoJson.builder?.global).toEqual(true)
})
})

View File

@ -73,15 +73,15 @@ describe("Public API - /applications endpoints", () => {
})
it("POST - unpublish an unpublished application", async () => {
const [response] = await config.applications.unpublish(
config.context._id
)
const [response] = await config.applications.unpublish(config.context._id)
expect(response).toHaveStatusCode(400)
})
it("DELETE - delete a published application and the dev application", async () => {
await config.applications.publish(config.context._id)
const [response, deletion] = await config.applications.delete(config.context._id)
const [response, deletion] = await config.applications.delete(
config.context._id
)
expect(response).toHaveStatusCode(200)
expect(deletion._id).toEqual(config.context._id)