Get test passing.
This commit is contained in:
parent
aa124524d4
commit
f1decee010
|
@ -25,6 +25,8 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import tk from "timekeeper"
|
import tk from "timekeeper"
|
||||||
|
|
||||||
|
jest.setTimeout(99999999)
|
||||||
|
|
||||||
describe("/applications", () => {
|
describe("/applications", () => {
|
||||||
let config = setup.getConfig()
|
let config = setup.getConfig()
|
||||||
let app: App
|
let app: App
|
||||||
|
@ -257,7 +259,7 @@ describe("/applications", () => {
|
||||||
|
|
||||||
describe("permissions", () => {
|
describe("permissions", () => {
|
||||||
it.only("should only return apps a user has access to", async () => {
|
it.only("should only return apps a user has access to", async () => {
|
||||||
const user = await config.createUser({
|
let user = await config.createUser({
|
||||||
builder: { global: false },
|
builder: { global: false },
|
||||||
admin: { global: false },
|
admin: { global: false },
|
||||||
})
|
})
|
||||||
|
@ -280,10 +282,10 @@ describe("/applications", () => {
|
||||||
expect(apps).toHaveLength(0)
|
expect(apps).toHaveLength(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
await config.api.user.update({
|
user = await config.globalUser({
|
||||||
...user,
|
...user,
|
||||||
builder: {
|
builder: {
|
||||||
[config.getAppId()]: true,
|
apps: [config.getProdAppId()],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -363,6 +363,7 @@ export default class TestConfiguration {
|
||||||
_id,
|
_id,
|
||||||
...existing,
|
...existing,
|
||||||
...config,
|
...config,
|
||||||
|
_rev: existing._rev,
|
||||||
email,
|
email,
|
||||||
roles,
|
roles,
|
||||||
tenantId,
|
tenantId,
|
||||||
|
@ -372,11 +373,12 @@ export default class TestConfiguration {
|
||||||
admin,
|
admin,
|
||||||
}
|
}
|
||||||
await sessions.createASession(_id, {
|
await sessions.createASession(_id, {
|
||||||
sessionId: "sessionid",
|
sessionId: this.sessionIdForUser(_id),
|
||||||
tenantId: this.getTenantId(),
|
tenantId: this.getTenantId(),
|
||||||
csrfToken: this.csrfToken,
|
csrfToken: this.csrfToken,
|
||||||
})
|
})
|
||||||
const resp = await db.put(user)
|
const resp = await db.put(user)
|
||||||
|
await cache.user.invalidateUser(_id)
|
||||||
return {
|
return {
|
||||||
_rev: resp.rev,
|
_rev: resp.rev,
|
||||||
...user,
|
...user,
|
||||||
|
@ -384,9 +386,7 @@ export default class TestConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
async createUser(user: Partial<User> = {}): Promise<User> {
|
async createUser(user: Partial<User> = {}): Promise<User> {
|
||||||
const resp = await this.globalUser(user)
|
return await this.globalUser(user)
|
||||||
await cache.user.invalidateUser(resp._id!)
|
|
||||||
return resp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async createGroup(roleId: string = roles.BUILTIN_ROLE_IDS.BASIC) {
|
async createGroup(roleId: string = roles.BUILTIN_ROLE_IDS.BASIC) {
|
||||||
|
@ -416,6 +416,10 @@ export default class TestConfiguration {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sessionIdForUser(userId: string): string {
|
||||||
|
return `sessionid-${userId}`
|
||||||
|
}
|
||||||
|
|
||||||
async login({
|
async login({
|
||||||
roleId,
|
roleId,
|
||||||
userId,
|
userId,
|
||||||
|
@ -442,13 +446,13 @@ export default class TestConfiguration {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
await sessions.createASession(userId, {
|
await sessions.createASession(userId, {
|
||||||
sessionId: "sessionid",
|
sessionId: this.sessionIdForUser(userId),
|
||||||
tenantId: this.getTenantId(),
|
tenantId: this.getTenantId(),
|
||||||
})
|
})
|
||||||
// have to fake this
|
// have to fake this
|
||||||
const authObj = {
|
const authObj = {
|
||||||
userId,
|
userId,
|
||||||
sessionId: "sessionid",
|
sessionId: this.sessionIdForUser(userId),
|
||||||
tenantId: this.getTenantId(),
|
tenantId: this.getTenantId(),
|
||||||
}
|
}
|
||||||
const authToken = jwt.sign(authObj, coreEnv.JWT_SECRET as Secret)
|
const authToken = jwt.sign(authObj, coreEnv.JWT_SECRET as Secret)
|
||||||
|
@ -470,7 +474,7 @@ export default class TestConfiguration {
|
||||||
const user = this.getUser()
|
const user = this.getUser()
|
||||||
const authObj: AuthToken = {
|
const authObj: AuthToken = {
|
||||||
userId: user._id!,
|
userId: user._id!,
|
||||||
sessionId: "sessionid",
|
sessionId: this.sessionIdForUser(user._id!),
|
||||||
tenantId,
|
tenantId,
|
||||||
}
|
}
|
||||||
const authToken = jwt.sign(authObj, coreEnv.JWT_SECRET as Secret)
|
const authToken = jwt.sign(authObj, coreEnv.JWT_SECRET as Secret)
|
||||||
|
|
Loading…
Reference in New Issue