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", "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": "lerna run test && yarn test:pro",
"test:pro": "bash scripts/pro/test.sh", "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:prettier": "prettier --check \"packages/**/*.{js,ts,svelte}\"",
"lint": "yarn run lint:eslint && yarn run lint:prettier", "lint": "yarn run lint:eslint && yarn run lint:prettier",
"lint:fix:eslint": "eslint --fix packages qa-core", "lint:fix:eslint": "eslint --fix packages qa-core",

View File

@ -38,8 +38,8 @@ export default class UserManagementApi {
const body = { const body = {
create: { create: {
users: userList, users: userList,
groups: [] groups: [],
} },
} }
const response = await this.api.post(`/global/users/bulk`, { body }) const response = await this.api.post(`/global/users/bulk`, { body })
const json = await response.json() const json = await response.json()
@ -52,10 +52,8 @@ export default class UserManagementApi {
async deleteMultiple(userId: string[]): Promise<[Response, responseMessage]> { async deleteMultiple(userId: string[]): Promise<[Response, responseMessage]> {
const body = { const body = {
delete: { delete: {
userIds: [ userIds: [userId],
userId },
]
}
} }
const response = await this.api.post(`/global/users/bulk`, { body }) const response = await this.api.post(`/global/users/bulk`, { body })
const json = await response.json() 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? // Applications type doesn't work here, save to add useTemplate parameter?
export const appFromTemplate = (): any => { export const appFromTemplate = (): any => {
return ({ return {
name: generator.word(), name: generator.word(),
url: `/${generator.word()}`, url: `/${generator.word()}`,
useTemplate: "true", useTemplate: "true",
templateName: "Near Miss Register", templateName: "Near Miss Register",
templateKey: "app/near-miss-register", templateKey: "app/near-miss-register",
templateFile: undefined, templateFile: undefined,
})
} }
}

View File

@ -1,79 +1,81 @@
import generator from "../../generator"; import generator from "../../generator"
import { User } from "@budibase/types"; import { User } from "@budibase/types"
const generateDeveloper = (): Partial<User> => { const generateDeveloper = (): Partial<User> => {
const randomId = generator.guid(); const randomId = generator.guid()
return ({ return {
email: `pedro+${randomId}@budibase.com`, email: `pedro+${randomId}@budibase.com`,
password: randomId, password: randomId,
roles: {}, roles: {},
forceResetPassword: true, forceResetPassword: true,
builder: { builder: {
global: true global: true,
},
} }
})
} }
const generateAdmin = (): Partial<User> => { const generateAdmin = (): Partial<User> => {
const randomId = generator.guid(); const randomId = generator.guid()
return ({ return {
email: `pedro+${randomId}@budibase.com`, email: `pedro+${randomId}@budibase.com`,
password: randomId, password: randomId,
roles: {}, roles: {},
forceResetPassword: true, forceResetPassword: true,
admin: { admin: {
global: true global: true,
}, },
builder: { builder: {
global: true global: true,
},
} }
})
} }
const generateAppUser = (): Partial<User> => { const generateAppUser = (): Partial<User> => {
const randomId = generator.guid(); const randomId = generator.guid()
return ({ return {
email: `pedro+${randomId}@budibase.com`, email: `pedro+${randomId}@budibase.com`,
password: randomId, password: randomId,
roles: {}, roles: {},
forceResetPassword: true, forceResetPassword: true,
admin: { admin: {
global: false global: false,
}, },
builder: { builder: {
global: false global: false,
},
} }
})
} }
export const generateInviteUser = (): Object[] => { export const generateInviteUser = (): Object[] => {
const randomId = generator.guid(); const randomId = generator.guid()
return [{ return [
{
email: `pedro+${randomId}@budibase.com`, email: `pedro+${randomId}@budibase.com`,
userInfo: { userInfo: {
userGroups: [] userGroups: [],
} },
}] },
]
} }
export const generateUser = (amount: number = 1, role?: string): Partial<User>[] => { export const generateUser = (
const userList: Partial<User>[] = []; amount: number = 1,
role?: string
): Partial<User>[] => {
const userList: Partial<User>[] = []
for (let i = 0; i < amount; i++) { for (let i = 0; i < amount; i++) {
switch (role) { switch (role) {
case "admin": case "admin":
userList.push(generateAdmin()); userList.push(generateAdmin())
break; break
case "developer": case "developer":
userList.push(generateDeveloper()); userList.push(generateDeveloper())
break; break
case "appUser": case "appUser":
userList.push(generateAppUser()); userList.push(generateAppUser())
break; break
default: default:
userList.push(generateAppUser()); userList.push(generateAppUser())
break; break
} }
} }
return userList 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 { Application } from "@budibase/server/api/controllers/public/mapping/types"
import { db } from "@budibase/backend-core" import { db } from "@budibase/backend-core"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" 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 generator from "../../../config/generator"
import generateScreen from "../../../config/internal-api/fixtures/screens" import generateScreen from "../../../config/internal-api/fixtures/screens"
@ -18,7 +21,6 @@ describe("Internal API - Application creation, update, publish and delete", () =
await config.afterAll() await config.afterAll()
}) })
it("Get applications without applications", async () => { it("Get applications without applications", async () => {
await config.applications.fetchEmptyAppList() await config.applications.fetchEmptyAppList()
}) })

View File

@ -1,7 +1,10 @@
import TestConfiguration from "../../../config/internal-api/TestConfiguration" import TestConfiguration from "../../../config/internal-api/TestConfiguration"
import { App } from "@budibase/types" import { App } from "@budibase/types"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" 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 { Screen } from "@budibase/types"
import generateScreen from "../../../config/internal-api/fixtures/screens" import generateScreen from "../../../config/internal-api/fixtures/screens"

View File

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

View File

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