Get tests passing again.
This commit is contained in:
parent
7ac2449201
commit
c81ca66aa4
|
@ -27,15 +27,17 @@ describe("/users", () => {
|
|||
|
||||
describe("fetch", () => {
|
||||
it("returns a list of users from an instance db", async () => {
|
||||
await config.createUser({ id: "uuidx" })
|
||||
await config.createUser({ id: "uuidy" })
|
||||
const id1 = `us_${utils.newid()}`
|
||||
const id2 = `us_${utils.newid()}`
|
||||
await config.createUser({ _id: id1 })
|
||||
await config.createUser({ _id: id2 })
|
||||
|
||||
const res = await config.api.user.fetch()
|
||||
expect(res.length).toBe(3)
|
||||
|
||||
const ids = res.map(u => u._id)
|
||||
expect(ids).toContain(`ro_ta_users_us_uuidx`)
|
||||
expect(ids).toContain(`ro_ta_users_us_uuidy`)
|
||||
expect(ids).toContain(`ro_ta_users_${id1}`)
|
||||
expect(ids).toContain(`ro_ta_users_${id2}`)
|
||||
})
|
||||
|
||||
it("should apply authorization to endpoint", async () => {
|
||||
|
@ -54,7 +56,7 @@ describe("/users", () => {
|
|||
describe("update", () => {
|
||||
it("should be able to update the user", async () => {
|
||||
const user: UserMetadata = await config.createUser({
|
||||
id: `us_update${utils.newid()}`,
|
||||
_id: `us_update${utils.newid()}`,
|
||||
})
|
||||
user.roleId = roles.BUILTIN_ROLE_IDS.BASIC
|
||||
delete user._rev
|
||||
|
|
|
@ -40,7 +40,7 @@ describe("migrations", () => {
|
|||
|
||||
describe("backfill", () => {
|
||||
it("runs app db migration", async () => {
|
||||
await config.doInContext(null, async () => {
|
||||
await config.doInContext(undefined, async () => {
|
||||
await clearMigrations()
|
||||
await config.createAutomation()
|
||||
await config.createAutomation(structures.newAutomation())
|
||||
|
@ -93,18 +93,18 @@ describe("migrations", () => {
|
|||
})
|
||||
|
||||
it("runs global db migration", async () => {
|
||||
await config.doInContext(null, async () => {
|
||||
await config.doInContext(undefined, async () => {
|
||||
await clearMigrations()
|
||||
const appId = config.prodAppId
|
||||
const appId = config.getProdAppId()
|
||||
const roles = { [appId]: "role_12345" }
|
||||
await config.createUser({
|
||||
builder: false,
|
||||
admin: true,
|
||||
builder: { global: false },
|
||||
admin: { global: true },
|
||||
roles,
|
||||
}) // admin only
|
||||
await config.createUser({
|
||||
builder: false,
|
||||
admin: false,
|
||||
builder: { global: false },
|
||||
admin: { global: false },
|
||||
roles,
|
||||
}) // non admin non builder
|
||||
await config.createTable()
|
||||
|
|
|
@ -43,8 +43,8 @@ async function createUser(email: string, roles: UserRoles, builder?: boolean) {
|
|||
const user = await config.createUser({
|
||||
email,
|
||||
roles,
|
||||
builder: builder || false,
|
||||
admin: false,
|
||||
builder: { global: builder || false },
|
||||
admin: { global: false },
|
||||
})
|
||||
await context.doInContext(config.appId!, async () => {
|
||||
await events.user.created(user)
|
||||
|
@ -55,10 +55,10 @@ async function createUser(email: string, roles: UserRoles, builder?: boolean) {
|
|||
async function removeUserRole(user: User) {
|
||||
const final = await config.globalUser({
|
||||
...user,
|
||||
id: user._id,
|
||||
_id: user._id,
|
||||
roles: {},
|
||||
builder: false,
|
||||
admin: false,
|
||||
builder: { global: false },
|
||||
admin: { global: false },
|
||||
})
|
||||
await context.doInContext(config.appId!, async () => {
|
||||
await events.user.updated(final)
|
||||
|
@ -69,8 +69,8 @@ async function createGroupAndUser(email: string) {
|
|||
groupUser = await config.createUser({
|
||||
email,
|
||||
roles: {},
|
||||
builder: false,
|
||||
admin: false,
|
||||
builder: { global: false },
|
||||
admin: { global: false },
|
||||
})
|
||||
group = await config.createGroup()
|
||||
await config.addUserToGroup(group._id!, groupUser._id!)
|
||||
|
|
|
@ -22,15 +22,18 @@ describe("syncGlobalUsers", () => {
|
|||
expect(metadata).toHaveLength(1)
|
||||
expect(metadata).toEqual([
|
||||
expect.objectContaining({
|
||||
_id: db.generateUserMetadataID(config.user._id),
|
||||
_id: db.generateUserMetadataID(config.getUser()._id!),
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
it("admin and builders users are synced", async () => {
|
||||
const user1 = await config.createUser({ admin: true })
|
||||
const user2 = await config.createUser({ admin: false, builder: true })
|
||||
const user1 = await config.createUser({ admin: { global: true } })
|
||||
const user2 = await config.createUser({
|
||||
admin: { global: false },
|
||||
builder: { global: true },
|
||||
})
|
||||
await config.doInContext(config.appId, async () => {
|
||||
expect(await rawUserMetadata()).toHaveLength(1)
|
||||
await syncGlobalUsers()
|
||||
|
@ -51,7 +54,10 @@ describe("syncGlobalUsers", () => {
|
|||
})
|
||||
|
||||
it("app users are not synced if not specified", async () => {
|
||||
const user = await config.createUser({ admin: false, builder: false })
|
||||
const user = await config.createUser({
|
||||
admin: { global: false },
|
||||
builder: { global: false },
|
||||
})
|
||||
await config.doInContext(config.appId, async () => {
|
||||
await syncGlobalUsers()
|
||||
|
||||
|
@ -68,8 +74,14 @@ describe("syncGlobalUsers", () => {
|
|||
it("app users are added when group is assigned to app", async () => {
|
||||
await config.doInTenant(async () => {
|
||||
const group = await proSdk.groups.save(structures.userGroups.userGroup())
|
||||
const user1 = await config.createUser({ admin: false, builder: false })
|
||||
const user2 = await config.createUser({ admin: false, builder: false })
|
||||
const user1 = await config.createUser({
|
||||
admin: { global: false },
|
||||
builder: { global: false },
|
||||
})
|
||||
const user2 = await config.createUser({
|
||||
admin: { global: false },
|
||||
builder: { global: false },
|
||||
})
|
||||
await proSdk.groups.addUsers(group.id, [user1._id!, user2._id!])
|
||||
|
||||
await config.doInContext(config.appId, async () => {
|
||||
|
@ -103,8 +115,14 @@ describe("syncGlobalUsers", () => {
|
|||
it("app users are removed when app is removed from user group", async () => {
|
||||
await config.doInTenant(async () => {
|
||||
const group = await proSdk.groups.save(structures.userGroups.userGroup())
|
||||
const user1 = await config.createUser({ admin: false, builder: false })
|
||||
const user2 = await config.createUser({ admin: false, builder: false })
|
||||
const user1 = await config.createUser({
|
||||
admin: { global: false },
|
||||
builder: { global: false },
|
||||
})
|
||||
const user2 = await config.createUser({
|
||||
admin: { global: false },
|
||||
builder: { global: false },
|
||||
})
|
||||
await proSdk.groups.updateGroupApps(group.id, {
|
||||
appsToAdd: [
|
||||
{ appId: config.prodAppId!, roleId: roles.BUILTIN_ROLE_IDS.BASIC },
|
||||
|
|
|
@ -307,23 +307,28 @@ export default class TestConfiguration {
|
|||
builder = { global: true },
|
||||
admin = { global: false },
|
||||
email = generator.email(),
|
||||
roles,
|
||||
tenantId = this.getTenantId(),
|
||||
roles = {},
|
||||
} = config
|
||||
|
||||
const db = tenancy.getTenantDB(this.getTenantId())
|
||||
let existing
|
||||
let existing: Partial<User> = {}
|
||||
try {
|
||||
existing = await db.get<User>(_id)
|
||||
} catch (err) {
|
||||
existing = { email }
|
||||
// ignore
|
||||
}
|
||||
const user: User = {
|
||||
_id: _id,
|
||||
_id,
|
||||
...existing,
|
||||
roles: roles || {},
|
||||
tenantId: this.getTenantId(),
|
||||
...config,
|
||||
email,
|
||||
roles,
|
||||
tenantId,
|
||||
firstName,
|
||||
lastName,
|
||||
builder,
|
||||
admin,
|
||||
}
|
||||
await sessions.createASession(_id, {
|
||||
sessionId: "sessionid",
|
||||
|
@ -331,7 +336,10 @@ export default class TestConfiguration {
|
|||
csrfToken: this.csrfToken,
|
||||
})
|
||||
const resp = await db.put(user)
|
||||
return { _rev: resp.rev, ...user }
|
||||
return {
|
||||
_rev: resp.rev,
|
||||
...user,
|
||||
}
|
||||
}
|
||||
|
||||
async createUser(user: Partial<User> = {}): Promise<User> {
|
||||
|
@ -751,7 +759,7 @@ export default class TestConfiguration {
|
|||
if (!automation) {
|
||||
return
|
||||
}
|
||||
return this._req(automationController.destroy, {
|
||||
return this._req(automationController.destroy, undefined, {
|
||||
id: automation._id,
|
||||
rev: automation._rev,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue