From 2b75d6074aae530cb35a8ba866f72cd8cb9d87b6 Mon Sep 17 00:00:00 2001 From: Artem Niehrieiev Date: Fri, 15 Sep 2023 11:27:48 +0200 Subject: [PATCH] added saas version of user invitation into group --- backend/src/app.module.ts | 4 +- backend/src/common/data-injection.tokens.ts | 1 + ...ompany-info-custom-repository.extension.ts | 8 + .../company-info-repository.interface.ts | 2 + .../entities/connection/connection.entity.ts | 16 +- .../connection.repository.interface.ts | 2 +- .../custom-connection-repository-extension.ts | 17 +- .../use-cases/create-connection.use.case.ts | 8 + .../data-sctructures/add-user-in-group.ds.ts | 10 ++ .../src/entities/group/group.controller.ts | 17 +- backend/src/entities/group/group.module.ts | 4 +- .../use-cases/add-user-in-group.use.case.ts | 3 +- .../saas-add-user-in-group-v2.use.case.ts | 167 ++++++++++++++++++ .../group/use-cases/use-cases.interfaces.ts | 6 +- .../create-or-update-permissions.use.case.ts | 3 +- .../data-structures/found-user.ds.ts | 3 + .../data-structures/usual-register-user.ds.ts | 7 + .../user-custom-repository-extension.ts | 17 +- .../repository/user.repository.interface.ts | 2 +- .../src/entities/user/user-helper.service.ts | 1 + backend/src/exceptions/text/messages.ts | 4 + .../client-microservice.module.ts | 10 -- .../client-microservice.service.ts | 33 ---- .../base-saas-gateway.service.ts | 49 +++++ ...tered-company-when-user-invite-group.ds.ts | 4 + .../saas-company-gateway.service.ts | 71 ++++++++ .../saas-gateway.ts/saas-gateway.module.ts | 12 ++ .../utils/generate-request-id.ts | 4 + .../utils/generate-saas-jwt.ts | 17 ++ .../saas-microservice/saas.controller.ts | 13 ++ .../saas-microservice/saas.module.ts | 10 +- .../UpdateUserStripeCustomerIdUseCase.ts | 35 ++++ .../add-company-id-to-user-use.case.ts | 15 +- .../use-cases/login-with-github.use.case.ts | 3 +- .../register-invited-user-use.case.ts | 78 ++++++++ .../remove-company-id-from-user.use.case.ts | 3 +- .../use-cases/saas-use-cases.interface.ts | 9 +- .../saas-usual-register-user.use.case.ts | 27 +++ ...update-user-stripe-customer-id.use.case.ts | 3 +- backend/test/ava-tests/connection-e2e.test.ts | 133 +++++++------- .../connection-properties-e2e.test.ts | 47 ++--- .../test/ava-tests/custom-field-e2e.test.ts | 10 +- backend/test/ava-tests/group-e2e.test.ts | 37 ++-- .../test/ava-tests/permissions-e2e.test.ts | 4 +- .../test/ava-tests/table-actions-e2e.test.ts | 16 +- .../ava-tests/table-mssql-agent-e2e.test.ts | 24 +-- .../ava-tests/table-mssql-cli-e2e.test.ts | 24 +-- .../test/ava-tests/table-mssql-e2e.test.ts | 24 +-- .../ava-tests/table-mssql-schema-e2e.test.ts | 24 +-- .../ava-tests/table-mysql-agent-e2e.test.ts | 24 +-- .../ava-tests/table-mysql-cli-e2e.test.ts | 24 +-- .../test/ava-tests/table-mysql-e2e.test.ts | 24 +-- .../ava-tests/table-oracle-agent-e2e.test.ts | 24 +-- .../ava-tests/table-oracle-cli-e2e.test.ts | 24 +-- .../test/ava-tests/table-oracledb-e2e.test.ts | 24 +-- .../table-oracledb-schema-e2e.test.ts | 24 +-- .../table-postgres-agent-e2e.test.ts | 24 +-- .../ava-tests/table-postgres-cli-e2e.test.ts | 24 +-- .../test/ava-tests/table-postgres-e2e.test.ts | 22 +-- .../table-postgres-encrypted-e2e.test.ts | 26 +-- .../table-postgres-schema-e2e.test.ts | 24 +-- .../test/ava-tests/table-widgets-e2e.test.ts | 8 +- .../user-admin-permissions-e2e.test.ts | 121 ++++++------- .../user-group-edit-permissions-e2e.test.ts | 117 ++++++------ ...onnection-readonly-permissions-e2e.test.ts | 85 ++++----- ...er-with-table-only-permissions-e2e.test.ts | 68 +++---- .../register-user-and-return-user-info.ts | 58 ++++++ .../user-with-different-permissions-utils.ts | 35 +++- .../command/command-executor-mssql.spec.ts | 4 +- .../command/command-executor-mysql.spec.ts | 4 +- .../command/command-executor-orecle.spec.ts | 4 +- .../command/command-executor-postgres.spec.ts | 4 +- 72 files changed, 1190 insertions(+), 647 deletions(-) create mode 100644 backend/src/entities/group/use-cases/saas-add-user-in-group-v2.use.case.ts delete mode 100644 backend/src/microservice-client/client-microservice.module.ts delete mode 100644 backend/src/microservice-client/client-microservice.service.ts create mode 100644 backend/src/microservices/gateways/saas-gateway.ts/base-saas-gateway.service.ts create mode 100644 backend/src/microservices/gateways/saas-gateway.ts/data-structures/registered-company-when-user-invite-group.ds.ts create mode 100644 backend/src/microservices/gateways/saas-gateway.ts/saas-company-gateway.service.ts create mode 100644 backend/src/microservices/gateways/saas-gateway.ts/saas-gateway.module.ts create mode 100644 backend/src/microservices/gateways/saas-gateway.ts/utils/generate-request-id.ts create mode 100644 backend/src/microservices/gateways/saas-gateway.ts/utils/generate-saas-jwt.ts create mode 100644 backend/src/microservices/saas-microservice/use-cases/UpdateUserStripeCustomerIdUseCase.ts create mode 100644 backend/src/microservices/saas-microservice/use-cases/register-invited-user-use.case.ts diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 3d35b231..31cfaece 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -28,8 +28,8 @@ import { ServeStaticModule } from '@nestjs/serve-static'; import { join } from 'path'; import path from 'path'; import { fileURLToPath } from 'url'; -import { ClientMicroserviceModule } from './microservice-client/client-microservice.module.js'; import { SaasModule } from './microservices/saas-microservice/saas.module.js'; +import { SaaSGatewayModule } from './microservices/gateways/saas-gateway.ts/saas-gateway.module.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -52,8 +52,8 @@ const __dirname = path.dirname(__filename); DatabaseModule, TableActionModule, StripeModule, - ClientMicroserviceModule, SaasModule, + SaaSGatewayModule, ServeStaticModule.forRoot({ rootPath: join(__dirname, '..', 'client'), }), diff --git a/backend/src/common/data-injection.tokens.ts b/backend/src/common/data-injection.tokens.ts index a0db2482..e5872624 100644 --- a/backend/src/common/data-injection.tokens.ts +++ b/backend/src/common/data-injection.tokens.ts @@ -115,6 +115,7 @@ export enum UseCaseType { SAAS_UPDATE_USER_STRIPE_CUSTOMER_ID = 'SAAS_UPDATE_USER_STRIPE_CUSTOMER_ID', SAAS_ADD_COMPANY_ID_TO_USER = 'SAAS_ADD_COMPANY_ID_TO_USER', SAAS_REMOVE_COMPANY_ID_FROM_USER = 'SAAS_REMOVE_COMPANY_ID_FROM_USER', + SAAS_REGISTER_INVITED_USER = 'SAAS_REGISTER_INVITED_USER', } export enum DynamicModuleEnum { diff --git a/backend/src/entities/company-info/repository/company-info-custom-repository.extension.ts b/backend/src/entities/company-info/repository/company-info-custom-repository.extension.ts index bda75fb0..a21cf012 100644 --- a/backend/src/entities/company-info/repository/company-info-custom-repository.extension.ts +++ b/backend/src/entities/company-info/repository/company-info-custom-repository.extension.ts @@ -8,4 +8,12 @@ export const companyInfoRepositoryExtension: ICompanyInfoRepository = { .where('company_info.id = :companyId', { companyId }) .getOne(); }, + + async findOneCompanyInfoByUserIdWithConnections(userId: string): Promise { + return await this.createQueryBuilder('company_info') + .leftJoinAndSelect('company_info.users', 'users') + .leftJoinAndSelect('company_info.connections', 'connections') + .where('users.id = :userId', { userId }) + .getOne(); + }, }; diff --git a/backend/src/entities/company-info/repository/company-info-repository.interface.ts b/backend/src/entities/company-info/repository/company-info-repository.interface.ts index 6335881a..6fd6f601 100644 --- a/backend/src/entities/company-info/repository/company-info-repository.interface.ts +++ b/backend/src/entities/company-info/repository/company-info-repository.interface.ts @@ -2,4 +2,6 @@ import { CompanyInfoEntity } from '../company-info.entity.js'; export interface ICompanyInfoRepository { findCompanyInfoWithUsersById(companyId: string): Promise; + + findOneCompanyInfoByUserIdWithConnections(userId: string): Promise; } diff --git a/backend/src/entities/connection/connection.entity.ts b/backend/src/entities/connection/connection.entity.ts index 8dcbdeb0..c9defa3a 100644 --- a/backend/src/entities/connection/connection.entity.ts +++ b/backend/src/entities/connection/connection.entity.ts @@ -154,28 +154,28 @@ export class ConnectionEntity { } } - @ManyToOne((type) => UserEntity, (user) => user.connections, { onDelete: 'CASCADE' }) + @ManyToOne(() => UserEntity, (user) => user.connections, { onDelete: 'CASCADE' }) author: Relation; - @OneToMany((type) => GroupEntity, (group) => group.connection) + @OneToMany(() => GroupEntity, (group) => group.connection) groups: Relation[]; - @OneToMany((type) => TableSettingsEntity, (settings) => settings.connection_id) + @OneToMany(() => TableSettingsEntity, (settings) => settings.connection_id) settings: Relation[]; - @OneToMany((type) => TableLogsEntity, (logs) => logs.connection_id) + @OneToMany(() => TableLogsEntity, (logs) => logs.connection_id) logs: Relation[]; - @OneToOne((type) => AgentEntity, (agent) => agent.connection) + @OneToOne(() => AgentEntity, (agent) => agent.connection) agent: Relation; - @OneToOne((type) => ConnectionPropertiesEntity, (connection_properties) => connection_properties.connection) + @OneToOne(() => ConnectionPropertiesEntity, (connection_properties) => connection_properties.connection) connection_properties: Relation; - @OneToMany((type) => TableInfoEntity, (table_info) => table_info.connection) + @OneToMany(() => TableInfoEntity, (table_info) => table_info.connection) tables_info: Relation[]; - @ManyToOne((type) => CompanyInfoEntity, (company) => company.connections) + @ManyToOne(() => CompanyInfoEntity, (company) => company.connections) @JoinTable() company: Relation; } diff --git a/backend/src/entities/connection/repository/connection.repository.interface.ts b/backend/src/entities/connection/repository/connection.repository.interface.ts index 4d8a0884..ac8234c9 100644 --- a/backend/src/entities/connection/repository/connection.repository.interface.ts +++ b/backend/src/entities/connection/repository/connection.repository.interface.ts @@ -33,7 +33,7 @@ export interface IConnectionRepository { getWorkedConnectionsInTwoWeeks(): Promise>; - getConnectionByGroupId(groupId: string): Promise; + getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId: string): Promise; findOneById(connectionId: string): Promise; diff --git a/backend/src/entities/connection/repository/custom-connection-repository-extension.ts b/backend/src/entities/connection/repository/custom-connection-repository-extension.ts index 8f5e29e5..a0b3ce49 100644 --- a/backend/src/entities/connection/repository/custom-connection-repository-extension.ts +++ b/backend/src/entities/connection/repository/custom-connection-repository-extension.ts @@ -83,10 +83,10 @@ export const customConnectionRepositoryExtension: IConnectionRepository = { connectionId: string, ): Promise | null> { const connectionQb = this.createQueryBuilder('connection') - .leftJoinAndSelect('connection.connection_properties', 'connection_properties') - .where('connection.id = :connectionId', { - connectionId: connectionId, - }); + .leftJoinAndSelect('connection.connection_properties', 'connection_properties') + .where('connection.id = :connectionId', { + connectionId: connectionId, + }); const connection = await connectionQb.getOne(); if (!connection) { return null; @@ -173,9 +173,12 @@ export const customConnectionRepositoryExtension: IConnectionRepository = { }); }, - async getConnectionByGroupId(groupId: string): Promise { - const qb = this.createQueryBuilder('connection').leftJoinAndSelect('connection.groups', 'group'); - qb.andWhere('group.id = :id', { id: groupId }); + async getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId: string): Promise { + const qb = this.createQueryBuilder('connection') + .leftJoinAndSelect('connection.groups', 'group') + .leftJoinAndSelect('connection.company', 'company') + .leftJoinAndSelect('company.users', 'user'); + qb.andWhere('group.id = :groupId', { groupId: groupId }); return await qb.getOne(); }, diff --git a/backend/src/entities/connection/use-cases/create-connection.use.case.ts b/backend/src/entities/connection/use-cases/create-connection.use.case.ts index efc257a2..0c5df1ff 100644 --- a/backend/src/entities/connection/use-cases/create-connection.use.case.ts +++ b/backend/src/entities/connection/use-cases/create-connection.use.case.ts @@ -57,6 +57,14 @@ export class CreateConnectionUseCase delete createdAdminGroup.connection; await this._dbContext.userRepository.saveUserEntity(connectionAuthor); createdConnection.groups = [createdAdminGroup]; + const foundUserCompany = await this._dbContext.companyInfoRepository.findOneCompanyInfoByUserIdWithConnections( + connectionAuthor.id, + ); + if (foundUserCompany) { + const connection = await this._dbContext.connectionRepository.findOneById(savedConnection.id); + connection.company = foundUserCompany; + await this._dbContext.connectionRepository.saveUpdatedConnection(connection); + } return buildCreatedConnectionDs(savedConnection, token, masterPwd); } diff --git a/backend/src/entities/group/application/data-sctructures/add-user-in-group.ds.ts b/backend/src/entities/group/application/data-sctructures/add-user-in-group.ds.ts index 2b52396d..cd01b1b1 100644 --- a/backend/src/entities/group/application/data-sctructures/add-user-in-group.ds.ts +++ b/backend/src/entities/group/application/data-sctructures/add-user-in-group.ds.ts @@ -1,4 +1,14 @@ export class AddUserInGroupDs { email: string; groupId: string; + companyId?: string; + userSaasRole?: string; +} + +export class AddUserInGroupWithSaaSDs { + email: string; + groupId: string; + companyId: string; + userSaasRole: string; + inviterId: string; } diff --git a/backend/src/entities/group/group.controller.ts b/backend/src/entities/group/group.controller.ts index c40137d8..8a70771b 100644 --- a/backend/src/entities/group/group.controller.ts +++ b/backend/src/entities/group/group.controller.ts @@ -26,18 +26,18 @@ import { SentryInterceptor } from '../../interceptors/index.js'; import { AmplitudeService } from '../amplitude/amplitude.service.js'; import { FoundUserInGroupDs } from '../user/application/data-structures/found-user-in-group.ds.js'; import { IToken, ITokenExp } from '../user/utils/generate-gwt-token.js'; -import { AddUserInGroupDs } from './application/data-sctructures/add-user-in-group.ds.js'; +import { AddUserInGroupDs, AddUserInGroupWithSaaSDs } from './application/data-sctructures/add-user-in-group.ds.js'; import { AddedUserInGroupDs } from './application/data-sctructures/added-user-in-group.ds.js'; import { DeletedGroupResultDs } from './application/data-sctructures/deleted-group-result.ds.js'; import { FoundUserGroupsDs } from './application/data-sctructures/found-user-groups.ds.js'; import { RemoveUserFromGroupResultDs } from './application/data-sctructures/remove-user-from-group-result.ds.js'; import { VerifyAddUserInGroupDs } from './application/data-sctructures/verify-add-user-in-group.ds.js'; import { - IAddUserInGroup, IDeleteGroup, IFindAllUsersInGroup, IFindUserGroups, IRemoveUserFromGroup, + ISaaSAddUserInGroup, IVerifyAddUserInGroup, } from './use-cases/use-cases.interfaces.js'; @@ -47,7 +47,7 @@ import { export class GroupController { constructor( @Inject(UseCaseType.INVITE_USER_IN_GROUP) - private readonly addUserInGroupUseCase: IAddUserInGroup, + private readonly addUserInGroupUseCase: ISaaSAddUserInGroup, @Inject(UseCaseType.VERIFY_INVITE_USER_IN_GROUP) private readonly verifyAddUserInGroupUseCase: IVerifyAddUserInGroup, @Inject(UseCaseType.FIND_ALL_USER_GROUPS) @@ -90,6 +90,8 @@ export class GroupController { @BodyEmail() email: string, @BodyUuid('groupId') groupId: string, @UserId() userId: string, + @Body('companyId') companyId: string, + @Body('role') userSaasRole: string, ): Promise { if (!email || email.length <= 0) { throw new HttpException( @@ -110,8 +112,15 @@ export class GroupController { } Cacher.increaseUserInvitationsCacheCount(userId); Cacher.increaseGroupInvitationsCacheCount(groupId); + const inputData: AddUserInGroupWithSaaSDs = { + companyId: companyId, + email: email, + groupId: groupId, + userSaasRole: userSaasRole, + inviterId: userId, + }; try { - return await this.addUserInGroupUseCase.execute({ email, groupId }, InTransactionEnum.ON); + return await this.addUserInGroupUseCase.execute(inputData, InTransactionEnum.ON); } catch (e) { throw e; } finally { diff --git a/backend/src/entities/group/group.module.ts b/backend/src/entities/group/group.module.ts index b1bdcd5d..a12d4944 100644 --- a/backend/src/entities/group/group.module.ts +++ b/backend/src/entities/group/group.module.ts @@ -12,12 +12,12 @@ import { UserEntity } from '../user/user.entity.js'; import { UserModule } from '../user/user.module.js'; import { GroupController } from './group.controller.js'; import { GroupEntity } from './group.entity.js'; -import { AddUserInGroupUseCase } from './use-cases/add-user-in-group.use.case.js'; import { DeleteGroupUseCase } from './use-cases/delete-group.use.case.js'; import { FindAllUserGroupsUseCase } from './use-cases/find-all-user-groups.use.case.js'; import { FindAllUsersInGroupUseCase } from './use-cases/find-all-users-in-group.use.case.js'; import { RemoveUserFromGroupUseCase } from './use-cases/remove-user-from-group.use.case.js'; import { VerifyAddUserInGroupUseCase } from './use-cases/verify-add-user-in-group.use.case.js'; +import { SaaSAddUserInGroupV2UseCase } from './use-cases/saas-add-user-in-group-v2.use.case.js'; @Module({ imports: [ @@ -39,7 +39,7 @@ import { VerifyAddUserInGroupUseCase } from './use-cases/verify-add-user-in-grou }, { provide: UseCaseType.INVITE_USER_IN_GROUP, - useClass: AddUserInGroupUseCase, + useClass: SaaSAddUserInGroupV2UseCase, }, { provide: UseCaseType.VERIFY_INVITE_USER_IN_GROUP, diff --git a/backend/src/entities/group/use-cases/add-user-in-group.use.case.ts b/backend/src/entities/group/use-cases/add-user-in-group.use.case.ts index 85e34122..b423ba8d 100644 --- a/backend/src/entities/group/use-cases/add-user-in-group.use.case.ts +++ b/backend/src/entities/group/use-cases/add-user-in-group.use.case.ts @@ -40,7 +40,8 @@ export class AddUserInGroupUseCase const { email, groupId } = inputData; const ownerId = await this._dbContext.connectionRepository.getConnectionAuthorIdByGroupInConnectionId(groupId); const foundGroup = await this._dbContext.groupRepository.findGroupById(groupId); - const foundUser = await this._dbContext.userRepository.findUserByEmailWithEmailVerificationAndInvitation(email); + const foundUser = + await this._dbContext.userRepository.findUserByEmailEndCompanyIdWithEmailVerificationAndInvitation(email); const foundOwner = await this._dbContext.userRepository.findOneUserById(ownerId); // eslint-disable-next-line prefer-const let { usersInConnections, usersInConnectionsCount } = diff --git a/backend/src/entities/group/use-cases/saas-add-user-in-group-v2.use.case.ts b/backend/src/entities/group/use-cases/saas-add-user-in-group-v2.use.case.ts new file mode 100644 index 00000000..d0506699 --- /dev/null +++ b/backend/src/entities/group/use-cases/saas-add-user-in-group-v2.use.case.ts @@ -0,0 +1,167 @@ +import { HttpException, HttpStatus, Inject } from '@nestjs/common'; +import AbstractUseCase from '../../../common/abstract-use.case.js'; +import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js'; +import { BaseType } from '../../../common/data-injection.tokens.js'; +import { AddUserInGroupWithSaaSDs } from '../application/data-sctructures/add-user-in-group.ds.js'; +import { AddedUserInGroupDs } from '../application/data-sctructures/added-user-in-group.ds.js'; +import { IAddUserInGroup } from './use-cases.interfaces.js'; +import { Messages } from '../../../exceptions/text/messages.js'; +import { SaasCompanyGatewayService } from '../../../microservices/gateways/saas-gateway.ts/saas-company-gateway.service.js'; +import { ConnectionEntity } from '../../connection/connection.entity.js'; +import { UserEntity } from '../../user/user.entity.js'; +import { sendEmailConfirmation, sendInvitationToGroup } from '../../email/send-email.js'; +import { UserInvitationEntity } from '../../user/user-invitation/user-invitation.entity.js'; + +export class SaaSAddUserInGroupV2UseCase + extends AbstractUseCase + implements IAddUserInGroup +{ + constructor( + @Inject(BaseType.GLOBAL_DB_CONTEXT) + protected _dbContext: IGlobalDatabaseContext, + private readonly saasCompanyGatewayService: SaasCompanyGatewayService, + ) { + super(); + } + + protected async implementation(inputData: AddUserInGroupWithSaaSDs): Promise { + const { email, groupId, inviterId } = inputData; + const foundGroup = await this._dbContext.groupRepository.findGroupById(groupId); + const foundConnection = + await this._dbContext.connectionRepository.getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId); + if (!foundConnection) { + throw new HttpException( + { + message: Messages.CONNECTION_NOT_FOUND, + }, + HttpStatus.NOT_FOUND, + ); + } + + if (!foundConnection.company) { + throw new HttpException( + { + message: Messages.COMPANY_NOT_EXISTS_IN_CONNECTION, + }, + HttpStatus.NOT_FOUND, + ); + } + + const foundUser = + await this._dbContext.userRepository.findUserByEmailEndCompanyIdWithEmailVerificationAndInvitation( + email, + foundConnection.company.id, + ); + + if (!foundUser) { + throw new HttpException( + { + message: Messages.USER_NOT_INVITED_IN_COMPANY(email), + }, + HttpStatus.BAD_REQUEST, + ); + } + const isUserInCompany = this.isUserAlreadyInCompany(foundConnection, foundUser); + const canInviteMoreUsers = await this.saasCompanyGatewayService.canInviteMoreUsers(foundConnection.company.id); + if (!canInviteMoreUsers && !isUserInCompany) { + throw new HttpException( + { + message: Messages.MAXIMUM_FREE_INVITATION_REACHED, + }, + HttpStatus.PAYMENT_REQUIRED, + ); + } + + if (foundUser && foundUser.isActive) { + const userAlreadyAdded = !!foundGroup.users.find((u) => u.id === foundUser.id); + if (userAlreadyAdded) { + throw new HttpException( + { + message: Messages.USER_ALREADY_ADDED, + }, + HttpStatus.BAD_REQUEST, + ); + } + + foundGroup.users.push(foundUser); + const savedGroup = await this._dbContext.groupRepository.saveNewOrUpdatedGroup(foundGroup); + delete savedGroup.connection; + return { + group: savedGroup, + message: Messages.USER_ADDED_IN_GROUP(foundUser.email), + external_invite: false, + }; + } + + if (foundUser && !foundUser.isActive) { + const userAlreadyAdded = !!foundGroup.users.find((u) => u.id === foundUser.id); + let savedInvitation: UserInvitationEntity; + if (userAlreadyAdded) { + savedInvitation = await this._dbContext.userInvitationRepository.createOrUpdateInvitationEntity( + foundUser, + inviterId, + ); + } else { + savedInvitation = await this._dbContext.userInvitationRepository.createOrUpdateInvitationEntity( + foundUser, + null, + ); + foundGroup.users.push(foundUser); + } + const savedGroup = await this._dbContext.groupRepository.saveNewOrUpdatedGroup(foundGroup); + delete savedGroup.connection; + const newEmailVerification = await this._dbContext.emailVerificationRepository.createOrUpdateEmailVerification( + foundUser, + ); + const confiramtionMailResult = await sendEmailConfirmation( + foundUser.email, + newEmailVerification.verification_string, + ); + + if (confiramtionMailResult?.rejected.includes(foundUser.email)) { + throw new HttpException( + { + message: Messages.FAILED_TO_SEND_CONFIRMATION_EMAIL(foundUser.email), + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + const invitationMailResult = await sendInvitationToGroup(foundUser.email, savedInvitation.verification_string); + + if (invitationMailResult?.rejected.includes(foundUser.email)) { + throw new HttpException( + { + message: Messages.FAILED_TO_SEND_INVITATION_EMAIL(foundUser.email), + }, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + if (userAlreadyAdded) { + throw new HttpException( + { + message: Messages.USER_ALREADY_ADDED_BUT_NOT_ACTIVE, + }, + HttpStatus.BAD_REQUEST, + ); + } + return { + group: savedGroup, + message: Messages.USER_ADDED_IN_GROUP(foundUser.email), + external_invite: false, + }; + } + } + + private isUserAlreadyInCompany(connectionWithCompanyAndUsers: ConnectionEntity, foundUser: UserEntity): boolean { + if ( + !connectionWithCompanyAndUsers.company || + !connectionWithCompanyAndUsers.company.users || + !connectionWithCompanyAndUsers.company.users.length || + !foundUser + ) { + return false; + } + const foundUserInCompany = connectionWithCompanyAndUsers.company.users.find((u) => u.id === foundUser.id); + return !!foundUserInCompany; + } +} diff --git a/backend/src/entities/group/use-cases/use-cases.interfaces.ts b/backend/src/entities/group/use-cases/use-cases.interfaces.ts index 6ebf6812..bc671cc2 100644 --- a/backend/src/entities/group/use-cases/use-cases.interfaces.ts +++ b/backend/src/entities/group/use-cases/use-cases.interfaces.ts @@ -1,7 +1,7 @@ import { InTransactionEnum } from '../../../enums/index.js'; import { FoundUserInGroupDs } from '../../user/application/data-structures/found-user-in-group.ds.js'; import { IToken } from '../../user/utils/generate-gwt-token.js'; -import { AddUserInGroupDs } from '../application/data-sctructures/add-user-in-group.ds.js'; +import { AddUserInGroupDs, AddUserInGroupWithSaaSDs } from '../application/data-sctructures/add-user-in-group.ds.js'; import { AddedUserInGroupDs } from '../application/data-sctructures/added-user-in-group.ds.js'; import { DeletedGroupResultDs } from '../application/data-sctructures/deleted-group-result.ds.js'; import { FoundUserGroupsDs } from '../application/data-sctructures/found-user-groups.ds.js'; @@ -12,6 +12,10 @@ export interface IAddUserInGroup { execute(inputData: AddUserInGroupDs, inTransaction: InTransactionEnum): Promise; } +export interface ISaaSAddUserInGroup { + execute(inputData: AddUserInGroupWithSaaSDs, inTransaction: InTransactionEnum): Promise; +} + export interface IVerifyAddUserInGroup { execute(inputData: VerifyAddUserInGroupDs, inTransaction: InTransactionEnum): Promise; } diff --git a/backend/src/entities/permission/use-cases/create-or-update-permissions.use.case.ts b/backend/src/entities/permission/use-cases/create-or-update-permissions.use.case.ts index ac51863f..e0dbbdd5 100644 --- a/backend/src/entities/permission/use-cases/create-or-update-permissions.use.case.ts +++ b/backend/src/entities/permission/use-cases/create-or-update-permissions.use.case.ts @@ -46,7 +46,8 @@ export class CreateOrUpdatePermissionsUseCase connection: { connectionId }, }, } = inputData; - const connectionWithThisGroup = await this._dbContext.connectionRepository.getConnectionByGroupId(groupId); + const connectionWithThisGroup = + await this._dbContext.connectionRepository.getConnectionByGroupIdWithCompanyAndUsersInCompany(groupId); if (connectionWithThisGroup.id !== connectionId) { throw new HttpException( { diff --git a/backend/src/entities/user/application/data-structures/found-user.ds.ts b/backend/src/entities/user/application/data-structures/found-user.ds.ts index 4d17c68b..f337dce1 100644 --- a/backend/src/entities/user/application/data-structures/found-user.ds.ts +++ b/backend/src/entities/user/application/data-structures/found-user.ds.ts @@ -10,4 +10,7 @@ export class FoundUserDs { intercom_hash?: string; name: string; is_2fa_enabled: boolean; + company?: { + id: string; + }; } diff --git a/backend/src/entities/user/application/data-structures/usual-register-user.ds.ts b/backend/src/entities/user/application/data-structures/usual-register-user.ds.ts index a4a3b3ed..076b64fa 100644 --- a/backend/src/entities/user/application/data-structures/usual-register-user.ds.ts +++ b/backend/src/entities/user/application/data-structures/usual-register-user.ds.ts @@ -8,3 +8,10 @@ export class UsualRegisterUserDs { export class SaasUsualUserRegisterDS extends UsualRegisterUserDs { companyId?: string; } + +export class RegisterInvitedUserDS { + email: string; + password: string; + name: string; + companyId: string; +} diff --git a/backend/src/entities/user/repository/user-custom-repository-extension.ts b/backend/src/entities/user/repository/user-custom-repository-extension.ts index c9bd394c..897482f0 100644 --- a/backend/src/entities/user/repository/user-custom-repository-extension.ts +++ b/backend/src/entities/user/repository/user-custom-repository-extension.ts @@ -24,7 +24,9 @@ export const userCustomRepositoryExtension: IUserRepository = { }, async findOneUserById(userId: string): Promise { - const userQb = this.createQueryBuilder('user').andWhere('user.id = :userId', { userId: userId }); + const userQb = this.createQueryBuilder('user') + .leftJoinAndSelect('user.company', 'company') + .andWhere('user.id = :userId', { userId: userId }); return await userQb.getOne(); }, @@ -47,11 +49,18 @@ export const userCustomRepositoryExtension: IUserRepository = { return await usersQb.getOne(); }, - async findUserByEmailWithEmailVerificationAndInvitation(email: string): Promise { + async findUserByEmailEndCompanyIdWithEmailVerificationAndInvitation( + email: string, + companyId?: string, + ): Promise { const usersQb = this.createQueryBuilder('user') .leftJoinAndSelect('user.email_verification', 'email_verification') .leftJoinAndSelect('user.user_invitation', 'user_invitation') + .leftJoinAndSelect('user.company', 'company') .where('user.email = :userEmail', { userEmail: email }); + if (companyId) { + usersQb.andWhere('company.id = :companyId', { companyId: companyId }); + } return await usersQb.getOne(); }, @@ -122,10 +131,10 @@ export const userCustomRepositoryExtension: IUserRepository = { return await userQb.getOne(); }, - async findOneUserByEmailAndCompanyId(email: string, companyId: string): Promise { + async findOneUserByEmailAndCompanyId(userEmail: string, companyId: string): Promise { const userQb = this.createQueryBuilder('user') .leftJoinAndSelect('user.company', 'company') - .where('user.email = :userEmail', { userEmail: email }); + .where('user.email = :userEmail', { userEmail: userEmail }); if (companyId) { userQb.andWhere('company.id = :companyId', { companyId: companyId }); } else { diff --git a/backend/src/entities/user/repository/user.repository.interface.ts b/backend/src/entities/user/repository/user.repository.interface.ts index 5fd59fe6..4510a4d1 100644 --- a/backend/src/entities/user/repository/user.repository.interface.ts +++ b/backend/src/entities/user/repository/user.repository.interface.ts @@ -21,7 +21,7 @@ export interface IUserRepository { findOneUserWithEmailVerification(userId: string): Promise; - findUserByEmailWithEmailVerificationAndInvitation(email: string): Promise; + findUserByEmailEndCompanyIdWithEmailVerificationAndInvitation(email: string, companyId?: string): Promise; deleteUserEntity(user: UserEntity): Promise; diff --git a/backend/src/entities/user/user-helper.service.ts b/backend/src/entities/user/user-helper.service.ts index 0da89167..b4a9475a 100644 --- a/backend/src/entities/user/user-helper.service.ts +++ b/backend/src/entities/user/user-helper.service.ts @@ -58,6 +58,7 @@ export class UserHelperService { intercom_hash: intercomHash, name: user.name, is_2fa_enabled: user.otpSecretKey !== null && user.isOTPEnabled, + company: user.company ? { id: user.company.id } : null, }; } } diff --git a/backend/src/exceptions/text/messages.ts b/backend/src/exceptions/text/messages.ts index 65605b7c..4d4b0bda 100644 --- a/backend/src/exceptions/text/messages.ts +++ b/backend/src/exceptions/text/messages.ts @@ -47,6 +47,8 @@ export const Messages = { CANT_UPDATE_TABLE_VIEW: `You can't update table view`, COGNITO_USERNAME_MISSING: 'Cognito username missing', COMPANY_ALREADY_EXISTS: 'Company already exists', + COMPANY_NOT_EXISTS_IN_CONNECTION: `Connection does not attached to company. Please contact our support team`, + COMPANY_NOT_FOUND: 'Company not found. Please contact our support team', CONNECTION_ID_MISSING: 'Connection id is missing', CONNECTION_NOT_CREATED: 'Connection was not successfully created.', CONNECTION_NOT_FOUND: 'Connection with specified parameters not found', @@ -180,6 +182,7 @@ export const Messages = { paramsNames.length > 1 ? 'are' : 'is' } missing`, ROW_PRIMARY_KEY_NOT_FOUND: 'Row with this primary key not found', + SAAS_COMPANY_NOT_REGISTERED_WITH_USER_INVITATION: `Failed to invite user in SaaS. Please contact our support team.`, SOMETHING_WENT_WRONG_ROW_ADD: 'Something went wrong on row insertion, check inserted parameters and try again', SSH_FORMAT_INCORRECT: 'Ssh value must be a boolean', SSH_HOST_MISSING: 'Ssh host is missing', @@ -252,6 +255,7 @@ export const Messages = { USER_ADDED_IN_GROUP: (email: string) => `User ${email} was added in group successfully`, USER_ALREADY_REGISTERED: (email: string) => `User with email ${email} is already registered`, USER_NOT_FOUND: 'User with specified parameters not found', + USER_NOT_INVITED_IN_COMPANY: (email: string) => `User ${email} is not invited in company. Invite user in company first`, USER_ID_MISSING: 'User id is missing', USER_TRY_CREATE_CONNECTION: (email: string) => `User "${email}" tried to create connection.`, USERNAME_MISSING: 'Username is missing', diff --git a/backend/src/microservice-client/client-microservice.module.ts b/backend/src/microservice-client/client-microservice.module.ts deleted file mode 100644 index 76a0f9fc..00000000 --- a/backend/src/microservice-client/client-microservice.module.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Global, Module } from '@nestjs/common'; -import { ClientMicroservice } from './client-microservice.service.js'; - -@Global() -@Module({ - imports: [], - providers: [ClientMicroservice], - exports: [ClientMicroservice], -}) -export class ClientMicroserviceModule {} diff --git a/backend/src/microservice-client/client-microservice.service.ts b/backend/src/microservice-client/client-microservice.service.ts deleted file mode 100644 index c244644f..00000000 --- a/backend/src/microservice-client/client-microservice.service.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { ClientProxy, ClientProxyFactory, Transport } from '@nestjs/microservices'; - -@Injectable() -export class ClientMicroservice { - private readonly client: ClientProxy; - constructor() { - this.client = ClientProxyFactory.create({ - transport: Transport.TCP, - options: { - host: process.env.MICROSERVICE_HOST || 'localhost', - port: 3001, - }, - }); - } - - public async sendMessageToMicroservice(pattern: any, data: string): Promise { - return this.client - .send(pattern, data) - .toPromise() - .catch((e) => { - console.log('🚀 ~ sendMessageToMicroservice error', e); - }); - } - - public async closeClient(): Promise { - await this.client.close(); - } - - public async connectClient(): Promise { - await this.client.connect(); - } -} diff --git a/backend/src/microservices/gateways/saas-gateway.ts/base-saas-gateway.service.ts b/backend/src/microservices/gateways/saas-gateway.ts/base-saas-gateway.service.ts new file mode 100644 index 00000000..2610d4a5 --- /dev/null +++ b/backend/src/microservices/gateways/saas-gateway.ts/base-saas-gateway.service.ts @@ -0,0 +1,49 @@ +import { Injectable } from '@nestjs/common'; +import Sentry from '@sentry/node'; +import { generateSaaSJwt } from './utils/generate-saas-jwt.js'; + +export type SaaSRequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE'; +export type SaaSResponse = { + status: number; + body: Record; +}; + +@Injectable() +export class BaseSaasGatewayService { + private readonly baseSaaSUrl = process.env.SAAS_URL || 'http://rocketadmin-private-microservice:3001'; + + async sendRequestToSaaS(patch: string, method: SaaSRequestMethod, body: Record): Promise { + try { + const bodyValue = body && method !== 'GET' ? JSON.stringify(body) : undefined; + + const jwtToken = generateSaaSJwt(); + const res = await fetch(`${this.baseSaaSUrl}${patch}`, { + method: method, + body: bodyValue, + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${jwtToken}`, + }, + }); + + return { + status: res.status, + body: await this.bodyToJSON(res), + }; + } catch (e) { + Sentry.captureException(e); + throw e; + } + } + + private async bodyToJSON(res: Response): Promise> { + if (!res.body) { + return {}; + } + try { + return await res.json(); + } catch (error) { + return {}; + } + } +} diff --git a/backend/src/microservices/gateways/saas-gateway.ts/data-structures/registered-company-when-user-invite-group.ds.ts b/backend/src/microservices/gateways/saas-gateway.ts/data-structures/registered-company-when-user-invite-group.ds.ts new file mode 100644 index 00000000..74e2e8d3 --- /dev/null +++ b/backend/src/microservices/gateways/saas-gateway.ts/data-structures/registered-company-when-user-invite-group.ds.ts @@ -0,0 +1,4 @@ +export class RegisteredCompanyUserInviteGroupDS { + companyId: string; + userId: string; +} \ No newline at end of file diff --git a/backend/src/microservices/gateways/saas-gateway.ts/saas-company-gateway.service.ts b/backend/src/microservices/gateways/saas-gateway.ts/saas-company-gateway.service.ts new file mode 100644 index 00000000..1b9dc934 --- /dev/null +++ b/backend/src/microservices/gateways/saas-gateway.ts/saas-company-gateway.service.ts @@ -0,0 +1,71 @@ +import { Injectable } from '@nestjs/common'; +import { BaseSaasGatewayService } from './base-saas-gateway.service.js'; +import { RegisteredCompanyUserInviteGroupDS } from './data-structures/registered-company-when-user-invite-group.ds.js'; +import { isObjectEmpty } from '../../../helpers/is-object-empty.js'; + +@Injectable() +export class SaasCompanyGatewayService extends BaseSaasGatewayService { + constructor() { + super(); + } + + public async registerCompanyWhenUserInviteInGroup( + userId: string, + userEmail: string, + gitHubId: number, + ): Promise { + const registrationResult = await this.sendRequestToSaaS(`/webhook/company/register`, 'POST', { + userId, + userEmail, + gitHubId, + }); + + if (isObjectEmpty(registrationResult.body)) { + return null; + } + return { + companyId: registrationResult.body.id as string, + userId: registrationResult.body.users[0].id as string, + }; + } + + public async canInviteMoreUsers(companyId: string): Promise { + const canInviteMoreUsersResult = await this.sendRequestToSaaS( + `/webhook/company/invite/check/${companyId}`, + 'GET', + null, + ); + return canInviteMoreUsersResult.body.success as boolean; + } + + public async inviteNewUserInCompany( + companyId: string, + newUserEmail: string, + newUserId: string, + userRole: string, + inviterId: string, + ): Promise { + const registrationResult = await this.sendRequestToSaaS(`/webhook/company/invite`, 'POST', { + userId: newUserId, + userEmail: newUserEmail, + companyId: companyId, + userRole: userRole, + inviterId: inviterId, + }); + if (isObjectEmpty(registrationResult.body)) { + return null; + } + return { + companyId: registrationResult.body.companyId as string, + userId: registrationResult.body.userId as string, + }; + } + + public async registerEmptyCompany( + userId: string, + userEmail: string, + gitHubId: number, + ): Promise { + return await this.registerCompanyWhenUserInviteInGroup(userId, userEmail, gitHubId); + } +} diff --git a/backend/src/microservices/gateways/saas-gateway.ts/saas-gateway.module.ts b/backend/src/microservices/gateways/saas-gateway.ts/saas-gateway.module.ts new file mode 100644 index 00000000..d67b2a2c --- /dev/null +++ b/backend/src/microservices/gateways/saas-gateway.ts/saas-gateway.module.ts @@ -0,0 +1,12 @@ +import { Global, Module } from '@nestjs/common'; +import { BaseSaasGatewayService } from './base-saas-gateway.service.js'; +import { SaasCompanyGatewayService } from './saas-company-gateway.service.js'; + +@Global() +@Module({ + imports: [], + controllers: [], + providers: [BaseSaasGatewayService, SaasCompanyGatewayService], + exports: [BaseSaasGatewayService, SaasCompanyGatewayService], +}) +export class SaaSGatewayModule {} diff --git a/backend/src/microservices/gateways/saas-gateway.ts/utils/generate-request-id.ts b/backend/src/microservices/gateways/saas-gateway.ts/utils/generate-request-id.ts new file mode 100644 index 00000000..2d89b719 --- /dev/null +++ b/backend/src/microservices/gateways/saas-gateway.ts/utils/generate-request-id.ts @@ -0,0 +1,4 @@ +import { nanoid } from 'nanoid'; +export function generateRequestId(): string { + return nanoid(10); +} diff --git a/backend/src/microservices/gateways/saas-gateway.ts/utils/generate-saas-jwt.ts b/backend/src/microservices/gateways/saas-gateway.ts/utils/generate-saas-jwt.ts new file mode 100644 index 00000000..e4cda7fc --- /dev/null +++ b/backend/src/microservices/gateways/saas-gateway.ts/utils/generate-saas-jwt.ts @@ -0,0 +1,17 @@ +import jwt from 'jsonwebtoken'; +import { generateRequestId } from './generate-request-id.js'; +import { getRequiredEnvVariable } from '../../../../helpers/app/get-requeired-env-variable.js'; + +export function generateSaaSJwt(): string { + const today = new Date(); + const exp = new Date(today); + exp.setDate(today.getDate() + 60); + const secret = getRequiredEnvVariable('MICROSERVICE_JWT_SECRET'); + const requestId = generateRequestId(); + return jwt.sign( + { + request_id: requestId, + }, + secret, + ); +} diff --git a/backend/src/microservices/saas-microservice/saas.controller.ts b/backend/src/microservices/saas-microservice/saas.controller.ts index fa63d0d0..a636c47f 100644 --- a/backend/src/microservices/saas-microservice/saas.controller.ts +++ b/backend/src/microservices/saas-microservice/saas.controller.ts @@ -9,6 +9,7 @@ import { IGetUserInfoByEmail, ILoginUserWithGitHub, ILoginUserWithGoogle, + ISaaSRegisterInvitedUser, ISaasRegisterUser, IUpdateUserStripeCustomerId, } from './use-cases/saas-use-cases.interface.js'; @@ -41,6 +42,8 @@ export class SaasController { private readonly addCompanyIdToUserUseCase: IAddOrRemoveCompanyIdToUser, @Inject(UseCaseType.SAAS_REMOVE_COMPANY_ID_FROM_USER) private readonly removeCompanyIdFromUserUserUseCase: IAddOrRemoveCompanyIdToUser, + @Inject(UseCaseType.SAAS_REGISTER_INVITED_USER) + private readonly registerInvitedUserUseCase: ISaaSRegisterInvitedUser, ) {} @Post('/company/registered') @@ -86,6 +89,16 @@ export class SaasController { return await this.usualRegisterUserUseCase.execute({ email, password, gclidValue, name, companyId }); } + @Post('/user/register/invite') + async registerInvitedUser( + @Body('email') email: string, + @Body('password') password: string, + @Body('name') name: string, + @Body('companyId') companyId: string, + ): Promise { + return await this.registerInvitedUserUseCase.execute({ email, password, name, companyId }); + } + @Post('user/google/login') async loginUserWithGoogle( @Body('email') email: string, diff --git a/backend/src/microservices/saas-microservice/saas.module.ts b/backend/src/microservices/saas-microservice/saas.module.ts index 1094b183..21ab1f46 100644 --- a/backend/src/microservices/saas-microservice/saas.module.ts +++ b/backend/src/microservices/saas-microservice/saas.module.ts @@ -10,9 +10,10 @@ import { SaasUsualRegisterUseCase } from './use-cases/saas-usual-register-user.u import { LoginWithGoogleUseCase } from './use-cases/login-with-google.use.case.js'; import { GetUserInfoByGitHubIdUseCase } from './use-cases/get-user-info-by-githubid.use.case.js'; import { LoginUserWithGithubUseCase } from './use-cases/login-with-github.use.case.js'; -import { UpdateUserStripeCustomerIdUseCase } from './use-cases/update-user-stripe-customer-id.use.case.js'; +import { UpdateUserStripeCustomerIdUseCase } from './use-cases/UpdateUserStripeCustomerIdUseCase.js'; import { AddCompanyIdToUserUseCase } from './use-cases/add-company-id-to-user-use.case.js'; import { RemoveCompanyIdFromUserUseCase } from './use-cases/remove-company-id-from-user.use.case.js'; +import { SaasRegisterInvitedUserUseCase } from './use-cases/register-invited-user-use.case.js'; @Module({ imports: [], @@ -60,7 +61,11 @@ import { RemoveCompanyIdFromUserUseCase } from './use-cases/remove-company-id-fr { provide: UseCaseType.SAAS_REMOVE_COMPANY_ID_FROM_USER, useClass: RemoveCompanyIdFromUserUseCase, - } + }, + { + provide: UseCaseType.SAAS_REGISTER_INVITED_USER, + useClass: SaasRegisterInvitedUserUseCase, + }, ], controllers: [SaasController], exports: [], @@ -79,6 +84,7 @@ export class SaasModule { { path: 'saas/user/github/login', method: RequestMethod.POST }, { path: 'saas/user/:userId/stripe', method: RequestMethod.PUT }, { path: 'saas/user/:userId/company/:companyId', method: RequestMethod.PUT }, + { path: 'sass/user/register/invite', method: RequestMethod.POST }, ); } } diff --git a/backend/src/microservices/saas-microservice/use-cases/UpdateUserStripeCustomerIdUseCase.ts b/backend/src/microservices/saas-microservice/use-cases/UpdateUserStripeCustomerIdUseCase.ts new file mode 100644 index 00000000..913298ab --- /dev/null +++ b/backend/src/microservices/saas-microservice/use-cases/UpdateUserStripeCustomerIdUseCase.ts @@ -0,0 +1,35 @@ +import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; +import AbstractUseCase from '../../../common/abstract-use.case.js'; +import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js'; +import { BaseType } from '../../../common/data-injection.tokens.js'; +import { UpdateUserStripeCustomerDS } from '../data-structures/update-user-stripe-customer-id.ds.js'; +import { IUpdateUserStripeCustomerId } from './saas-use-cases.interface.js'; +import { Messages } from '../../../exceptions/text/messages.js'; + + +@Injectable() +export class UpdateUserStripeCustomerIdUseCase + extends AbstractUseCase + implements IUpdateUserStripeCustomerId { + constructor( + @Inject(BaseType.GLOBAL_DB_CONTEXT) + protected _dbContext: IGlobalDatabaseContext + ) { + super(); + } + + protected async implementation(inputData: UpdateUserStripeCustomerDS): Promise { + const foundUser = await this._dbContext.userRepository.findOneUserById(inputData.userId); + if (!foundUser) { + throw new HttpException( + { + message: Messages.USER_NOT_FOUND, + }, + HttpStatus.BAD_REQUEST + ); + } + foundUser.stripeId = inputData.stripeCustomerId; + await this._dbContext.userRepository.saveUserEntity(foundUser); + return; + } +} diff --git a/backend/src/microservices/saas-microservice/use-cases/add-company-id-to-user-use.case.ts b/backend/src/microservices/saas-microservice/use-cases/add-company-id-to-user-use.case.ts index 4bc98a52..efa1ce4d 100644 --- a/backend/src/microservices/saas-microservice/use-cases/add-company-id-to-user-use.case.ts +++ b/backend/src/microservices/saas-microservice/use-cases/add-company-id-to-user-use.case.ts @@ -19,8 +19,11 @@ export class AddCompanyIdToUserUseCase protected async implementation(inputData: AddRemoveCompanyIdToUserDS): Promise { const { userId, companyId } = inputData; const foundUser = await this._dbContext.userRepository.findOneUserById(userId); - const foundCompany = await this._dbContext.companyInfoRepository.findOneBy({ id: companyId }); - if (!foundUser || !foundCompany) { + const foundCompanyWithUsers = await this._dbContext.companyInfoRepository.findOne({ + where: { id: companyId }, + relations: ['users'], + }); + if (!foundUser || !foundCompanyWithUsers) { throw new HttpException( { message: 'Required entity not found', @@ -28,8 +31,10 @@ export class AddCompanyIdToUserUseCase HttpStatus.INTERNAL_SERVER_ERROR, ); } - - foundUser.company = foundCompany; - await this._dbContext.userRepository.saveUserEntity(foundUser); + const userAlreadyInCompany = !!foundCompanyWithUsers.users.find((user) => user.id === foundUser.id); + if (!userAlreadyInCompany) { + foundCompanyWithUsers.users.push(foundUser); + await this._dbContext.companyInfoRepository.save(foundCompanyWithUsers); + } } } diff --git a/backend/src/microservices/saas-microservice/use-cases/login-with-github.use.case.ts b/backend/src/microservices/saas-microservice/use-cases/login-with-github.use.case.ts index f4ea8b1e..29d23b7a 100644 --- a/backend/src/microservices/saas-microservice/use-cases/login-with-github.use.case.ts +++ b/backend/src/microservices/saas-microservice/use-cases/login-with-github.use.case.ts @@ -1,4 +1,4 @@ -import { HttpException, HttpStatus, Inject } from '@nestjs/common'; +import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; import AbstractUseCase from '../../../common/abstract-use.case.js'; import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js'; import { BaseType } from '../../../common/data-injection.tokens.js'; @@ -18,6 +18,7 @@ import { buildTestTableSettings } from '../../../entities/user/utils/build-test- import { Constants } from '../../../helpers/constants/constants.js'; import { Messages } from '../../../exceptions/text/messages.js'; +@Injectable() export class LoginUserWithGithubUseCase extends AbstractUseCase implements ILoginUserWithGitHub diff --git a/backend/src/microservices/saas-microservice/use-cases/register-invited-user-use.case.ts b/backend/src/microservices/saas-microservice/use-cases/register-invited-user-use.case.ts new file mode 100644 index 00000000..c436d26e --- /dev/null +++ b/backend/src/microservices/saas-microservice/use-cases/register-invited-user-use.case.ts @@ -0,0 +1,78 @@ +import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; +import AbstractUseCase from '../../../common/abstract-use.case.js'; +import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js'; +import { BaseType } from '../../../common/data-injection.tokens.js'; +import { FoundUserDs } from '../../../entities/user/application/data-structures/found-user.ds.js'; +import { RegisterInvitedUserDS } from '../../../entities/user/application/data-structures/usual-register-user.ds.js'; +import { sendEmailConfirmation } from '../../../entities/email/send-email.js'; +import { RegisterUserDs } from '../../../entities/user/application/data-structures/register-user-ds.js'; +import { Messages } from '../../../exceptions/text/messages.js'; +import { ValidationHelper } from '../../../helpers/validators/validation-helper.js'; +import { ISaaSRegisterInvitedUser } from './saas-use-cases.interface.js'; + +@Injectable() +export class SaasRegisterInvitedUserUseCase + extends AbstractUseCase + implements ISaaSRegisterInvitedUser +{ + constructor( + @Inject(BaseType.GLOBAL_DB_CONTEXT) + protected _dbContext: IGlobalDatabaseContext, + ) { + super(); + } + + protected async implementation(userData: RegisterInvitedUserDS): Promise { + const { email, password, name, companyId } = userData; + ValidationHelper.isPasswordStrongOrThrowError(password); + const foundUser = await this._dbContext.userRepository.findOneUserByEmailAndCompanyId(email, companyId); + const foundCompany = await this._dbContext.companyInfoRepository.findCompanyInfoWithUsersById(companyId); + + if (foundUser) { + throw new HttpException( + { + message: Messages.USER_ALREADY_REGISTERED(email), + }, + HttpStatus.BAD_REQUEST, + ); + } + + if (!foundCompany) { + throw new HttpException( + { + message: Messages.COMPANY_NOT_FOUND, + }, + HttpStatus.BAD_REQUEST, + ); + } + + const registerUserData: RegisterUserDs = { + email: email, + password: password, + isActive: false, + gclidValue: null, + name: name, + }; + const savedUser = await this._dbContext.userRepository.saveRegisteringUser(registerUserData); + + savedUser.company = foundCompany; + await this._dbContext.userRepository.saveUserEntity(savedUser); + + const createdEmailVerification = await this._dbContext.emailVerificationRepository.createOrUpdateEmailVerification( + savedUser, + ); + + await sendEmailConfirmation(savedUser.email, createdEmailVerification.verification_string); + return { + id: savedUser.id, + createdAt: savedUser.createdAt, + isActive: savedUser.isActive, + email: savedUser.email, + portal_link: null, + subscriptionLevel: null, + intercom_hash: null, + name: savedUser.name, + is_2fa_enabled: false, + }; + } +} diff --git a/backend/src/microservices/saas-microservice/use-cases/remove-company-id-from-user.use.case.ts b/backend/src/microservices/saas-microservice/use-cases/remove-company-id-from-user.use.case.ts index 2dcd6a92..692325ff 100644 --- a/backend/src/microservices/saas-microservice/use-cases/remove-company-id-from-user.use.case.ts +++ b/backend/src/microservices/saas-microservice/use-cases/remove-company-id-from-user.use.case.ts @@ -1,4 +1,4 @@ -import { HttpException, HttpStatus, Inject } from '@nestjs/common'; +import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; import AbstractUseCase from '../../../common/abstract-use.case.js'; import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js'; import { BaseType } from '../../../common/data-injection.tokens.js'; @@ -6,6 +6,7 @@ import { AddRemoveCompanyIdToUserDS } from '../data-structures/add-company-id-to import { IAddOrRemoveCompanyIdToUser } from './saas-use-cases.interface.js'; import { Messages } from '../../../exceptions/text/messages.js'; +@Injectable() export class RemoveCompanyIdFromUserUseCase extends AbstractUseCase implements IAddOrRemoveCompanyIdToUser diff --git a/backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts b/backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts index 11e03827..d1384f8b 100644 --- a/backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts +++ b/backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts @@ -1,5 +1,8 @@ import { FoundUserDs } from '../../../entities/user/application/data-structures/found-user.ds.js'; -import { SaasUsualUserRegisterDS } from '../../../entities/user/application/data-structures/usual-register-user.ds.js'; +import { + RegisterInvitedUserDS, + SaasUsualUserRegisterDS, +} from '../../../entities/user/application/data-structures/usual-register-user.ds.js'; import { UserEntity } from '../../../entities/user/user.entity.js'; import { AddRemoveCompanyIdToUserDS } from '../data-structures/add-company-id-to-user.ds.js'; import { GetUserInfoByEmailDS } from '../data-structures/get-user-info.ds.js'; @@ -25,6 +28,10 @@ export interface ISaasRegisterUser { execute(userData: SaasUsualUserRegisterDS): Promise; } +export interface ISaaSRegisterInvitedUser { + execute(userData: RegisterInvitedUserDS): Promise; +} + export interface ILoginUserWithGoogle { execute(inputData: SaasRegisterUserWithGoogleDS): Promise; } diff --git a/backend/src/microservices/saas-microservice/use-cases/saas-usual-register-user.use.case.ts b/backend/src/microservices/saas-microservice/use-cases/saas-usual-register-user.use.case.ts index 3772dc79..c15132e4 100644 --- a/backend/src/microservices/saas-microservice/use-cases/saas-usual-register-user.use.case.ts +++ b/backend/src/microservices/saas-microservice/use-cases/saas-usual-register-user.use.case.ts @@ -19,6 +19,8 @@ import { Messages } from '../../../exceptions/text/messages.js'; import { Constants } from '../../../helpers/constants/constants.js'; import { ValidationHelper } from '../../../helpers/validators/validation-helper.js'; import { ISaasRegisterUser } from './saas-use-cases.interface.js'; +import { CompanyInfoEntity } from '../../../entities/company-info/company-info.entity.js'; +import { UserEntity } from '../../../entities/user/user.entity.js'; export class SaasUsualRegisterUseCase extends AbstractUseCase @@ -35,6 +37,8 @@ export class SaasUsualRegisterUseCase const { email, password, gclidValue, name, companyId } = userData; ValidationHelper.isPasswordStrongOrThrowError(password); const foundUser = await this._dbContext.userRepository.findOneUserByEmailAndCompanyId(email, companyId); + const foundCompany = await this._dbContext.companyInfoRepository.findCompanyInfoWithUsersById(companyId); + if (foundUser) { throw new HttpException( { @@ -51,6 +55,7 @@ export class SaasUsualRegisterUseCase name: name, }; const savedUser = await this._dbContext.userRepository.saveRegisteringUser(registerUserData); + const testConnections = Constants.getTestConnectionsArr(); const testConnectionsEntities = buildConnectionEntitiesFromTestDtos(testConnections); const createdTestConnections = await Promise.all( @@ -84,6 +89,14 @@ export class SaasUsualRegisterUseCase savedUser, ); await sendEmailConfirmation(savedUser.email, createdEmailVerification.verification_string); + + if (foundCompany) { + foundCompany.users.push(savedUser); + await this._dbContext.companyInfoRepository.save(foundCompany); + } else { + await this.registerEmptyCompany(savedUser, createdTestConnections, companyId); + } + return { id: savedUser.id, createdAt: savedUser.createdAt, @@ -96,4 +109,18 @@ export class SaasUsualRegisterUseCase is_2fa_enabled: false, }; } + + private async registerEmptyCompany( + savedUser: UserEntity, + testConnections: Array, + companyId: string, + ): Promise { + const newCompanyInfo = new CompanyInfoEntity(); + newCompanyInfo.id = companyId; + newCompanyInfo.connections = [...testConnections]; + const savedCompanyInfo = await this._dbContext.companyInfoRepository.save(newCompanyInfo); + savedUser.company = savedCompanyInfo; + await this._dbContext.userRepository.saveUserEntity(savedUser); + return savedCompanyInfo; + } } diff --git a/backend/src/microservices/saas-microservice/use-cases/update-user-stripe-customer-id.use.case.ts b/backend/src/microservices/saas-microservice/use-cases/update-user-stripe-customer-id.use.case.ts index 1ed0d7f1..8aa68bdd 100644 --- a/backend/src/microservices/saas-microservice/use-cases/update-user-stripe-customer-id.use.case.ts +++ b/backend/src/microservices/saas-microservice/use-cases/update-user-stripe-customer-id.use.case.ts @@ -1,4 +1,4 @@ -import { HttpException, HttpStatus, Inject } from '@nestjs/common'; +import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; import AbstractUseCase from '../../../common/abstract-use.case.js'; import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js'; import { BaseType } from '../../../common/data-injection.tokens.js'; @@ -6,6 +6,7 @@ import { UpdateUserStripeCustomerDS } from '../data-structures/update-user-strip import { IUpdateUserStripeCustomerId } from './saas-use-cases.interface.js'; import { Messages } from '../../../exceptions/text/messages.js'; +@Injectable() export class UpdateUserStripeCustomerIdUseCase extends AbstractUseCase implements IUpdateUserStripeCustomerId diff --git a/backend/test/ava-tests/connection-e2e.test.ts b/backend/test/ava-tests/connection-e2e.test.ts index 0dcd8c41..3e53afcb 100644 --- a/backend/test/ava-tests/connection-e2e.test.ts +++ b/backend/test/ava-tests/connection-e2e.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { faker } from '@faker-js/faker'; import { INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; @@ -7,11 +8,11 @@ import request from 'supertest'; import { ApplicationModule } from '../../src/app.module.js'; import { AccessLevelEnum } from '../../src/enums/index.js'; import { Messages } from '../../src/exceptions/text/messages.js'; -import { Constants } from '../../src/helpers/constants/constants.js'; import { DatabaseModule } from '../../src/shared/database/database.module.js'; import { DatabaseService } from '../../src/shared/database/database.service.js'; import { MockFactory } from '../mock.factory.js'; import { TestUtils } from '../utils/test.utils.js'; +import { inviteUserInCompanyAndAcceptInvitation, registerUserAndReturnUserInfo } from '../utils/register-user-and-return-user-info.js'; const mockFactory = new MockFactory(); let app: INestApplication; @@ -52,31 +53,11 @@ function getTestData() { }; } -async function registerUserAndReturnUserInfo(): Promise<{ - token: string; - email: string; - password: string; -}> { - const adminUserRegisterInfo: RegisterUserData = { - email: faker.internet.email(), - password: 'ahalai-mahalai', - }; - - const registerAdminUserResponse = await request(app.getHttpServer()) - .post('/user/register/') - .send(adminUserRegisterInfo) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - - const token = `${Constants.JWT_COOKIE_KEY_NAME}=${TestUtils.getJwtTokenFromResponse(registerAdminUserResponse)}`; - return { token: token, ...adminUserRegisterInfo }; -} - currentTest = '> GET /connections >'; test(`${currentTest} should return all connections for this user`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const findAllConnectionsResponse = await request(app.getHttpServer()) .get('/connections') .set('Cookie', token) @@ -140,7 +121,7 @@ currentTest = '> GET connection/users/:slug >'; test(`${currentTest} should return all connection users`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') .send(newConnection) @@ -174,7 +155,7 @@ test(`${currentTest} should return all connection users`, async (t) => { test(`${currentTest} should return all connection users from different groups`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app) const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') .send(newConnection) @@ -196,8 +177,10 @@ test(`${currentTest} should return all connection users from different groups`, t.is(createGroupResponse.status, 201); const createGroupRO = JSON.parse(createGroupResponse.text); + const secondUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation(token, undefined, app); + const requestBody = { - email: faker.internet.email(), + email: secondUserRegisterInfo.email, groupId: createGroupRO.id, }; const addUserInGroupResponse = await request(app.getHttpServer()) @@ -237,7 +220,7 @@ test(`${currentTest} should return all connection users from different groups`, test(`${currentTest} should throw an exception, when connection id is incorrect`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') .send(newConnection) @@ -257,8 +240,10 @@ test(`${currentTest} should throw an exception, when connection id is incorrect` t.is(createGroupResponse.status, 201); const createGroupRO = JSON.parse(createGroupResponse.text); + const secondUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation(token, undefined, app); + const requestBody = { - email: faker.internet.email(), + email: secondUserRegisterInfo.email, groupId: createGroupRO.id, }; @@ -270,7 +255,7 @@ test(`${currentTest} should throw an exception, when connection id is incorrect` .set('Accept', 'application/json'); t.is(addUserInGroupResponse.status, 200); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const findAllUsersResponse = await request(app.getHttpServer()) .get(`/connection/users/${fakeConnectionId}`) .set('Content-Type', 'application/json') @@ -290,7 +275,7 @@ currentTest = 'GET /connection/one/:slug'; test(`${currentTest} should return a found connection`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -333,7 +318,7 @@ test(`${currentTest} should return a found connection`, async (t) => { test(`${currentTest} should throw an exception "id is missing" when connection id not passed in the request`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -364,7 +349,7 @@ currentTest = 'POST /connection'; test(`${currentTest} should return created connection`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const response = await request(app.getHttpServer()) .post('/connection') @@ -410,7 +395,7 @@ test(`${currentTest} should return created connection`, async (t) => { test(`${currentTest} should throw error when create connection without type`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); delete newConnection.type; const response = await request(app.getHttpServer()) @@ -433,7 +418,7 @@ test(`${currentTest} should throw error when create connection without type`, as test(`${currentTest} should throw error when create connection without host`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); delete newConnection.host; const response = await request(app.getHttpServer()) .post('/connection') @@ -455,7 +440,7 @@ test(`${currentTest} should throw error when create connection without host`, as test(`${currentTest} should throw error when create connection without port`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); delete newConnection.port; const response = await request(app.getHttpServer()) .post('/connection') @@ -477,7 +462,7 @@ test(`${currentTest} should throw error when create connection without port`, as test(`${currentTest} should throw error when create connection wit port value more than 65535`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); newConnection.port = 65536; const response = await request(app.getHttpServer()) .post('/connection') @@ -499,7 +484,7 @@ test(`${currentTest} should throw error when create connection wit port value mo test(`${currentTest} should throw error when create connection wit port value less than 0`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); newConnection.port = -1; const response = await request(app.getHttpServer()) @@ -521,7 +506,7 @@ test(`${currentTest} should throw error when create connection wit port value le test(`${currentTest} should throw error when create connection without username`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); delete newConnection.username; const response = await request(app.getHttpServer()) .post('/connection') @@ -543,7 +528,7 @@ test(`${currentTest} should throw error when create connection without username` test(`${currentTest} should throw error when create connection without database`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); delete newConnection.database; const response = await request(app.getHttpServer()) .post('/connection') @@ -565,7 +550,7 @@ test(`${currentTest} should throw error when create connection without database` test(`${currentTest} should throw error when create connection without password`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); delete newConnection.password; const response = await request(app.getHttpServer()) .post('/connection') @@ -586,7 +571,7 @@ test(`${currentTest} should throw error when create connection without password` test(`${currentTest} should throw error with complex message when create connection without database, type, port`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); delete newConnection.database; delete newConnection.type; delete newConnection.port; @@ -615,7 +600,7 @@ currentTest = 'PUT /connection'; test(`${currentTest} should return updated connection`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') .send(newConnection) @@ -656,7 +641,7 @@ test(`${currentTest} should return updated connection`, async (t) => { test(`${currentTest} 'should throw error when update connection without type'`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') .send(newConnection) @@ -687,7 +672,7 @@ test(`${currentTest} 'should throw error when update connection without type'`, test(`${currentTest} should throw error when update connection without host`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') .send(newConnection) @@ -717,7 +702,7 @@ test(`${currentTest} should throw error when update connection without host`, as test(`${currentTest} should throw error when update connection without port`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -749,7 +734,7 @@ test(`${currentTest} should throw error when update connection without port`, as test(`${currentTest} should throw error when update connection wit port value more than 65535`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') .send(newConnection) @@ -780,7 +765,7 @@ test(`${currentTest} should throw error when update connection wit port value mo test(`${currentTest} should throw error when update connection wit port value less than 0`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -812,7 +797,7 @@ test(`${currentTest} should throw error when update connection wit port value le test(`${currentTest} should throw error when update connection without username`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') .send(newConnection) @@ -843,7 +828,7 @@ test(`${currentTest} should throw error when update connection without username` test(`${currentTest} should throw error when update connection without database`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -875,7 +860,7 @@ test(`${currentTest} should throw error when update connection without database` test(`${currentTest} should throw error with complex message when update connection without database, type, port`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -913,7 +898,7 @@ currentTest = 'DELETE /connection/:slug'; test(`${currentTest} should return delete result`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResult = await request(app.getHttpServer()) .post('/connection') .send(newConnection) @@ -967,7 +952,7 @@ test(`${currentTest} should return delete result`, async (t) => { test(`${currentTest} should throw an exception when connection not found`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResult = await request(app.getHttpServer()) .post('/connection') @@ -977,7 +962,7 @@ test(`${currentTest} should throw an exception when connection not found`, async .set('Accept', 'application/json'); const createConnectionRO = JSON.parse(createConnectionResult.text); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const response = await request(app.getHttpServer()) .put(`/connection/delete/${createConnectionRO.id}`) @@ -998,7 +983,7 @@ test(`${currentTest} should throw an exception when connection not found`, async test(`${currentTest} should throw an exception when connection id not passed in the request`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResult = await request(app.getHttpServer()) .post('/connection') @@ -1028,7 +1013,7 @@ currentTest = 'POST /connection/group/:slug'; test(`${currentTest} should return a created group`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token, email } = await registerUserAndReturnUserInfo(); + const { token, email } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -1066,7 +1051,7 @@ test(`${currentTest} should return a created group`, async (t) => { test(`${currentTest} throw an exception when connectionId not passed in request`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -1095,7 +1080,7 @@ test(`${currentTest} throw an exception when connectionId not passed in request` test(`${currentTest} throw an exception when group title not passed in request`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -1127,7 +1112,7 @@ test(`${currentTest} throw an exception when group title not passed in request`, test(`${currentTest} throw an exception when connectionId is incorrect`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -1137,7 +1122,7 @@ test(`${currentTest} throw an exception when connectionId is incorrect`, async ( .set('Accept', 'application/json'); const createConnectionRO = JSON.parse(createConnectionResponse.text); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const createGroupResponse = await request(app.getHttpServer()) .post(`/connection/group/${createConnectionRO.id}`) .send(newGroup1) @@ -1159,7 +1144,7 @@ test(`${currentTest} throw an exception when connectionId is incorrect`, async ( test(`${currentTest} throw an exception when group name is not unique`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -1192,7 +1177,7 @@ currentTest = 'PUT /connection/group/delete/:slug'; test(`${currentTest} should return connection without deleted group result`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResult = await request(app.getHttpServer()) .post('/connection') @@ -1267,7 +1252,7 @@ test(`${currentTest} should return connection without deleted group result`, asy test(`${currentTest}`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); t.pass(); } catch (e) { throw e; @@ -1277,7 +1262,7 @@ test(`${currentTest}`, async (t) => { test(`${currentTest} should throw an exception when connection id is not passed in the request`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResult = await request(app.getHttpServer()) .post('/connection') .send(newConnection) @@ -1321,7 +1306,7 @@ test(`${currentTest} should throw an exception when connection id is not passed test(`${currentTest} should throw an exception when group id is not passed in the request`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResult = await request(app.getHttpServer()) .post('/connection') @@ -1368,7 +1353,7 @@ test(`${currentTest} should throw an exception when group id is not passed in th test(`${currentTest} should throw an exception when group id is incorrect`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResult = await request(app.getHttpServer()) .post('/connection') @@ -1395,7 +1380,7 @@ test(`${currentTest} should throw an exception when group id is incorrect`, asyn t.is(result.title, newGroup1.title); const createGroupRO = JSON.parse(createGroupResponse.text); - createGroupRO.id = faker.datatype.uuid(); + createGroupRO.id = faker.string.uuid(); const response = await request(app.getHttpServer()) .put(`/connection/group/delete/${createConnectionRO.id}`) .send({ groupId: createGroupRO.id }) @@ -1416,7 +1401,7 @@ test(`${currentTest} should throw an exception when group id is incorrect`, asyn test(`${currentTest} should throw an exception when connection id is incorrect`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResult = await request(app.getHttpServer()) .post('/connection') @@ -1443,7 +1428,7 @@ test(`${currentTest} should throw an exception when connection id is incorrect`, t.is(result.title, newGroup1.title); const createGroupRO = JSON.parse(createGroupResponse.text); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const response = await request(app.getHttpServer()) .put(`/connection/group/delete/${createConnectionRO.id}`) .send({ groupId: createGroupRO.id }) @@ -1464,7 +1449,7 @@ test(`${currentTest} should throw an exception when connection id is incorrect`, test(`${currentTest} should throw an exception when trying delete admin group`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResult = await request(app.getHttpServer()) .post('/connection') @@ -1496,7 +1481,7 @@ currentTest = 'PUT /connection/encryption/restore/:slug'; test(`${currentTest} should return restored connection`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const newPgConnection = mockFactory.generateConnectionToTestPostgresDBInDocker(); newPgConnection.masterEncryption = true; @@ -1546,7 +1531,7 @@ currentTest = 'GET /connection/groups/:slug'; test(`${currentTest} should groups in connection`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -1596,7 +1581,7 @@ test(`${currentTest} should groups in connection`, async (t) => { test(`${currentTest} should throw an exception when connection id not passed in the request`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -1634,7 +1619,7 @@ test(`${currentTest} should throw an exception when connection id not passed in test(`${currentTest} should throw an exception when connection id is invalid`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') .send(newConnection) @@ -1652,7 +1637,7 @@ test(`${currentTest} should throw an exception when connection id is invalid`, a .set('Accept', 'application/json'); t.is(createGroupResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const response = await request(app.getHttpServer()) .get(`/connection/groups/${createConnectionRO.id}`) .send(newConnection) @@ -1677,7 +1662,7 @@ currentTest = 'GET /connection/user/permissions'; // test(`${currentTest}`, async (t) => { // try { // const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); -// const { token } = await registerUserAndReturnUserInfo(); +// const { token } = await registerUserAndReturnUserInfo(app); // t.pass(); // } catch (e) { // throw e; diff --git a/backend/test/ava-tests/connection-properties-e2e.test.ts b/backend/test/ava-tests/connection-properties-e2e.test.ts index 0984d059..3e55c82d 100644 --- a/backend/test/ava-tests/connection-properties-e2e.test.ts +++ b/backend/test/ava-tests/connection-properties-e2e.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { faker } from '@faker-js/faker'; import { INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; @@ -5,13 +6,12 @@ import test from 'ava'; import cookieParser from 'cookie-parser'; import request from 'supertest'; import { ApplicationModule } from '../../src/app.module.js'; -import { Constants } from '../../src/helpers/constants/constants.js'; import { DatabaseModule } from '../../src/shared/database/database.module.js'; import { DatabaseService } from '../../src/shared/database/database.service.js'; import { MockFactory } from '../mock.factory.js'; -import { dropTestTables } from '../utils/drop-test-tables.js'; import { getTestKnex } from '../utils/get-test-knex.js'; import { TestUtils } from '../utils/test.utils.js'; +import { registerUserAndReturnUserInfo } from '../utils/register-user-and-return-user-info.js'; const mockFactory = new MockFactory(); let app: INestApplication; @@ -85,29 +85,6 @@ type RegisterUserData = { password: string; }; -async function registerUserAndReturnUserInfo(): Promise<{ - token: string; - email: string; - password: string; -}> { - const adminUserRegisterInfo: RegisterUserData = { - email: faker.internet.email(), - password: 'ahalai-mahalai', - }; - - const registerAdminUserResponse = await request(app.getHttpServer()) - .post('/user/register/') - .send(adminUserRegisterInfo) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - - if (registerAdminUserResponse.status > 300) { - console.log('registerAdminUserResponse.text -> ', registerAdminUserResponse.text); - } - const token = `${Constants.JWT_COOKIE_KEY_NAME}=${TestUtils.getJwtTokenFromResponse(registerAdminUserResponse)}`; - return { token: token, ...adminUserRegisterInfo }; -} - function getTestData() { const newConnection = mockFactory.generateConnectionToTestPostgresDBInDocker(); const newConnection2 = mockFactory.generateCreateConnectionDto2(); @@ -127,7 +104,7 @@ currentTest = 'POST /connection/properties/:slug'; test(`${currentTest} should return created connection properties`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -157,7 +134,7 @@ test(`${currentTest} should return created connection properties`, async (t) => test(`${currentTest} should return connection without excluded tables`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -197,7 +174,7 @@ test(`${currentTest} should return connection without excluded tables`, async (t test(`${currentTest} should throw an exception when excluded table name is incorrect`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -229,7 +206,7 @@ currentTest = 'GET /connection/properties/:slug'; test(`${currentTest} should return connection properties`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -266,7 +243,7 @@ test(`${currentTest} should return connection properties`, async (t) => { test(`${currentTest} should throw exception when connection id is incorrect`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -286,7 +263,7 @@ test(`${currentTest} should throw exception when connection id is incorrect`, as t.is(createConnectionPropertiesResponse.status, 201); const getConnectionPropertiesResponse = await request(app.getHttpServer()) - .get(`/connection/properties/${faker.datatype.uuid()}`) + .get(`/connection/properties/${faker.string.uuid()}`) .set('Cookie', token) .set('Content-Type', 'application/json') .set('Accept', 'application/json'); @@ -300,7 +277,7 @@ currentTest = 'DELETE /connection/properties/:slug'; test(`${currentTest} should return deleted connection properties`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -358,7 +335,7 @@ test(`${currentTest} should return deleted connection properties`, async (t) => test(`${currentTest} should throw exception when connection id is incorrect`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') @@ -378,7 +355,7 @@ test(`${currentTest} should throw exception when connection id is incorrect`, as t.is(createConnectionPropertiesResponse.status, 201); const getConnectionPropertiesResponse = await request(app.getHttpServer()) - .get(`/connection/properties/${faker.datatype.uuid()}`) + .get(`/connection/properties/${faker.string.uuid()}`) .set('Cookie', token) .set('Content-Type', 'application/json') .set('Accept', 'application/json'); @@ -392,7 +369,7 @@ currentTest = 'PUT /connection/properties/:slug'; test(`${currentTest} should return updated connection properties`, async (t) => { try { const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData(); - const { token } = await registerUserAndReturnUserInfo(); + const { token } = await registerUserAndReturnUserInfo(app); const createConnectionResponse = await request(app.getHttpServer()) .post('/connection') diff --git a/backend/test/ava-tests/custom-field-e2e.test.ts b/backend/test/ava-tests/custom-field-e2e.test.ts index 9add59cd..bb3a1020 100644 --- a/backend/test/ava-tests/custom-field-e2e.test.ts +++ b/backend/test/ava-tests/custom-field-e2e.test.ts @@ -191,7 +191,7 @@ test.serial(`${currentTest} should throw exception when connection id passed in t.is(createConnectionResponse.status, 201); const newCustomField = mockFactory.generateCustomFieldForConnectionTable('id', 'title'); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const createCustomFieldResponse = await request(app.getHttpServer()) .post(`/field/${createConnectionRO.id}?tableName=connection`) @@ -511,7 +511,7 @@ test.serial(`${currentTest} should throw exception when connection id passed in t.is(createConnectionResponse.status, 201); const newCustomField = mockFactory.generateCustomFieldForConnectionTable('id', 'title'); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const createCustomFieldResponse = await request(app.getHttpServer()) .post(`/field/${createConnectionRO.id}?tableName=connection`) .send(newCustomField) @@ -754,7 +754,7 @@ test.serial(`${currentTest} should throw exception, when connection id passed in text: 'updated', template_string: 'https//?connectionId={{id}}&connectionType={{type}}', }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateCustomFieldResponse = await request(app.getHttpServer()) .put(`/field/${createConnectionRO.id}?tableName=connection`) .send(updateDTO) @@ -1499,7 +1499,7 @@ test.serial(`${currentTest} should throw exception, when connection id passed in t.is(getCustomFieldsRO[0].text, newCustomField.text); t.is(getCustomFieldsRO[0].template_string, 'https//?connectionId={{id}}&connectionTitle={{title}}'); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const deleteCustomField = await request(app.getHttpServer()) .delete(`/field/${createConnectionRO.id}?tableName=connection&id=${getCustomFieldsRO[0].id}`) .set('Content-Type', 'application/json') @@ -1715,7 +1715,7 @@ test.serial(`${currentTest} should throw exception, when field id passed in requ t.is(getCustomFieldsRO[0].text, newCustomField.text); t.is(getCustomFieldsRO[0].template_string, 'https//?connectionId={{id}}&connectionTitle={{title}}'); - getCustomFieldsRO[0].id = faker.datatype.uuid(); + getCustomFieldsRO[0].id = faker.string.uuid(); const deleteCustomField = await request(app.getHttpServer()) .delete(`/field/${createConnectionRO.id}?tableName=connection&id=${getCustomFieldsRO[0].id}`) .set('Content-Type', 'application/json') diff --git a/backend/test/ava-tests/group-e2e.test.ts b/backend/test/ava-tests/group-e2e.test.ts index 5eb03d67..da1ec9d6 100644 --- a/backend/test/ava-tests/group-e2e.test.ts +++ b/backend/test/ava-tests/group-e2e.test.ts @@ -8,7 +8,10 @@ import { DatabaseModule } from '../../src/shared/database/database.module.js'; import { DatabaseService } from '../../src/shared/database/database.service.js'; import cookieParser from 'cookie-parser'; import { AllExceptionsFilter } from '../../src/exceptions/all-exceptions.filter.js'; -import { registerUserAndReturnUserInfo } from '../utils/register-user-and-return-user-info.js'; +import { + inviteUserInCompanyAndAcceptInvitation, + registerUserAndReturnUserInfo, +} from '../utils/register-user-and-return-user-info.js'; import { getTestData } from '../utils/get-test-data.js'; import request from 'supertest'; import { AccessLevelEnum } from '../../src/enums/index.js'; @@ -75,7 +78,6 @@ test(`${currentTest} should return all user groups`, async (t) => { t.is(findAllUserGroups.status, 200); const result = JSON.parse(findAllUserGroups.text); - console.log('-> result', result); t.is(result.length, 2); t.is(uuidRegex.test(result[0].group.id), true); @@ -174,7 +176,7 @@ test(`${currentTest} should throw an error when group id is not real`, async (t) const createGroupRO = JSON.parse(createGroupResponse.text); - createGroupRO.id = faker.datatype.uuid(); + createGroupRO.id = faker.string.uuid(); const findAllUsersInGroup = await request(app.getHttpServer()) .get(`/group/users/${createGroupRO.id}`) .set('Cookie', firstUserToken) @@ -240,7 +242,7 @@ currentTest = 'PUT /group/user/:slug'; test(`${currentTest} should return a group with new added user`, async (t) => { try { const firstUserToken = (await registerUserAndReturnUserInfo(app)).token; - const secondUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const secondUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation(firstUserToken, undefined, app); const { newConnection, newConnection2, newGroup1 } = getTestData(mockFactory); let createConnectionResponse = await request(app.getHttpServer()) @@ -299,7 +301,7 @@ test(`${currentTest} should return a group with new added user`, async (t) => { test(`${currentTest} should throw an error when groupId not passed in request`, async (t) => { try { const firstUserToken = (await registerUserAndReturnUserInfo(app)).token; - const secondUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const secondUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation(firstUserToken, undefined, app); const { newConnection, newConnection2, newGroup1 } = getTestData(mockFactory); let createConnectionResponse = await request(app.getHttpServer()) @@ -402,7 +404,7 @@ test(`${currentTest} should throw an error when user email not passed in request test(`${currentTest} should throw an error when groupId is incorrect`, async (t) => { try { const firstUserToken = (await registerUserAndReturnUserInfo(app)).token; - const secondUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const secondUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation(firstUserToken, undefined, app); const { newConnection, newConnection2, newGroup1 } = getTestData(mockFactory); @@ -433,7 +435,7 @@ test(`${currentTest} should throw an error when groupId is incorrect`, async (t) const createGroupRO = JSON.parse(createGroupResponse.text); - createGroupRO.id = faker.datatype.uuid(); + createGroupRO.id = faker.string.uuid(); const requestBody = { email: secondUserRegisterInfo.email, @@ -458,7 +460,7 @@ test(`${currentTest} should throw an error when groupId is incorrect`, async (t) test(`${currentTest} should throw an error when add a user what been already added in this group`, async (t) => { try { const firstUserToken = (await registerUserAndReturnUserInfo(app)).token; - const secondUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const secondUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation(firstUserToken, undefined, app); const { newConnection, newConnection2, newGroup1 } = getTestData(mockFactory); @@ -468,7 +470,7 @@ test(`${currentTest} should throw an error when add a user what been already add .set('Cookie', firstUserToken) .set('Content-Type', 'application/json') .set('Accept', 'application/json'); - const createConnectionRO = JSON.parse(createConnectionResponse.text); + let createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); createConnectionResponse = await request(app.getHttpServer()) @@ -478,6 +480,7 @@ test(`${currentTest} should throw an error when add a user what been already add .set('Content-Type', 'application/json') .set('Accept', 'application/json'); t.is(createConnectionResponse.status, 201); + createConnectionRO = JSON.parse(createConnectionResponse.text); const createGroupResponse = await request(app.getHttpServer()) .post(`/connection/group/${createConnectionRO.id}`) @@ -493,6 +496,7 @@ test(`${currentTest} should throw an error when add a user what been already add email: secondUserRegisterInfo.email, groupId: createGroupRO.id, }; + const addUserInGroup1 = await request(app.getHttpServer()) .put(`/group/user/`) .send(requestBody) @@ -508,6 +512,7 @@ test(`${currentTest} should throw an error when add a user what been already add .set('Cookie', firstUserToken) .set('Content-Type', 'application/json') .set('Accept', 'application/json'); + t.is(addUserInGroup2.status, 400); const { message } = JSON.parse(addUserInGroup2.text); t.is(message, Messages.USER_ALREADY_ADDED_BUT_NOT_ACTIVE); @@ -626,7 +631,7 @@ test(`${currentTest} should return throw an exception when groupId is incorrect` const createGroupRO = JSON.parse(createGroupResponse.text); - createGroupRO.id = faker.datatype.uuid(); + createGroupRO.id = faker.string.uuid(); const deleteResult = await request(app.getHttpServer()) .delete(`/group/${createGroupRO.id}`) .set('Cookie', firstUserToken) @@ -694,7 +699,7 @@ currentTest = 'PUT /group/user/delete'; test(`${currentTest} should return a group without deleted user`, async (t) => { try { const firstUserToken = (await registerUserAndReturnUserInfo(app)).token; - const secondUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const secondUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation(firstUserToken, undefined, app); const { newConnection, newConnection2, newGroup1 } = getTestData(mockFactory); @@ -772,7 +777,7 @@ test(`${currentTest} should return a group without deleted user`, async (t) => { test(`${currentTest} should throw an error, when group id not passed in request`, async (t) => { try { const firstUserToken = (await registerUserAndReturnUserInfo(app)).token; - const secondUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const secondUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation(firstUserToken, undefined, app); const { newConnection, newConnection2, newGroup1 } = getTestData(mockFactory); @@ -845,7 +850,7 @@ test(`${currentTest} should throw an error, when group id not passed in request` test(`${currentTest} should throw an error, when email is not passed in request`, async (t) => { try { const firstUserToken = (await registerUserAndReturnUserInfo(app)).token; - const secondUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const secondUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation(firstUserToken, undefined, app); const { newConnection, newConnection2, newGroup1 } = getTestData(mockFactory); let createConnectionResponse = await request(app.getHttpServer()) @@ -917,7 +922,7 @@ test(`${currentTest} should throw an error, when email is not passed in request` test(`${currentTest} should throw an error, when there is no this email in database`, async (t) => { try { const firstUserToken = (await registerUserAndReturnUserInfo(app)).token; - const secondUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const secondUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation(firstUserToken, undefined, app); const { newConnection, newConnection2, newGroup1 } = getTestData(mockFactory); @@ -983,7 +988,7 @@ test(`${currentTest} should throw an error, when there is no this email in datab test(`${currentTest} should throw an error, when group id is incorrect`, async (t) => { try { const firstUserToken = (await registerUserAndReturnUserInfo(app)).token; - const secondUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const secondUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation(firstUserToken, undefined, app); const { newConnection, newConnection2, newGroup1 } = getTestData(mockFactory); @@ -1035,7 +1040,7 @@ test(`${currentTest} should throw an error, when group id is incorrect`, async ( t.is(uuidRegex.test(result.users[0].id), true); t.is(result.users[1].email, secondUserRegisterInfo.email); - requestBody.groupId = faker.datatype.uuid(); + requestBody.groupId = faker.string.uuid(); const removeUserFromGroup = await request(app.getHttpServer()) .put(`/group/user/delete/`) .send(requestBody) diff --git a/backend/test/ava-tests/permissions-e2e.test.ts b/backend/test/ava-tests/permissions-e2e.test.ts index 01b9f84a..d44dd520 100644 --- a/backend/test/ava-tests/permissions-e2e.test.ts +++ b/backend/test/ava-tests/permissions-e2e.test.ts @@ -197,7 +197,7 @@ test(`${currentTest} should throw an exception when groupId passed in request is connectionAccessLevel, groupAccesssLevel, ); - createGroupRO.id = faker.datatype.uuid(); + createGroupRO.id = faker.string.uuid(); let createPermissionsResponse = await request(app.getHttpServer()) .put(`/permissions/${createGroupRO.id}`) .send(permissionsDTO) @@ -243,7 +243,7 @@ test(`${currentTest} should throw an exception when connectionId is incorrect`, connectionAccessLevel, groupAccesssLevel, ); - permissionsDTO.permissions.connection.connectionId = faker.datatype.uuid(); + permissionsDTO.permissions.connection.connectionId = faker.string.uuid(); let createPermissionsResponse = await request(app.getHttpServer()) .put(`/permissions/${createGroupRO.id}`) .send(permissionsDTO) diff --git a/backend/test/ava-tests/table-actions-e2e.test.ts b/backend/test/ava-tests/table-actions-e2e.test.ts index 1f0974e9..a9d5a0ca 100644 --- a/backend/test/ava-tests/table-actions-e2e.test.ts +++ b/backend/test/ava-tests/table-actions-e2e.test.ts @@ -165,7 +165,7 @@ test(`${currentTest} should throw exception when connection id incorrect`, async const createConnectionRO = JSON.parse(createConnectionResult.text); t.is(createConnectionResult.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const createTableActionResult = await request(app.getHttpServer()) .post(`/table/action/${createConnectionRO.id}?tableName=${testTableName}`) .send(newTableAction) @@ -236,7 +236,7 @@ test(`${currentTest} should throw exception when connection id incorrect`, async t.is(createTableActionResult.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const findTableActiponResult = await request(app.getHttpServer()) .get(`/table/actions/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', token) @@ -336,7 +336,7 @@ test(`${currentTest} should throw exception when type is incorrect`, async (t) = }; updatedTableAction.title = faker.lorem.words(2); updatedTableAction.url = faker.internet.url(); - updatedTableAction.type = faker.datatype.uuid() as any; + updatedTableAction.type = faker.string.uuid() as any; const updateTableActionResult = await request(app.getHttpServer()) .post(`/table/action/${createConnectionRO.id}?tableName=${testTableName}&actionId=${createTableActionRO.id}`) @@ -378,7 +378,7 @@ test(`${currentTest} should throw exception when connection id incorrect`, async updatedTableAction.title = faker.lorem.words(2); updatedTableAction.url = faker.internet.url(); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateTableActionResult = await request(app.getHttpServer()) .post(`/table/action/${createConnectionRO.id}?tableName=${testTableName}&actionId=${createTableActionRO.id}`) .send(updatedTableAction) @@ -456,7 +456,7 @@ test(`${currentTest} should throw exception when connection id incorrect`, async const createTableActionRO = JSON.parse(createTableActionResult.text); t.is(createTableActionResult.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const deleteTableActionResult = await request(app.getHttpServer()) .delete(`/table/action/${createConnectionRO.id}?actionId=${createTableActionRO.id}`) .set('Cookie', token) @@ -488,7 +488,7 @@ test(`${currentTest} should throw exception when table action id incorrect`, asy const createTableActionRO = JSON.parse(createTableActionResult.text); t.is(createTableActionResult.status, 201); - createTableActionRO.id = faker.datatype.uuid(); + createTableActionRO.id = faker.string.uuid(); const deleteTableActionResult = await request(app.getHttpServer()) .delete(`/table/action/${createConnectionRO.id}?actionId=${createTableActionRO.id}`) .set('Cookie', token) @@ -558,7 +558,7 @@ test(`${currentTest} should throw exception when connection id incorrect`, async const createTableActionRO = JSON.parse(createConnectionResult.text); t.is(createTableActionResult.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const findTableActionResult = await request(app.getHttpServer()) .get(`/table/action/${createConnectionRO.id}?actionId=${createTableActionRO.id}`) @@ -592,7 +592,7 @@ test(`${currentTest} should throw exception when table action id is incorrect`, const createTableActionRO = JSON.parse(createConnectionResult.text); t.is(createTableActionResult.status, 201); - createTableActionRO.id = faker.datatype.uuid(); + createTableActionRO.id = faker.string.uuid(); const findTableActionResult = await request(app.getHttpServer()) .get(`/table/action/${createConnectionRO.id}?actionId=${createTableActionRO.id}`) diff --git a/backend/test/ava-tests/table-mssql-agent-e2e.test.ts b/backend/test/ava-tests/table-mssql-agent-e2e.test.ts index fc855a3c..a937a4e6 100644 --- a/backend/test/ava-tests/table-mssql-agent-e2e.test.ts +++ b/backend/test/ava-tests/table-mssql-agent-e2e.test.ts @@ -191,7 +191,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1548,7 +1548,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1606,7 +1606,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1766,7 +1766,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2044,7 +2044,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2189,7 +2189,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2222,7 +2222,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2255,7 +2255,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2466,7 +2466,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2556,7 +2556,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2773,7 +2773,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -2823,7 +2823,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-mssql-cli-e2e.test.ts b/backend/test/ava-tests/table-mssql-cli-e2e.test.ts index 5d22205e..3b87173c 100644 --- a/backend/test/ava-tests/table-mssql-cli-e2e.test.ts +++ b/backend/test/ava-tests/table-mssql-cli-e2e.test.ts @@ -191,7 +191,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1546,7 +1546,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1604,7 +1604,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1764,7 +1764,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2042,7 +2042,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2187,7 +2187,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2220,7 +2220,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2253,7 +2253,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2465,7 +2465,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2555,7 +2555,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2772,7 +2772,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -2822,7 +2822,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-mssql-e2e.test.ts b/backend/test/ava-tests/table-mssql-e2e.test.ts index cef20de9..a0fd0105 100644 --- a/backend/test/ava-tests/table-mssql-e2e.test.ts +++ b/backend/test/ava-tests/table-mssql-e2e.test.ts @@ -157,7 +157,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1645,7 +1645,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1709,7 +1709,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1890,7 +1890,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2206,7 +2206,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2366,7 +2366,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2404,7 +2404,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2442,7 +2442,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2684,7 +2684,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2784,7 +2784,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -3030,7 +3030,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -3090,7 +3090,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-mssql-schema-e2e.test.ts b/backend/test/ava-tests/table-mssql-schema-e2e.test.ts index 71bd3a45..e4774983 100644 --- a/backend/test/ava-tests/table-mssql-schema-e2e.test.ts +++ b/backend/test/ava-tests/table-mssql-schema-e2e.test.ts @@ -144,7 +144,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1632,7 +1632,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1696,7 +1696,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1877,7 +1877,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2193,7 +2193,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2353,7 +2353,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2391,7 +2391,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2429,7 +2429,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2671,7 +2671,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2771,7 +2771,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -3017,7 +3017,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -3077,7 +3077,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-mysql-agent-e2e.test.ts b/backend/test/ava-tests/table-mysql-agent-e2e.test.ts index 28a896bf..120d5459 100644 --- a/backend/test/ava-tests/table-mysql-agent-e2e.test.ts +++ b/backend/test/ava-tests/table-mysql-agent-e2e.test.ts @@ -191,7 +191,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1548,7 +1548,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1606,7 +1606,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1766,7 +1766,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2048,7 +2048,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2193,7 +2193,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2226,7 +2226,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2259,7 +2259,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2469,7 +2469,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2559,7 +2559,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2776,7 +2776,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -2826,7 +2826,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-mysql-cli-e2e.test.ts b/backend/test/ava-tests/table-mysql-cli-e2e.test.ts index b682763c..db9b9425 100644 --- a/backend/test/ava-tests/table-mysql-cli-e2e.test.ts +++ b/backend/test/ava-tests/table-mysql-cli-e2e.test.ts @@ -190,7 +190,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1548,7 +1548,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1606,7 +1606,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1766,7 +1766,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2048,7 +2048,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2193,7 +2193,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2226,7 +2226,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2259,7 +2259,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2469,7 +2469,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2559,7 +2559,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2776,7 +2776,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -2826,7 +2826,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-mysql-e2e.test.ts b/backend/test/ava-tests/table-mysql-e2e.test.ts index 924212d2..94419bc1 100644 --- a/backend/test/ava-tests/table-mysql-e2e.test.ts +++ b/backend/test/ava-tests/table-mysql-e2e.test.ts @@ -152,7 +152,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1636,7 +1636,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1700,7 +1700,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1881,7 +1881,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2197,7 +2197,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2357,7 +2357,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2395,7 +2395,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2433,7 +2433,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2675,7 +2675,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2775,7 +2775,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -3021,7 +3021,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -3081,7 +3081,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-oracle-agent-e2e.test.ts b/backend/test/ava-tests/table-oracle-agent-e2e.test.ts index 4f0ff8f9..0335579c 100644 --- a/backend/test/ava-tests/table-oracle-agent-e2e.test.ts +++ b/backend/test/ava-tests/table-oracle-agent-e2e.test.ts @@ -191,7 +191,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1548,7 +1548,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1606,7 +1606,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1766,7 +1766,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2048,7 +2048,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2193,7 +2193,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2226,7 +2226,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2259,7 +2259,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2469,7 +2469,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2559,7 +2559,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2776,7 +2776,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -2826,7 +2826,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-oracle-cli-e2e.test.ts b/backend/test/ava-tests/table-oracle-cli-e2e.test.ts index 99389f06..cb30c200 100644 --- a/backend/test/ava-tests/table-oracle-cli-e2e.test.ts +++ b/backend/test/ava-tests/table-oracle-cli-e2e.test.ts @@ -191,7 +191,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1548,7 +1548,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1606,7 +1606,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1766,7 +1766,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2048,7 +2048,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2193,7 +2193,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2226,7 +2226,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2259,7 +2259,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2469,7 +2469,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2559,7 +2559,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2776,7 +2776,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -2826,7 +2826,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-oracledb-e2e.test.ts b/backend/test/ava-tests/table-oracledb-e2e.test.ts index 00515bdc..7242f5a3 100644 --- a/backend/test/ava-tests/table-oracledb-e2e.test.ts +++ b/backend/test/ava-tests/table-oracledb-e2e.test.ts @@ -155,7 +155,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1642,7 +1642,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1706,7 +1706,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1887,7 +1887,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2204,7 +2204,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2364,7 +2364,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2402,7 +2402,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2440,7 +2440,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2682,7 +2682,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2782,7 +2782,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -3028,7 +3028,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -3088,7 +3088,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-oracledb-schema-e2e.test.ts b/backend/test/ava-tests/table-oracledb-schema-e2e.test.ts index e84486f7..2e3d8dbf 100644 --- a/backend/test/ava-tests/table-oracledb-schema-e2e.test.ts +++ b/backend/test/ava-tests/table-oracledb-schema-e2e.test.ts @@ -153,7 +153,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1641,7 +1641,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1705,7 +1705,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1886,7 +1886,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2203,7 +2203,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2363,7 +2363,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2401,7 +2401,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2439,7 +2439,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2681,7 +2681,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2781,7 +2781,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -3027,7 +3027,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -3087,7 +3087,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-postgres-agent-e2e.test.ts b/backend/test/ava-tests/table-postgres-agent-e2e.test.ts index 08172abb..aae62b1f 100644 --- a/backend/test/ava-tests/table-postgres-agent-e2e.test.ts +++ b/backend/test/ava-tests/table-postgres-agent-e2e.test.ts @@ -191,7 +191,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1548,7 +1548,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1606,7 +1606,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1766,7 +1766,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2048,7 +2048,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2193,7 +2193,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2226,7 +2226,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2259,7 +2259,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2469,7 +2469,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2559,7 +2559,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2776,7 +2776,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -2826,7 +2826,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-postgres-cli-e2e.test.ts b/backend/test/ava-tests/table-postgres-cli-e2e.test.ts index 6463ffd8..a4c08bb6 100644 --- a/backend/test/ava-tests/table-postgres-cli-e2e.test.ts +++ b/backend/test/ava-tests/table-postgres-cli-e2e.test.ts @@ -191,7 +191,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1548,7 +1548,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1606,7 +1606,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1766,7 +1766,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2048,7 +2048,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2193,7 +2193,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2226,7 +2226,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2259,7 +2259,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2469,7 +2469,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2559,7 +2559,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2776,7 +2776,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -2826,7 +2826,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-postgres-e2e.test.ts b/backend/test/ava-tests/table-postgres-e2e.test.ts index 3c74337b..9c8750b0 100644 --- a/backend/test/ava-tests/table-postgres-e2e.test.ts +++ b/backend/test/ava-tests/table-postgres-e2e.test.ts @@ -134,7 +134,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1619,7 +1619,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1683,7 +1683,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1864,7 +1864,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2340,7 +2340,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2378,7 +2378,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2416,7 +2416,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2658,7 +2658,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2758,7 +2758,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -3004,7 +3004,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -3064,7 +3064,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-postgres-encrypted-e2e.test.ts b/backend/test/ava-tests/table-postgres-encrypted-e2e.test.ts index f23938b9..8ec78ddd 100644 --- a/backend/test/ava-tests/table-postgres-encrypted-e2e.test.ts +++ b/backend/test/ava-tests/table-postgres-encrypted-e2e.test.ts @@ -159,7 +159,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1706,7 +1706,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1773,7 +1773,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1963,7 +1963,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2021,7 +2021,7 @@ test(`${currentTest} should throw an exception when tableName passed in request .set('Accept', 'application/json'); const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - const tableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const tableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${tableName}`) .set('Cookie', firstUserToken) @@ -2297,7 +2297,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2466,7 +2466,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2506,7 +2506,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2546,7 +2546,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2802,7 +2802,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2914,7 +2914,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -3181,7 +3181,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -3245,7 +3245,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-postgres-schema-e2e.test.ts b/backend/test/ava-tests/table-postgres-schema-e2e.test.ts index bbcee3c4..56f4e6ab 100644 --- a/backend/test/ava-tests/table-postgres-schema-e2e.test.ts +++ b/backend/test/ava-tests/table-postgres-schema-e2e.test.ts @@ -151,7 +151,7 @@ test(`${currentTest} should throw an error when connection id is incorrect`, asy const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTablesResponse = await request(app.getHttpServer()) .get(`/connection/tables/${createConnectionRO.id}`) .set('Cookie', firstUserToken) @@ -1639,7 +1639,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const fieldGtvalue = '25'; const fieldLtvalue = '40'; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${testTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1703,7 +1703,7 @@ test(`${currentTest} should throw an exception when table name passed in request const fieldGtvalue = '25'; const fieldLtvalue = '40'; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableRowsResponse = await request(app.getHttpServer()) .get( `/table/rows/${createConnectionRO.id}?tableName=${fakeTableName}&search=${testSearchedUserName}&page=1&perPage=2&f_${fieldname}__lt=${fieldLtvalue}&f_${fieldname}__gt=${fieldGtvalue}`, @@ -1884,7 +1884,7 @@ test(`${currentTest} should throw an exception whe connection id passed in reque const createConnectionRO = JSON.parse(createConnectionResponse.text); t.is(createConnectionResponse.status, 201); - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const getTableStructure = await request(app.getHttpServer()) .get(`/table/structure/${createConnectionRO.id}?tableName=${testTableName}`) .set('Cookie', firstUserToken) @@ -2200,7 +2200,7 @@ test(`${currentTest} should throw an exception when table name passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTableResponse = await request(app.getHttpServer()) .post(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}`) .send(JSON.stringify(row)) @@ -2360,7 +2360,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=1`) .send(JSON.stringify(row)) @@ -2398,7 +2398,7 @@ test(`${currentTest} should throw an exception when tableName not passed in requ [testTableSecondColumnName]: fakeMail, }; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=&id=1`) .send(JSON.stringify(row)) @@ -2436,7 +2436,7 @@ test(`${currentTest} should throw an exception when tableName passed in request [testTableSecondColumnName]: fakeMail, }; - const fakeTableName = faker.datatype.uuid(); + const fakeTableName = faker.string.uuid(); const updateRowInTableResponse = await request(app.getHttpServer()) .put(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=1`) .send(JSON.stringify(row)) @@ -2678,7 +2678,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const connectionId = faker.datatype.uuid(); + const connectionId = faker.string.uuid(); const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${connectionId}?tableName=${testTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -2778,7 +2778,7 @@ test(`${currentTest} should throw an exception when tableName passed in request t.is(createConnectionResponse.status, 201); const idForDeletion = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTableResponse = await request(app.getHttpServer()) .delete(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForDeletion}`) .set('Cookie', firstUserToken) @@ -3024,7 +3024,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req t.is(createConnectionResponse.status, 201); const idForSearch = 1; - createConnectionRO.id = faker.datatype.uuid(); + createConnectionRO.id = faker.string.uuid(); const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${testTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) @@ -3084,7 +3084,7 @@ test(`${currentTest} should throw an exception, when tableName passed in request t.is(createConnectionResponse.status, 201); const idForSearch = 1; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const foundRowInTableResponse = await request(app.getHttpServer()) .get(`/table/row/${createConnectionRO.id}?tableName=${fakeTableName}&id=${idForSearch}`) .set('Cookie', firstUserToken) diff --git a/backend/test/ava-tests/table-widgets-e2e.test.ts b/backend/test/ava-tests/table-widgets-e2e.test.ts index 020ee359..fc634eab 100644 --- a/backend/test/ava-tests/table-widgets-e2e.test.ts +++ b/backend/test/ava-tests/table-widgets-e2e.test.ts @@ -208,7 +208,7 @@ test(`${currentTest} should throw exception when connection id passed in request t.is(uuidRegex.test(createTableWidgetRO[1].id), true); t.is(createTableWidgetRO[0].description, newTableWidgets[0].description); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const getTableWidgets = await request(app.getHttpServer()) .get(`/widgets/${fakeConnectionId}?tableName=${tableNameForWidgets}`) .set('Content-Type', 'application/json') @@ -252,7 +252,7 @@ test(`${currentTest} should throw exception when tableName passed in request is t.is(uuidRegex.test(createTableWidgetRO[1].id), true); t.is(createTableWidgetRO[0].description, newTableWidgets[0].description); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTableWidgets = await request(app.getHttpServer()) .get(`/widgets/${connectionId}?tableName=${fakeTableName}`) .set('Content-Type', 'application/json') @@ -590,7 +590,7 @@ test(`${currentTest} should throw exception when connection id passed in request .set('Accept', 'application/json'); const newTableWidgets = mockFactory.generateCreateWidgetDTOsArrayForConnectionTable(); const connectionId = JSON.parse(createdConnection.text).id; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const createTableWidgetResponse = await request(app.getHttpServer()) .post(`/widget/${fakeConnectionId}?tableName=${tableNameForWidgets}`) .send({ widgets: newTableWidgets }) @@ -616,7 +616,7 @@ test(`${currentTest} should throw exception when tableName passed in request is const connectionId = JSON.parse(createdConnection.text).id; const newTableWidgets = mockFactory.generateCreateWidgetDTOsArrayForConnectionTable(); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const createTableWidgetResponse = await request(app.getHttpServer()) .post(`/widget/${connectionId}?tableName=${fakeTableName}`) diff --git a/backend/test/ava-tests/user-admin-permissions-e2e.test.ts b/backend/test/ava-tests/user-admin-permissions-e2e.test.ts index de80efc4..dc779dfd 100644 --- a/backend/test/ava-tests/user-admin-permissions-e2e.test.ts +++ b/backend/test/ava-tests/user-admin-permissions-e2e.test.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable security/detect-object-injection */ import { faker } from '@faker-js/faker'; import { INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; @@ -16,6 +18,7 @@ import { MockFactory } from '../mock.factory.js'; import { compareTableWidgetsArrays } from '../utils/compare-table-widgets-arrays.js'; import { TestUtils } from '../utils/test.utils.js'; import { createConnectionsAndInviteNewUserInAdminGroupOfFirstConnection } from '../utils/user-with-different-permissions-utils.js'; +import { inviteUserInCompanyAndAcceptInvitation } from '../utils/register-user-and-return-user-info.js'; let app: INestApplication; let testUtils: TestUtils; @@ -64,24 +67,24 @@ test(`${currentTest} should return connections, where second user have access`, t.is(findAll.status, 200); const result = findAll.body.connections; - t.is(result.length, 5); + t.is(result.length, 1); t.is(result[0].hasOwnProperty('connection'), true); - t.is(result[1].hasOwnProperty('accessLevel'), true); - t.is(result[2].accessLevel, AccessLevelEnum.edit); + t.is(result[0].hasOwnProperty('accessLevel'), true); + t.is(result[0].accessLevel, AccessLevelEnum.edit); t.is(uuidRegex.test(result[0].connection.id), true); - t.is(result[3].hasOwnProperty('accessLevel'), true); - t.is(result[4].connection.hasOwnProperty('host'), true); - t.is(result[3].connection.hasOwnProperty('host'), true); + t.is(result[0].hasOwnProperty('accessLevel'), true); + t.is(result[0].connection.hasOwnProperty('host'), true); + t.is(result[0].connection.hasOwnProperty('host'), true); t.is(typeof result[0].connection.port, 'number'); - t.is(result[1].connection.hasOwnProperty('port'), true); - t.is(result[2].connection.hasOwnProperty('username'), true); - t.is(result[3].connection.hasOwnProperty('database'), true); - t.is(result[4].connection.hasOwnProperty('sid'), true); + t.is(result[0].connection.hasOwnProperty('port'), true); + t.is(result[0].connection.hasOwnProperty('username'), true); + t.is(result[0].connection.hasOwnProperty('database'), true); + t.is(result[0].connection.hasOwnProperty('sid'), true); t.is(result[0].connection.hasOwnProperty('createdAt'), true); - t.is(result[1].connection.hasOwnProperty('updatedAt'), true); - t.is(result[2].connection.hasOwnProperty('password'), false); - t.is(result[3].connection.hasOwnProperty('groups'), false); - t.is(result[4].connection.hasOwnProperty('author'), false); + t.is(result[0].connection.hasOwnProperty('updatedAt'), true); + t.is(result[0].connection.hasOwnProperty('password'), false); + t.is(result[0].connection.hasOwnProperty('groups'), false); + t.is(result[0].connection.hasOwnProperty('author'), false); } catch (error) { console.error(error); throw error; @@ -661,13 +664,13 @@ test(`${currentTest} should return found groups with current user`, async (t) => t.is(getGroupsResponse.status, 200); const getGroupsRO = JSON.parse(getGroupsResponse.text); const { groups, groupsCount } = getGroupsRO; - t.is(groupsCount, 5); - t.is(groups.length, 5); + t.is(groupsCount, 1); + t.is(groups.length, 1); t.is(groups[0].hasOwnProperty('group'), true); - t.is(groups[1].hasOwnProperty('accessLevel'), true); + t.is(groups[0].hasOwnProperty('accessLevel'), true); t.is(uuidRegex.test(groups[0].group.id), true); - t.is(groups[2].group.hasOwnProperty('title'), true); - t.is(groups[3].group.hasOwnProperty('isMain'), true); + t.is(groups[0].group.hasOwnProperty('title'), true); + t.is(groups[0].group.hasOwnProperty('isMain'), true); } catch (error) { console.error(error); throw error; @@ -750,7 +753,11 @@ test(`${currentTest} should return group with added user`, async (t) => { const getGroupsRO = JSON.parse(getGroupsResponse.text); const groupId = getGroupsRO[0].group.id; - const email = faker.internet.email(); + + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(testData.users.adminUserToken, undefined, app); + + const email = thirdTestUser.email; + const addUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user') .set('Cookie', testData.users.simpleUserToken) @@ -845,7 +852,7 @@ test(`${currentTest} should throw exception, when group id passed in request is const getGroupsRO = JSON.parse(getGroupsResponse.text); const email = faker.internet.email(); - const groupId = faker.datatype.uuid(); + const groupId = faker.string.uuid(); const addUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user') .set('Cookie', testData.users.simpleUserToken) @@ -962,7 +969,7 @@ test(`${currentTest} should throw an exception when group id passed in request i t.is(getGroupsResponse.status, 200); - const groupId = faker.datatype.uuid(); + const groupId = faker.string.uuid(); const deleteGroupResponse = await request(app.getHttpServer()) .delete(`/group/${groupId}`) .set('Cookie', testData.users.simpleUserToken) @@ -992,7 +999,11 @@ test(`${currentTest} should return group without deleted user`, async (t) => { const getGroupsRO = JSON.parse(getGroupsResponse.text); const groupId = getGroupsRO[0].group.id; - const email = faker.internet.email(); + + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(testData.users.adminUserToken, undefined, app); + + const email = thirdTestUser.email; + const addUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user') .set('Cookie', testData.users.simpleUserToken) @@ -1034,14 +1045,10 @@ test(`${currentTest} should throw exception, when user email not passed in reque const getGroupsRO = JSON.parse(getGroupsResponse.text); const groupId = getGroupsRO[0].group.id; - const email = faker.internet.email(); - const addUserInGroupResponse = await request(app.getHttpServer()) - .put('/group/user') - .set('Cookie', testData.users.simpleUserToken) - .send({ groupId, email }) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - t.is(addUserInGroupResponse.status, 200); + + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(testData.users.adminUserToken, undefined, app); + + const email = thirdTestUser.email; const deleteUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user/delete') @@ -1071,15 +1078,9 @@ test(`${currentTest} should throw exception, when group id not passed in request const groupId = getGroupsRO[0].group.id; - const email = faker.internet.email(); - const addUserInGroupResponse = await request(app.getHttpServer()) - .put('/group/user') - .set('Cookie', testData.users.simpleUserToken) - .send({ groupId, email }) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - - t.is(addUserInGroupResponse.status, 200); + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(testData.users.adminUserToken, undefined, app); + + const email = thirdTestUser.email; const deleteUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user/delete') @@ -1108,17 +1109,11 @@ test(`${currentTest} should throw exception, when group id passed in request is const getGroupsRO = JSON.parse(getGroupsResponse.text); let groupId = getGroupsRO[0].group.id; - const email = faker.internet.email(); - const addUserInGroupResponse = await request(app.getHttpServer()) - .put('/group/user') - .set('Cookie', testData.users.simpleUserToken) - .send({ groupId, email }) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - - t.is(addUserInGroupResponse.status, 200); + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(testData.users.adminUserToken, undefined, app); + + const email = thirdTestUser.email; - groupId = faker.datatype.uuid(); + groupId = faker.string.uuid(); const deleteUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user/delete') .set('Cookie', testData.users.simpleUserToken) @@ -1503,7 +1498,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req .set('Accept', 'application/json'); t.is(createOrUpdatePermissionResponse.status, 200); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const getTablesInConnection = await request(app.getHttpServer()) .get(`/connection/tables/${fakeConnectionId}`) .set('Cookie', testData.users.simpleUserToken) @@ -1689,7 +1684,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ .set('Accept', 'application/json'); t.is(createOrUpdatePermissionResponse.status, 200); - const fakeId = faker.datatype.uuid(); + const fakeId = faker.string.uuid(); const getTablesInConnection = await request(app.getHttpServer()) .get(`/table/rows/${fakeId}?tableName=${testData.firstTableInfo.testTableName}`) .set('Cookie', testData.users.simpleUserToken) @@ -1750,7 +1745,7 @@ test(`${currentTest} should throw an exception when table name passed in request .set('Accept', 'application/json'); t.is(createOrUpdatePermissionResponse.status, 200); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTablesInConnection = await request(app.getHttpServer()) .get(`/table/rows/${testData.connections.firstId}?tableName=${fakeTableName}`) .set('Cookie', testData.users.simpleUserToken) @@ -1938,7 +1933,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ .set('Accept', 'application/json'); t.is(createOrUpdatePermissionResponse.status, 200); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const getTablesStructure = await request(app.getHttpServer()) .get(`/table/structure/${fakeConnectionId}?tableName=users`) .set('Cookie', testData.users.simpleUserToken) @@ -2059,7 +2054,7 @@ test(`${currentTest} should throw an exception when table name passed in request .set('Accept', 'application/json'); t.is(createOrUpdatePermissionResponse.status, 200); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTablesStructure = await request(app.getHttpServer()) .get(`/table/structure/${testData.connections.firstId}?tableName=${fakeTableName}`) .set('Cookie', testData.users.simpleUserToken) @@ -2206,7 +2201,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const created_at = new Date(); const updated_at = new Date(); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const addRowInTable = await request(app.getHttpServer()) .post(`/table/row/${fakeConnectionId}?tableName=${testData.firstTableInfo.testTableName}`) .send({ @@ -2277,7 +2272,7 @@ test(`${currentTest} should throw an exception when table name passed in request const created_at = new Date(); const updated_at = new Date(); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTable = await request(app.getHttpServer()) .post(`/table/row/${testData.connections.firstId}?tableName=${fakeTableName}`) .send({ @@ -2430,7 +2425,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const created_at = new Date(); const updated_at = new Date(); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const addRowInTable = await request(app.getHttpServer()) .put(`/table/row/${fakeConnectionId}?tableName=${testData.firstTableInfo.testTableName}&id=1`) .send({ @@ -2501,7 +2496,7 @@ test(`${currentTest} should throw an exception when table name passed in request const created_at = new Date(); const updated_at = new Date(); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTable = await request(app.getHttpServer()) .put(`/table/row/${testData.connections.firstId}?tableName=${fakeTableName}&id=1`) .send({ @@ -2627,7 +2622,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ .set('Accept', 'application/json'); t.is(createOrUpdatePermissionResponse.status, 200); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const deleteRowInTable = await request(app.getHttpServer()) .delete(`/table/row/${fakeConnectionId}?tableName=${testData.firstTableInfo.testTableName}&id=1`) .set('Cookie', testData.users.simpleUserToken) @@ -2687,7 +2682,7 @@ test(`${currentTest} should throw an exception when table name passed in request .set('Content-Type', 'application/json') .set('Accept', 'application/json'); t.is(createOrUpdatePermissionResponse.status, 200); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTable = await request(app.getHttpServer()) .delete(`/table/row/${testData.connections.firstId}?tableName=${fakeTableName}&id=1`) .set('Cookie', testData.users.simpleUserToken) @@ -2816,7 +2811,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ .set('Accept', 'application/json'); t.is(createOrUpdatePermissionResponse.status, 200); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const addRowInTable = await request(app.getHttpServer()) .get(`/table/row/${fakeConnectionId}?tableName=${testData.firstTableInfo.testTableName}&id=5`) .set('Cookie', testData.users.simpleUserToken) @@ -2877,7 +2872,7 @@ test(`${currentTest} should throw an exception when table name passed in request .set('Accept', 'application/json'); t.is(createOrUpdatePermissionResponse.status, 200); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTable = await request(app.getHttpServer()) .get(`/table/row/${testData.connections.firstId}?tableName=${fakeTableName}&id=5`) .set('Cookie', testData.users.simpleUserToken) diff --git a/backend/test/ava-tests/user-group-edit-permissions-e2e.test.ts b/backend/test/ava-tests/user-group-edit-permissions-e2e.test.ts index 63a7e2c1..1dce3889 100644 --- a/backend/test/ava-tests/user-group-edit-permissions-e2e.test.ts +++ b/backend/test/ava-tests/user-group-edit-permissions-e2e.test.ts @@ -1,3 +1,5 @@ +/* eslint-disable security/detect-object-injection */ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { faker } from '@faker-js/faker'; import { INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; @@ -16,6 +18,7 @@ import { MockFactory } from '../mock.factory.js'; import { compareTableWidgetsArrays } from '../utils/compare-table-widgets-arrays.js'; import { TestUtils } from '../utils/test.utils.js'; import { createConnectionsAndInviteNewUserInNewGroupWithGroupPermissions } from '../utils/user-with-different-permissions-utils.js'; +import { inviteUserInCompanyAndAcceptInvitation } from '../utils/register-user-and-return-user-info.js'; let app: INestApplication; let testUtils: TestUtils; @@ -83,23 +86,23 @@ test(`${currentTest} should return connections, where second user have access`, t.is(findAll.status, 200); const result = findAll.body.connections; - t.is(result.length, 5); + t.is(result.length, 1); t.is(result[0].hasOwnProperty('connection'), true); - t.is(result[1].hasOwnProperty('accessLevel'), true); + t.is(result[0].hasOwnProperty('accessLevel'), true); t.is(uuidRegex.test(result[0].connection.id), true); - t.is(result[3].hasOwnProperty('accessLevel'), true); - t.is(result[4].connection.hasOwnProperty('host'), true); - t.is(result[3].connection.hasOwnProperty('host'), true); + t.is(result[0].hasOwnProperty('accessLevel'), true); + t.is(result[0].connection.hasOwnProperty('host'), true); + t.is(result[0].connection.hasOwnProperty('host'), true); t.is(typeof result[0].connection.port, 'number'); - t.is(result[1].connection.hasOwnProperty('port'), true); - t.is(result[2].connection.hasOwnProperty('username'), true); - t.is(result[3].connection.hasOwnProperty('database'), true); - t.is(result[4].connection.hasOwnProperty('sid'), true); + t.is(result[0].connection.hasOwnProperty('port'), true); + t.is(result[0].connection.hasOwnProperty('username'), true); + t.is(result[0].connection.hasOwnProperty('database'), true); + t.is(result[0].connection.hasOwnProperty('sid'), true); t.is(result[0].connection.hasOwnProperty('createdAt'), true); - t.is(result[1].connection.hasOwnProperty('updatedAt'), true); - t.is(result[2].connection.hasOwnProperty('password'), false); - t.is(result[3].connection.hasOwnProperty('groups'), false); - t.is(result[4].connection.hasOwnProperty('author'), false); + t.is(result[0].connection.hasOwnProperty('updatedAt'), true); + t.is(result[0].connection.hasOwnProperty('password'), false); + t.is(result[0].connection.hasOwnProperty('groups'), false); + t.is(result[0].connection.hasOwnProperty('author'), false); } catch (e) { console.error(e); } @@ -713,13 +716,13 @@ test(`${currentTest} should return found groups with current user`, async (t) => t.is(getGroupsResponse.status, 200); const getGroupsRO = JSON.parse(getGroupsResponse.text); const { groups, groupsCount } = getGroupsRO; - t.is(groupsCount, 5); - t.is(groups.length, 5); + t.is(groupsCount, 1); + t.is(groups.length, 1); t.is(groups[0].hasOwnProperty('group'), true); - t.is(groups[1].hasOwnProperty('accessLevel'), true); + t.is(groups[0].hasOwnProperty('accessLevel'), true); t.is(uuidRegex.test(groups[0].group.id), true); - t.is(groups[2].group.hasOwnProperty('title'), true); - t.is(groups[3].group.hasOwnProperty('isMain'), true); + t.is(groups[0].group.hasOwnProperty('title'), true); + t.is(groups[0].group.hasOwnProperty('isMain'), true); } catch (e) { console.error(e); } @@ -937,7 +940,7 @@ test(`${currentTest} should throw exception, when group id passed in request is const getGroupsRO = JSON.parse(getGroupsResponse.text); const email = faker.internet.email(); - const groupId = faker.datatype.uuid(); + const groupId = faker.string.uuid(); const addUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user') .set('Cookie', simpleUserToken) @@ -1072,7 +1075,7 @@ test(`${currentTest} should throw an exception when group id passed in request i t.is(getGroupsResponse.status, 200); - const groupId = faker.datatype.uuid(); + const groupId = faker.string.uuid(); const deleteGroupResponse = await request(app.getHttpServer()) .delete(`/group/${groupId}`) .set('Cookie', simpleUserToken) @@ -1109,14 +1112,17 @@ test(`${currentTest} should return group without deleted user`, async (t) => { const groupId = getGroupsRO[0].group.id; - const email = faker.internet.email(); + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(adminUserToken, undefined, app); + + const email = thirdTestUser.email; + const addUserInGroupResponse = await request(app.getHttpServer()) - .put('/group/user') - .set('Cookie', simpleUserToken) - .send({ groupId, email }) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - t.is(addUserInGroupResponse.status, 200); + .put('/group/user') + .set('Cookie', testData.users.simpleUserToken) + .send({ groupId, email }) + .set('Content-Type', 'application/json') + .set('Accept', 'application/json'); + t.is(addUserInGroupResponse.status, 200); const deleteUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user/delete') @@ -1159,14 +1165,9 @@ test(`${currentTest} should throw exception, when user email not passed in reque const groupId = getGroupsRO[0].group.id; - const email = faker.internet.email(); - const addUserInGroupResponse = await request(app.getHttpServer()) - .put('/group/user') - .set('Cookie', simpleUserToken) - .send({ groupId, email }) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - t.is(addUserInGroupResponse.status, 200); + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(adminUserToken, undefined, app); + + const email = thirdTestUser.email; const deleteUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user/delete') @@ -1203,14 +1204,9 @@ test(`${currentTest} should throw exception, when group id not passed in request const groupId = getGroupsRO[0].group.id; - const email = faker.internet.email(); - const addUserInGroupResponse = await request(app.getHttpServer()) - .put('/group/user') - .set('Cookie', simpleUserToken) - .send({ groupId, email }) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - t.is(addUserInGroupResponse.status, 200); + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(adminUserToken, undefined, app); + + const email = thirdTestUser.email; const deleteUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user/delete') @@ -1247,16 +1243,11 @@ test(`${currentTest} should throw exception, when group id passed in request is let groupId = getGroupsRO[0].group.id; - const email = faker.internet.email(); - const addUserInGroupResponse = await request(app.getHttpServer()) - .put('/group/user') - .set('Cookie', simpleUserToken) - .send({ groupId, email }) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - t.is(addUserInGroupResponse.status, 200); + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(adminUserToken, undefined, app); + + const email = thirdTestUser.email; - groupId = faker.datatype.uuid(); + groupId = faker.string.uuid(); const deleteUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user/delete') .set('Cookie', simpleUserToken) @@ -1513,7 +1504,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const getTablesInConnection = await request(app.getHttpServer()) .get(`/connection/tables/${fakeConnectionId}`) .set('Cookie', simpleUserToken) @@ -1593,7 +1584,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeId = faker.datatype.uuid(); + const fakeId = faker.string.uuid(); const getTableRows = await request(app.getHttpServer()) .get(`/table/rows/${fakeId}?tableName=${testData.firstTableInfo.testTableName}`) .set('Cookie', simpleUserToken) @@ -1618,7 +1609,7 @@ test(`${currentTest} should throw an exception when table name passed in request secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTablesRows = await request(app.getHttpServer()) .get(`/table/rows/${connections.firstId}?tableName=${fakeTableName}`) .set('Cookie', simpleUserToken) @@ -1702,7 +1693,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ users: { adminUserToken, simpleUserToken }, } = testData; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const getTablesStructure = await request(app.getHttpServer()) .get(`/table/structure/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}`) .set('Cookie', simpleUserToken) @@ -1826,7 +1817,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const randomEmail = faker.internet.email(); const created_at = new Date(); const updated_at = new Date(); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const addRowInTable = await request(app.getHttpServer()) .post(`/table/row/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}`) .send({ @@ -1931,7 +1922,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const randomEmail = faker.internet.email(); const created_at = new Date(); const updated_at = new Date(); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const addRowInTable = await request(app.getHttpServer()) .put(`/table/row/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}&id=1`) .send({ @@ -1965,7 +1956,7 @@ test(`${currentTest} should throw an exception when table name passed in request const randomEmail = faker.internet.email(); const created_at = new Date(); const updated_at = new Date(); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTable = await request(app.getHttpServer()) .put(`/table/row/${connections.firstId}?tableName=${fakeTableName}&id=1`) .send({ @@ -2020,7 +2011,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const deleteRowInTable = await request(app.getHttpServer()) .delete(`/table/row/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}&id=1`) .set('Cookie', simpleUserToken) @@ -2045,7 +2036,7 @@ test(`${currentTest} should throw an exception when table name passed in request secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTable = await request(app.getHttpServer()) .delete(`/table/row/${connections.firstId}?tableName=${fakeTableName}&id=1`) .set('Cookie', simpleUserToken) @@ -2101,7 +2092,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const addRowInTable = await request(app.getHttpServer()) .get(`/table/row/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}&id=5`) .set('Cookie', simpleUserToken) @@ -2125,7 +2116,7 @@ test(`${currentTest} should throw an exception when table name passed in request secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTable = await request(app.getHttpServer()) .get(`/table/row/${connections.firstId}?tableName=${fakeTableName}&id=5`) .set('Cookie', simpleUserToken) diff --git a/backend/test/ava-tests/user-table-different-group-connection-readonly-permissions-e2e.test.ts b/backend/test/ava-tests/user-table-different-group-connection-readonly-permissions-e2e.test.ts index 6af967d2..29cf0e94 100644 --- a/backend/test/ava-tests/user-table-different-group-connection-readonly-permissions-e2e.test.ts +++ b/backend/test/ava-tests/user-table-different-group-connection-readonly-permissions-e2e.test.ts @@ -1,3 +1,5 @@ +/* eslint-disable security/detect-object-injection */ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { faker } from '@faker-js/faker'; import { INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; @@ -16,6 +18,7 @@ import { MockFactory } from '../mock.factory.js'; import { compareTableWidgetsArrays } from '../utils/compare-table-widgets-arrays.js'; import { TestUtils } from '../utils/test.utils.js'; import { createConnectionsAndInviteNewUserInNewGroupWithTableDifferentConnectionGroupReadOnlyPermissions } from '../utils/user-with-different-permissions-utils.js'; +import { inviteUserInCompanyAndAcceptInvitation } from '../utils/register-user-and-return-user-info.js'; let app: INestApplication; let testUtils: TestUtils; @@ -87,23 +90,23 @@ test(`${currentTest} should return connections, where second user have access`, const result = findAll.body.connections; const nonTestConnection = result.find(({ connection }) => connection.id === connections.firstId); - t.is(result.length, 5); + t.is(result.length, 1); t.is(nonTestConnection.hasOwnProperty('connection'), true); t.is(nonTestConnection.hasOwnProperty('accessLevel'), true); t.is(nonTestConnection.accessLevel, AccessLevelEnum.readonly); t.is(uuidRegex.test(nonTestConnection.connection.id), true); t.is(nonTestConnection.connection.hasOwnProperty('host'), true); - t.is(result[3].connection.hasOwnProperty('host'), true); + t.is(result[0].connection.hasOwnProperty('host'), true); t.is(typeof result[0].connection.port, 'number'); - t.is(result[1].connection.hasOwnProperty('port'), true); - t.is(result[2].connection.hasOwnProperty('username'), true); - t.is(result[3].connection.hasOwnProperty('database'), true); - t.is(result[4].connection.hasOwnProperty('sid'), true); + t.is(result[0].connection.hasOwnProperty('port'), true); + t.is(result[0].connection.hasOwnProperty('username'), true); + t.is(result[0].connection.hasOwnProperty('database'), true); + t.is(result[0].connection.hasOwnProperty('sid'), true); t.is(result[0].connection.hasOwnProperty('createdAt'), true); - t.is(result[1].connection.hasOwnProperty('updatedAt'), true); - t.is(result[2].connection.hasOwnProperty('password'), false); - t.is(result[3].connection.hasOwnProperty('groups'), false); - t.is(result[4].connection.hasOwnProperty('author'), false); + t.is(result[0].connection.hasOwnProperty('updatedAt'), true); + t.is(result[0].connection.hasOwnProperty('password'), false); + t.is(result[0].connection.hasOwnProperty('groups'), false); + t.is(result[0].connection.hasOwnProperty('author'), false); } catch (e) { console.error(e); throw e; @@ -737,13 +740,13 @@ test(`${currentTest} should return found groups with current user`, async (t) => t.is(getGroupsResponse.status, 200); const getGroupsRO = JSON.parse(getGroupsResponse.text); const { groups, groupsCount } = getGroupsRO; - t.is(groupsCount, 5); - t.is(groups.length, 5); + t.is(groupsCount, 1); + t.is(groups.length, 1); t.is(groups[0].hasOwnProperty('group'), true); - t.is(groups[1].hasOwnProperty('accessLevel'), true); + t.is(groups[0].hasOwnProperty('accessLevel'), true); t.is(uuidRegex.test(groups[0].group.id), true); - t.is(groups[2].group.hasOwnProperty('title'), true); - t.is(groups[3].group.hasOwnProperty('isMain'), true); + t.is(groups[0].group.hasOwnProperty('title'), true); + t.is(groups[0].group.hasOwnProperty('isMain'), true); } catch (e) { console.error(e); throw e; @@ -926,7 +929,7 @@ test(`${currentTest} should throw exception, when group id passed in request is const getGroupsRO = JSON.parse(getGroupsResponse.text); const email = faker.internet.email(); - const groupId = faker.datatype.uuid(); + const groupId = faker.string.uuid(); const addUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user') .set('Cookie', simpleUserToken) @@ -1069,7 +1072,7 @@ test(`${currentTest} should throw an exception when group id passed in request i t.is(getGroupsResponse.status, 200); - const groupId = faker.datatype.uuid(); + const groupId = faker.string.uuid(); const deleteGroupResponse = await request(app.getHttpServer()) .delete(`/group/${groupId}`) .set('Cookie', simpleUserToken) @@ -1108,14 +1111,9 @@ test(`${currentTest} should throw an exception ${Messages.DONT_HAVE_PERMISSIONS} const groupId = getGroupsRO[0].group.id; - const email = faker.internet.email(); - const addUserInGroupResponse = await request(app.getHttpServer()) - .put('/group/user') - .set('Cookie', adminUserToken) - .send({ groupId, email }) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - t.is(addUserInGroupResponse.status, 200); + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(adminUserToken, undefined, app); + + const email = thirdTestUser.email; const deleteUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user/delete') @@ -1155,14 +1153,9 @@ test(`${currentTest} should throw exception, when group id not passed in request const groupId = getGroupsRO[0].group.id; - const email = faker.internet.email(); - const addUserInGroupResponse = await request(app.getHttpServer()) - .put('/group/user') - .set('Cookie', adminUserToken) - .send({ groupId, email }) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - t.is(addUserInGroupResponse.status, 200); + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(adminUserToken, undefined, app); + + const email = thirdTestUser.email; const deleteUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user/delete') @@ -1431,7 +1424,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const getTablesInConnection = await request(app.getHttpServer()) .get(`/connection/tables/${fakeConnectionId}`) .set('Cookie', simpleUserToken) @@ -1517,7 +1510,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeId = faker.datatype.uuid(); + const fakeId = faker.string.uuid(); const getTableRows = await request(app.getHttpServer()) .get(`/table/rows/${fakeId}?tableName=${testData.firstTableInfo.testTableName}`) .set('Cookie', simpleUserToken) @@ -1544,7 +1537,7 @@ test(`${currentTest} should throw an exception when table name passed in request secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTablesRows = await request(app.getHttpServer()) .get(`/table/rows/${connections.firstId}?tableName=${fakeTableName}`) .set('Cookie', simpleUserToken) @@ -1634,7 +1627,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ users: { adminUserToken, simpleUserToken }, } = testData; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const getTablesStructure = await request(app.getHttpServer()) .get(`/table/structure/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}`) .set('Cookie', simpleUserToken) @@ -1687,7 +1680,7 @@ test(`${currentTest} should throw an exception when table name passed in request secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTablesStructure = await request(app.getHttpServer()) .get(`/table/structure/${connections.firstId}?tableName=${fakeTableName}`) .set('Cookie', simpleUserToken) @@ -1766,7 +1759,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const randomEmail = faker.internet.email(); const created_at = new Date(); const updated_at = new Date(); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const addRowInTable = await request(app.getHttpServer()) .post(`/table/row/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}`) .send({ @@ -1802,7 +1795,7 @@ test(`${currentTest} should throw an exception when table name passed in request const randomEmail = faker.internet.email(); const created_at = new Date(); const updated_at = new Date(); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTable = await request(app.getHttpServer()) .post(`/table/row/${connections.firstId}?tableName=${fakeTableName}`) .send({ @@ -1877,7 +1870,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const randomEmail = faker.internet.email(); const created_at = new Date(); const updated_at = new Date(); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const addRowInTable = await request(app.getHttpServer()) .put(`/table/row/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}&id=1`) .send({ @@ -1913,7 +1906,7 @@ test(`${currentTest} should throw an exception when table name passed in request const randomEmail = faker.internet.email(); const created_at = new Date(); const updated_at = new Date(); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTable = await request(app.getHttpServer()) .put(`/table/row/${connections.firstId}?tableName=${fakeTableName}&id=1`) .send({ @@ -1972,7 +1965,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const deleteRowInTable = await request(app.getHttpServer()) .delete(`/table/row/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}&id=1`) .set('Cookie', simpleUserToken) @@ -1999,7 +1992,7 @@ test(`${currentTest} should throw an exception when table name passed in request secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTable = await request(app.getHttpServer()) .delete(`/table/row/${connections.firstId}?tableName=${fakeTableName}&id=1`) .set('Cookie', simpleUserToken) @@ -2059,7 +2052,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const addRowInTable = await request(app.getHttpServer()) .get(`/table/row/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}&id=5`) .set('Cookie', simpleUserToken) @@ -2085,7 +2078,7 @@ test(`${currentTest} should throw an exception when table name passed in request secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTable = await request(app.getHttpServer()) .get(`/table/row/${connections.firstId}?tableName=${fakeTableName}&id=5`) .set('Cookie', simpleUserToken) diff --git a/backend/test/ava-tests/user-with-table-only-permissions-e2e.test.ts b/backend/test/ava-tests/user-with-table-only-permissions-e2e.test.ts index b4205581..cdd45e4f 100644 --- a/backend/test/ava-tests/user-with-table-only-permissions-e2e.test.ts +++ b/backend/test/ava-tests/user-with-table-only-permissions-e2e.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable security/detect-object-injection */ import { faker } from '@faker-js/faker'; import { INestApplication } from '@nestjs/common'; @@ -17,6 +18,7 @@ import { MockFactory } from '../mock.factory.js'; import { compareTableWidgetsArrays } from '../utils/compare-table-widgets-arrays.js'; import { TestUtils } from '../utils/test.utils.js'; import { createConnectionsAndInviteNewUserInNewGroupWithOnlyTablePermissions } from '../utils/user-with-different-permissions-utils.js'; +import { inviteUserInCompanyAndAcceptInvitation } from '../utils/register-user-and-return-user-info.js'; let app: INestApplication; let testUtils: TestUtils; @@ -84,7 +86,7 @@ test(`${currentTest} should return connections, where second user have access`, t.is(findAll.status, 200); const result = findAll.body.connections; - t.is(result.length, 5); + t.is(result.length, 1); const nonTestConnection = result.find(({ connection }) => connection.id === connections.firstId); for (const key in nonTestConnection.connection) { t.is(Constants.CONNECTION_KEYS_NONE_PERMISSION.includes(key), true); @@ -696,13 +698,13 @@ test(`${currentTest} should return found groups with current user`, async (t) => t.is(getGroupsResponse.status, 200); const getGroupsRO = JSON.parse(getGroupsResponse.text); const { groups, groupsCount } = getGroupsRO; - t.is(groupsCount, 5); - t.is(groups.length, 5); + t.is(groupsCount, 1); + t.is(groups.length, 1); t.is(groups[0].hasOwnProperty('group'), true); - t.is(groups[1].hasOwnProperty('accessLevel'), true); + t.is(groups[0].hasOwnProperty('accessLevel'), true); t.is(uuidRegex.test(groups[0].group.id), true); - t.is(groups[2].group.hasOwnProperty('title'), true); - t.is(groups[3].group.hasOwnProperty('isMain'), true); + t.is(groups[0].group.hasOwnProperty('title'), true); + t.is(groups[0].group.hasOwnProperty('isMain'), true); } catch (e) { console.error(e); throw e; @@ -881,7 +883,7 @@ test(`${currentTest} should throw exception, when group id passed in request is const getGroupsRO = JSON.parse(getGroupsResponse.text); const email = faker.internet.email(); - const groupId = faker.datatype.uuid(); + const groupId = faker.string.uuid(); const addUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user') .set('Cookie', simpleUserToken) @@ -1020,7 +1022,7 @@ test(`${currentTest} should throw an exception when group id passed in request i t.is(getGroupsResponse.status, 200); - const groupId = faker.datatype.uuid(); + const groupId = faker.string.uuid(); const deleteGroupResponse = await request(app.getHttpServer()) .delete(`/group/${groupId}`) .set('Cookie', simpleUserToken) @@ -1058,14 +1060,9 @@ test(`${currentTest} should throw an exception ${Messages.DONT_HAVE_PERMISSIONS} const groupId = getGroupsRO[0].group.id; - const email = faker.internet.email(); - const addUserInGroupResponse = await request(app.getHttpServer()) - .put('/group/user') - .set('Cookie', adminUserToken) - .send({ groupId, email }) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - t.is(addUserInGroupResponse.status, 200); + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(adminUserToken, undefined, app); + + const email = thirdTestUser.email; const deleteUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user/delete') @@ -1102,16 +1099,9 @@ test(`${currentTest} should throw exception, when group id not passed in request t.is(getGroupsResponse.status, 200); const getGroupsRO = JSON.parse(getGroupsResponse.text); - const groupId = getGroupsRO[0].group.id; - - const email = faker.internet.email(); - const addUserInGroupResponse = await request(app.getHttpServer()) - .put('/group/user') - .set('Cookie', adminUserToken) - .send({ groupId, email }) - .set('Content-Type', 'application/json') - .set('Accept', 'application/json'); - t.is(addUserInGroupResponse.status, 200); + const thirdTestUser = await inviteUserInCompanyAndAcceptInvitation(adminUserToken, undefined, app); + + const email = thirdTestUser.email; const deleteUserInGroupResponse = await request(app.getHttpServer()) .put('/group/user/delete') @@ -1374,7 +1364,7 @@ test(`${currentTest} should throw an exception, when connection id passed in req secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const getTablesInConnection = await request(app.getHttpServer()) .get(`/connection/tables/${fakeConnectionId}`) .set('Cookie', simpleUserToken) @@ -1457,7 +1447,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeId = faker.datatype.uuid(); + const fakeId = faker.string.uuid(); const getTableRows = await request(app.getHttpServer()) .get(`/table/rows/${fakeId}?tableName=${testData.firstTableInfo.testTableName}`) .set('Cookie', simpleUserToken) @@ -1483,7 +1473,7 @@ test(`${currentTest} should throw an exception when table name passed in request secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTablesRows = await request(app.getHttpServer()) .get(`/table/rows/${connections.firstId}?tableName=${fakeTableName}`) .set('Cookie', simpleUserToken) @@ -1570,7 +1560,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ users: { adminUserToken, simpleUserToken }, } = testData; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const getTablesStructure = await request(app.getHttpServer()) .get(`/table/structure/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}`) .set('Cookie', simpleUserToken) @@ -1621,7 +1611,7 @@ test(`${currentTest} should throw an exception when table name passed in request secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const getTablesStructure = await request(app.getHttpServer()) .get(`/table/structure/${connections.firstId}?tableName=${fakeTableName}`) .set('Cookie', simpleUserToken) @@ -1698,7 +1688,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const randomEmail = faker.internet.email(); const created_at = new Date(); const updated_at = new Date(); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const addRowInTable = await request(app.getHttpServer()) .post(`/table/row/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}`) .send({ @@ -1733,7 +1723,7 @@ test(`${currentTest} should throw an exception when table name passed in request const randomEmail = faker.internet.email(); const created_at = new Date(); const updated_at = new Date(); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTable = await request(app.getHttpServer()) .post(`/table/row/${connections.firstId}?tableName=${fakeTableName}`) .send({ @@ -1806,7 +1796,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ const randomEmail = faker.internet.email(); const created_at = new Date(); const updated_at = new Date(); - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const addRowInTable = await request(app.getHttpServer()) .put(`/table/row/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}&id=1`) .send({ @@ -1841,7 +1831,7 @@ test(`${currentTest} should throw an exception when table name passed in request const randomEmail = faker.internet.email(); const created_at = new Date(); const updated_at = new Date(); - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTable = await request(app.getHttpServer()) .put(`/table/row/${connections.firstId}?tableName=${fakeTableName}&id=1`) .send({ @@ -1898,7 +1888,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const deleteRowInTable = await request(app.getHttpServer()) .delete(`/table/row/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}&id=1`) .set('Cookie', simpleUserToken) @@ -1924,7 +1914,7 @@ test(`${currentTest} should throw an exception when table name passed in request secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const deleteRowInTable = await request(app.getHttpServer()) .delete(`/table/row/${connections.firstId}?tableName=${fakeTableName}&id=1`) .set('Cookie', simpleUserToken) @@ -1982,7 +1972,7 @@ test(`${currentTest} should throw an exception when connection id passed in requ secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeConnectionId = faker.datatype.uuid(); + const fakeConnectionId = faker.string.uuid(); const addRowInTable = await request(app.getHttpServer()) .get(`/table/row/${fakeConnectionId}?tableName=${firstTableInfo.testTableName}&id=5`) .set('Cookie', simpleUserToken) @@ -2007,7 +1997,7 @@ test(`${currentTest} should throw an exception when table name passed in request secondTableInfo, users: { adminUserToken, simpleUserToken }, } = testData; - const fakeTableName = `${faker.lorem.words(1)}_${faker.datatype.uuid()}`; + const fakeTableName = `${faker.lorem.words(1)}_${faker.string.uuid()}`; const addRowInTable = await request(app.getHttpServer()) .get(`/table/row/${connections.firstId}?tableName=${fakeTableName}&id=5`) .set('Cookie', simpleUserToken) diff --git a/backend/test/utils/register-user-and-return-user-info.ts b/backend/test/utils/register-user-and-return-user-info.ts index c4b9e8ba..5eeef757 100644 --- a/backend/test/utils/register-user-and-return-user-info.ts +++ b/backend/test/utils/register-user-and-return-user-info.ts @@ -4,6 +4,7 @@ import request from 'supertest'; import { Constants } from '../../src/helpers/constants/constants.js'; import { TestUtils } from './test.utils.js'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars export async function registerUserAndReturnUserInfo(app: INestApplication): Promise<{ token: string; email: string; @@ -67,3 +68,60 @@ type RegisterUserData = { email: string; password: string; }; + +export async function inviteUserInCompanyAndAcceptInvitation( + inviterJwtToken: string, + role: 'ADMIN' | 'USER' = 'USER', + app: INestApplication, +): Promise<{ + email: string; + password: string; + token: string; +}> { + const foundUser: any = await request(app.getHttpServer()) + .get('/user/') + .set('Cookie', inviterJwtToken) + .set('Content-Type', 'application/json') + .set('Accept', 'application/json'); + const foundUserJson = JSON.parse(foundUser.text); + + const newEmail = `${faker.lorem.words(1)}_${faker.lorem.words(1)}_${faker.internet.email()}`; + const newPassword = `#r@dY^e&7R4b5Ib@31iE4xbn`; + const invitationRequestBody = { + companyId: foundUserJson.company.id, + userEmail: newEmail, + role: role, + }; + + const invitationResult = await fetch('http://rocketadmin-private-microservice:3001/company/user/', { + method: 'PUT', + body: JSON.stringify(invitationRequestBody), + headers: { + Cookie: inviterJwtToken, + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + }); + + if (invitationResult.status > 201) { + console.info('invitationResult.body -> ', await invitationResult.json()); + } + const verificationResult = await fetch('http://rocketadmin-private-microservice:3001/company/user/accept/test', { + method: 'POST', + body: JSON.stringify({ + email: newEmail, + password: newPassword, + }), + headers: { + Cookie: inviterJwtToken, + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + }); + if (verificationResult.status > 201) { + console.info('verificationResult.body -> ', await verificationResult.json()); + } + const token = `${Constants.JWT_COOKIE_KEY_NAME}=${TestUtils.getJwtTokenFromResponse2(verificationResult)}`; + + return { email: newEmail, password: newPassword, token: token }; +} diff --git a/backend/test/utils/user-with-different-permissions-utils.ts b/backend/test/utils/user-with-different-permissions-utils.ts index 6c941ad9..dc4e704e 100644 --- a/backend/test/utils/user-with-different-permissions-utils.ts +++ b/backend/test/utils/user-with-different-permissions-utils.ts @@ -3,7 +3,10 @@ import request from 'supertest'; import { AccessLevelEnum } from '../../src/enums/index.js'; import { MockFactory } from '../mock.factory.js'; import { CreatedTableInfo, createTestTable } from './create-test-table.js'; -import { registerUserAndReturnUserInfo } from './register-user-and-return-user-info.js'; +import { + inviteUserInCompanyAndAcceptInvitation, + registerUserAndReturnUserInfo, +} from './register-user-and-return-user-info.js'; export async function createConnectionsAndInviteNewUserInNewGroupInFirstConnection( app: INestApplication, @@ -15,7 +18,11 @@ export async function createConnectionsAndInviteNewUserInNewGroupInFirstConnecti }; const mockFactory = new MockFactory(); const connectionAdminUserInfo = await registerUserAndReturnUserInfo(app); - const simpleUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const simpleUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation( + connectionAdminUserInfo.token, + undefined, + app, + ); const connectionAdminUserToken = connectionAdminUserInfo.token; const simpleUserToken = simpleUserRegisterInfo.token; @@ -130,7 +137,11 @@ export async function createConnectionsAndInviteNewUserInNewGroupWithGroupPermis }; const mockFactory = new MockFactory(); const connectionAdminUserInfo = await registerUserAndReturnUserInfo(app); - const simpleUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const simpleUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation( + connectionAdminUserInfo.token, + undefined, + app, + ); const connectionAdminUserToken = connectionAdminUserInfo.token; const simpleUserToken = simpleUserRegisterInfo.token; @@ -255,7 +266,11 @@ export async function createConnectionsAndInviteNewUserInNewGroupWithOnlyTablePe }; const mockFactory = new MockFactory(); const connectionAdminUserInfo = await registerUserAndReturnUserInfo(app); - const simpleUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const simpleUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation( + connectionAdminUserInfo.token, + undefined, + app, + ); const connectionAdminUserToken = connectionAdminUserInfo.token; const simpleUserToken = simpleUserRegisterInfo.token; @@ -380,7 +395,11 @@ export async function createConnectionsAndInviteNewUserInNewGroupWithTableDiffer }; const mockFactory = new MockFactory(); const connectionAdminUserInfo = await registerUserAndReturnUserInfo(app); - const simpleUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const simpleUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation( + connectionAdminUserInfo.token, + undefined, + app, + ); const connectionAdminUserToken = connectionAdminUserInfo.token; const simpleUserToken = simpleUserRegisterInfo.token; @@ -505,7 +524,11 @@ export async function createConnectionsAndInviteNewUserInAdminGroupOfFirstConnec }; const mockFactory = new MockFactory(); const connectionAdminUserInfo = await registerUserAndReturnUserInfo(app); - const simpleUserRegisterInfo = await registerUserAndReturnUserInfo(app); + const simpleUserRegisterInfo = await inviteUserInCompanyAndAcceptInvitation( + connectionAdminUserInfo.token, + undefined, + app, + ); const connectionAdminUserToken = connectionAdminUserInfo.token; const simpleUserToken = simpleUserRegisterInfo.token; diff --git a/rocketadmin-agent/test/command/command-executor-mssql.spec.ts b/rocketadmin-agent/test/command/command-executor-mssql.spec.ts index 2a842edb..95d451c5 100644 --- a/rocketadmin-agent/test/command/command-executor-mssql.spec.ts +++ b/rocketadmin-agent/test/command/command-executor-mssql.spec.ts @@ -626,7 +626,7 @@ describe('Command executor tests', () => { const commandExecutor = new CommandExecutor(connectionConfig); const settings = { - connection_id: faker.datatype.uuid(), + connection_id: faker.string.uuid();, table_name: testTableName, display_name: '', search_fields: [testTableColumnName], @@ -670,7 +670,7 @@ describe('Command executor tests', () => { const commandExecutor = new CommandExecutor(connectionConfig); const settings = { - connection_id: faker.datatype.uuid(), + connection_id: faker.string.uuid();, table_name: testTableName, display_name: '', search_fields: [faker.lorem.words(1)], diff --git a/rocketadmin-agent/test/command/command-executor-mysql.spec.ts b/rocketadmin-agent/test/command/command-executor-mysql.spec.ts index 969933cd..eeb16a92 100644 --- a/rocketadmin-agent/test/command/command-executor-mysql.spec.ts +++ b/rocketadmin-agent/test/command/command-executor-mysql.spec.ts @@ -627,7 +627,7 @@ describe('Command executor tests', () => { const commandExecutor = new CommandExecutor(connectionConfig); const settings = { - connection_id: faker.datatype.uuid(), + connection_id: faker.string.uuid();, table_name: testTableName, display_name: '', search_fields: [testTableColumnName], @@ -671,7 +671,7 @@ describe('Command executor tests', () => { const commandExecutor = new CommandExecutor(connectionConfig); const settings = { - connection_id: faker.datatype.uuid(), + connection_id: faker.string.uuid();, table_name: testTableName, display_name: '', search_fields: [faker.lorem.words(1)], diff --git a/rocketadmin-agent/test/command/command-executor-orecle.spec.ts b/rocketadmin-agent/test/command/command-executor-orecle.spec.ts index f58f3b35..3ee52cea 100644 --- a/rocketadmin-agent/test/command/command-executor-orecle.spec.ts +++ b/rocketadmin-agent/test/command/command-executor-orecle.spec.ts @@ -630,7 +630,7 @@ describe('Command executor tests', () => { const commandExecutor = new CommandExecutor(connectionConfig); const settings = { - connection_id: faker.datatype.uuid(), + connection_id: faker.string.uuid();, table_name: testTableName, display_name: '', search_fields: [testTableColumnName], @@ -674,7 +674,7 @@ describe('Command executor tests', () => { const commandExecutor = new CommandExecutor(connectionConfig); const settings = { - connection_id: faker.datatype.uuid(), + connection_id: faker.string.uuid();, table_name: testTableName, display_name: '', search_fields: [faker.lorem.words(1)], diff --git a/rocketadmin-agent/test/command/command-executor-postgres.spec.ts b/rocketadmin-agent/test/command/command-executor-postgres.spec.ts index 3af12d08..335ec85a 100644 --- a/rocketadmin-agent/test/command/command-executor-postgres.spec.ts +++ b/rocketadmin-agent/test/command/command-executor-postgres.spec.ts @@ -627,7 +627,7 @@ describe('Command executor tests', () => { const commandExecutor = new CommandExecutor(connectionConfig); const settings = { - connection_id: faker.datatype.uuid(), + connection_id: faker.string.uuid();, table_name: testTableName, display_name: '', search_fields: [testTableColumnName], @@ -671,7 +671,7 @@ describe('Command executor tests', () => { const commandExecutor = new CommandExecutor(connectionConfig); const settings = { - connection_id: faker.datatype.uuid(), + connection_id: faker.string.uuid();, table_name: testTableName, display_name: '', search_fields: [faker.lorem.words(1)],