fixing tests
This commit is contained in:
parent
c4f424cb80
commit
be396dc3c0
|
@ -9,6 +9,7 @@ import {
|
|||
getTenantIDFromAppID,
|
||||
} from "../context"
|
||||
import env from "../environment"
|
||||
import { PlatformUser, PlatformUserByEmail } from "@budibase/types"
|
||||
|
||||
const TENANT_DOC = StaticDatabases.PLATFORM_INFO.docs.tenants
|
||||
const PLATFORM_INFO_DB = StaticDatabases.PLATFORM_INFO.name
|
||||
|
@ -108,13 +109,15 @@ export const lookupTenantId = async (userId: string) => {
|
|||
}
|
||||
|
||||
// lookup, could be email or userId, either will return a doc
|
||||
export const getTenantUser = async (identifier: string) => {
|
||||
export const getTenantUser = async (
|
||||
identifier: string
|
||||
): Promise<PlatformUser | null> => {
|
||||
// use the view here and allow to find anyone regardless of casing
|
||||
// Use lowercase to ensure email login is case insensitive
|
||||
const response = await queryPlatformView(ViewName.PLATFORM_USERS_LOWERCASE, {
|
||||
const response = queryPlatformView(ViewName.PLATFORM_USERS_LOWERCASE, {
|
||||
keys: [identifier.toLowerCase()],
|
||||
include_docs: true,
|
||||
})
|
||||
}) as Promise<PlatformUser>
|
||||
return response
|
||||
}
|
||||
|
||||
|
|
|
@ -7,3 +7,12 @@ export interface PlatformUserByEmail extends Document {
|
|||
tenantId: string
|
||||
userId: string
|
||||
}
|
||||
|
||||
/**
|
||||
* doc id is userId
|
||||
*/
|
||||
export interface PlatformUserById extends Document {
|
||||
tenantId: string
|
||||
}
|
||||
|
||||
export type PlatformUser = PlatformUserByEmail | PlatformUserById
|
||||
|
|
|
@ -248,7 +248,7 @@ describe("/api/global/users", () => {
|
|||
await api.users.saveUser(user)
|
||||
|
||||
user.email = user.email.toUpperCase()
|
||||
await api.users.saveUser(user)
|
||||
await api.users.saveUser(user, 400)
|
||||
|
||||
expect(events.user.created).toBeCalledTimes(1)
|
||||
})
|
||||
|
|
|
@ -164,7 +164,7 @@ const buildUser = async (
|
|||
const validateUniqueUser = async (email: string, tenantId: string) => {
|
||||
// check budibase users in other tenants
|
||||
if (env.MULTI_TENANCY) {
|
||||
const tenantUser = (await tenancy.getTenantUser(email)) as User | undefined
|
||||
const tenantUser = await tenancy.getTenantUser(email)
|
||||
if (tenantUser != null && tenantUser.tenantId !== tenantId) {
|
||||
throw `Unavailable`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue