diff --git a/packages/backend-core/tests/utilities/structures/accounts.ts b/packages/backend-core/tests/utilities/structures/accounts.ts index 6bfeedf196..62a9ac19d1 100644 --- a/packages/backend-core/tests/utilities/structures/accounts.ts +++ b/packages/backend-core/tests/utilities/structures/accounts.ts @@ -8,6 +8,8 @@ import { CloudAccount, Hosting, SSOAccount, + CreateAccount, + CreatePassswordAccount, } from "@budibase/types" import _ from "lodash" @@ -29,6 +31,10 @@ export const account = (): Account => { } } +export function selfHostAccount() { + return account() +} + export const cloudAccount = (): CloudAccount => { return { ...account(), @@ -47,9 +53,9 @@ function provider(): AccountSSOProvider { return _.sample(Object.values(AccountSSOProvider)) as AccountSSOProvider } -export function ssoAccount(): SSOAccount { +export function ssoAccount(account: Account = cloudAccount()): SSOAccount { return { - ...cloudAccount(), + ...account, authType: AuthType.SSO, oauth2: { accessToken: generator.string(), @@ -61,3 +67,49 @@ export function ssoAccount(): SSOAccount { thirdPartyProfile: {}, } } + +export const cloudCreateAccount: CreatePassswordAccount = { + email: "cloud@budibase.com", + tenantId: "cloud", + hosting: Hosting.CLOUD, + authType: AuthType.PASSWORD, + password: "Password123!", + tenantName: "cloud", + name: "Budi Armstrong", + size: "10+", + profession: "Software Engineer", +} + +export const cloudSSOCreateAccount: CreateAccount = { + email: "cloud-sso@budibase.com", + tenantId: "cloud-sso", + hosting: Hosting.CLOUD, + authType: AuthType.SSO, + tenantName: "cloudsso", + name: "Budi Armstrong", + size: "10+", + profession: "Software Engineer", +} + +export const selfCreateAccount: CreatePassswordAccount = { + email: "self@budibase.com", + tenantId: "self", + hosting: Hosting.SELF, + authType: AuthType.PASSWORD, + password: "Password123!", + tenantName: "self", + name: "Budi Armstrong", + size: "10+", + profession: "Software Engineer", +} + +export const selfSSOCreateAccount: CreateAccount = { + email: "self-sso@budibase.com", + tenantId: "self-sso", + hosting: Hosting.SELF, + authType: AuthType.SSO, + tenantName: "selfsso", + name: "Budi Armstrong", + size: "10+", + profession: "Software Engineer", +} diff --git a/packages/backend-core/tests/utilities/structures/sso.ts b/packages/backend-core/tests/utilities/structures/sso.ts index a5957c9233..7413fa3c09 100644 --- a/packages/backend-core/tests/utilities/structures/sso.ts +++ b/packages/backend-core/tests/utilities/structures/sso.ts @@ -1,6 +1,7 @@ import { GoogleInnerConfig, JwtClaims, + OAuth2, OIDCInnerConfig, OIDCWellKnownConfig, SSOAuthDetails, @@ -14,6 +15,13 @@ import * as shared from "./shared" import _ from "lodash" import { user } from "./shared" +export function OAuth(): OAuth2 { + return { + refreshToken: generator.string(), + accessToken: generator.string(), + } +} + export function authDetails(userDoc?: User): SSOAuthDetails { if (!userDoc) { userDoc = user() @@ -28,10 +36,7 @@ export function authDetails(userDoc?: User): SSOAuthDetails { return { email: userDoc.email, - oauth2: { - refreshToken: generator.string(), - accessToken: generator.string(), - }, + oauth2: OAuth(), profile, provider, providerType: providerType(), diff --git a/packages/types/src/documents/global/user.ts b/packages/types/src/documents/global/user.ts index 2ef13a7412..af48dbb758 100644 --- a/packages/types/src/documents/global/user.ts +++ b/packages/types/src/documents/global/user.ts @@ -48,13 +48,18 @@ export interface User extends Document { global: boolean } password?: string - status?: string + status?: UserStatus createdAt?: number // override the default createdAt behaviour - users sdk historically set this to Date.now() dayPassRecordedAt?: string userGroups?: string[] onboardedAt?: string } +export enum UserStatus { + ACTIVE = "active", + INACTIVE = "inactive", +} + export interface UserRoles { [key: string]: string }