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