import { ApiKey, ApplicationEvent, ApplicationEventName, CustomDomain, CustomDomainStatus, GitBranchType, GitRepo, KeyAlgorithm, OAuthApp, OtpModel, OtpState, OtpType, ProjectMember, SigningKey, } from '@activepieces/ee-shared' import { LATEST_CONTEXT_VERSION } from '@activepieces/pieces-framework' import { apDayjs } from '@activepieces/server-shared' import { AiOverageState, AIProvider, AIProviderName, apId, AppConnection, AppConnectionScope, AppConnectionStatus, AppConnectionType, assertNotNullOrUndefined, Cell, ColorName, Field, FieldType, File, FileCompression, FileLocation, FileType, FilteredPieceBehavior, Flow, FlowOperationStatus, FlowRun, FlowRunStatus, FlowStatus, FlowTriggerType, FlowVersion, FlowVersionState, InvitationStatus, InvitationType, PackageType, PiecesFilterType, PieceType, Platform, PlatformPlan, PlatformRole, Project, ProjectIcon, ProjectPlan, ProjectRelease, ProjectReleaseType, ProjectRole, ProjectType, Record, RoleType, RunEnvironment, Table, TeamProjectsLimit, Template, TemplateStatus, TemplateType, User, UserIdentity, UserIdentityProvider, UserInvitation, UserStatus, } from '@activepieces/shared' import { faker } from '@faker-js/faker' import bcrypt from 'bcrypt' import dayjs from 'dayjs' import { AIProviderSchema } from '../../../src/app/ai/ai-provider-entity' import { databaseConnection } from '../../../src/app/database/database-connection' import { generateApiKey } from '../../../src/app/ee/api-keys/api-key-service' import { OAuthAppWithEncryptedSecret } from '../../../src/app/ee/oauth-apps/oauth-app.entity' import { PlatformPlanEntity } from '../../../src/app/ee/platform/platform-plan/platform-plan.entity' import { encryptUtils } from '../../../src/app/helper/encryption' import { PieceMetadataSchema } from '../../../src/app/pieces/metadata/piece-metadata-entity' import { PieceTagSchema } from '../../../src/app/pieces/tags/pieces/piece-tag.entity' import { TagEntitySchema } from '../../../src/app/pieces/tags/tag-entity' export const CLOUD_PLATFORM_ID = 'cloud-id' export const createMockUserIdentity = (userIdentity?: Partial): UserIdentity => { return { id: userIdentity?.id ?? apId(), created: userIdentity?.created ?? faker.date.recent().toISOString(), updated: userIdentity?.updated ?? faker.date.recent().toISOString(), email: (userIdentity?.email ?? faker.internet.email()).toLowerCase().trim(), firstName: userIdentity?.firstName ?? faker.person.firstName(), lastName: userIdentity?.lastName ?? faker.person.lastName(), tokenVersion: userIdentity?.tokenVersion ?? undefined, password: userIdentity?.password ? bcrypt.hashSync(userIdentity.password, 10) : faker.internet.password(), trackEvents: userIdentity?.trackEvents ?? faker.datatype.boolean(), newsLetter: userIdentity?.newsLetter ?? faker.datatype.boolean(), verified: userIdentity?.verified ?? faker.datatype.boolean(), provider: userIdentity?.provider ?? UserIdentityProvider.EMAIL, } } export const createMockUser = (user?: Partial): User => { return { id: user?.id ?? apId(), created: user?.created ?? faker.date.recent().toISOString(), updated: user?.updated ?? faker.date.recent().toISOString(), status: user?.status ?? UserStatus.ACTIVE, platformRole: user?.platformRole ?? faker.helpers.enumValue(PlatformRole), externalId: user?.externalId, identityId: user?.identityId ?? apId(), platformId: user?.platformId ?? null, } } export const createMockOAuthApp = async ( oAuthApp?: Partial, ): Promise => { return { id: oAuthApp?.id ?? apId(), created: oAuthApp?.created ?? faker.date.recent().toISOString(), updated: oAuthApp?.updated ?? faker.date.recent().toISOString(), platformId: oAuthApp?.platformId ?? apId(), pieceName: oAuthApp?.pieceName ?? faker.lorem.word(), clientId: oAuthApp?.clientId ?? apId(), clientSecret: await encryptUtils.encryptString(faker.lorem.word()), } } export const createMockTemplate = ( template?: Partial