Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change types for constants on communication module #1440

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { DeepMocked, createMock } from '@golevelup/ts-jest';
import faker from '@faker-js/faker';
import { BoardFactory } from 'src/libs/test-utils/mocks/factories/board-factory.mock';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import * as CommunicationsType from 'src/modules/communication/interfaces/types';
import MergeBoardUseCaseDto from '../dto/useCase/merge-board.use-case.dto';
import Board from '../entities/board.schema';
import { CommunicationServiceInterface } from 'src/modules/communication/interfaces/slack-communication.service.interface';
Expand All @@ -14,6 +13,7 @@ import { generateNewSubColumns } from '../utils/generate-subcolumns';
import { mergeCardsFromSubBoardColumnsIntoMainBoard } from '../utils/merge-cards-from-subboard';
import { MergeBoardUseCase } from './merge-board.use-case';
import { BOARD_REPOSITORY } from 'src/modules/boards/constants';
import { SLACK_COMMUNICATION_SERVICE } from 'src/modules/communication/constants';

const userId = faker.datatype.uuid();
const subBoards = BoardFactory.createMany(2, [
Expand Down Expand Up @@ -64,17 +64,15 @@ describe('MergeBoardUseCase', () => {
useValue: createMock<BoardRepositoryInterface>()
},
{
provide: CommunicationsType.TYPES.services.SlackCommunicationService,
provide: SLACK_COMMUNICATION_SERVICE,
useValue: createMock<CommunicationServiceInterface>()
}
]
}).compile();

useCase = module.get(MergeBoardUseCase);
boardRepositoryMock = module.get(BOARD_REPOSITORY);
slackCommunicationServiceMock = module.get(
CommunicationsType.TYPES.services.SlackCommunicationService
);
slackCommunicationServiceMock = module.get(SLACK_COMMUNICATION_SERVICE);
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { BoardNotFoundException } from 'src/libs/exceptions/boardNotFoundExcepti
import { UpdateFailedException } from 'src/libs/exceptions/updateFailedBadRequestException';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { CommunicationServiceInterface } from 'src/modules/communication/interfaces/slack-communication.service.interface';
import * as CommunicationsType from 'src/modules/communication/interfaces/types';
import MergeBoardUseCaseDto from '../dto/useCase/merge-board.use-case.dto';
import Board from '../entities/board.schema';
import { BOARD_REPOSITORY } from '../constants';
import { BoardRepositoryInterface } from '../repositories/board.repository.interface';
import { generateNewSubColumns } from '../utils/generate-subcolumns';
import { mergeCardsFromSubBoardColumnsIntoMainBoard } from '../utils/merge-cards-from-subboard';
import { SLACK_COMMUNICATION_SERVICE } from 'src/modules/communication/constants';

@Injectable()
export class MergeBoardUseCase implements UseCase<MergeBoardUseCaseDto, Board> {
Expand All @@ -18,7 +18,7 @@ export class MergeBoardUseCase implements UseCase<MergeBoardUseCaseDto, Board> {
constructor(
@Inject(BOARD_REPOSITORY)
private readonly boardRepository: BoardRepositoryInterface,
@Inject(CommunicationsType.TYPES.services.SlackCommunicationService)
@Inject(SLACK_COMMUNICATION_SERVICE)
private readonly slackCommunicationService: CommunicationServiceInterface
) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { BoardFactory } from 'src/libs/test-utils/mocks/factories/board-factory.mock';
import { TeamFactory } from 'src/libs/test-utils/mocks/factories/team-factory.mock';
import { SendMessageServiceInterface } from 'src/modules/communication/interfaces/send-message.service.interface';
import * as CommunicationsType from 'src/modules/communication/interfaces/types';
import { BoardRepositoryInterface } from '../repositories/board.repository.interface';
import { UpdateBoardPhaseUseCase } from './update-board-phase.use-case';
import { BOARD_REPOSITORY } from 'src/modules/boards/constants';
import { SLACK_SEND_MESSAGE_SERVICE } from 'src/modules/communication/constants';

describe('UpdateBoardPhaseUseCase', () => {
let useCase: UseCase<BoardPhaseDto, void>;
Expand All @@ -28,7 +28,7 @@ describe('UpdateBoardPhaseUseCase', () => {
providers: [
UpdateBoardPhaseUseCase,
{
provide: CommunicationsType.TYPES.services.SlackSendMessageService,
provide: SLACK_SEND_MESSAGE_SERVICE,
useValue: createMock<SendMessageServiceInterface>()
},
{
Expand All @@ -50,9 +50,7 @@ describe('UpdateBoardPhaseUseCase', () => {
boardRepositoryMock = module.get(BOARD_REPOSITORY);
eventEmitterMock = module.get(EventEmitter2);
configServiceMock = module.get(ConfigService);
slackSendMessageServiceMock = module.get(
CommunicationsType.TYPES.services.SlackSendMessageService
);
slackSendMessageServiceMock = module.get(SLACK_SEND_MESSAGE_SERVICE);
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import { UpdateFailedException } from 'src/libs/exceptions/updateFailedBadReques
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { SlackMessageDto } from 'src/modules/communication/dto/slack.message.dto';
import { SendMessageServiceInterface } from 'src/modules/communication/interfaces/send-message.service.interface';
import * as CommunicationsType from 'src/modules/communication/interfaces/types';
import PhaseChangeEvent from 'src/modules/socket/events/user-updated-phase.event';
import { BOARD_REPOSITORY } from '../constants';
import { BoardRepositoryInterface } from '../repositories/board.repository.interface';
import { SLACK_SEND_MESSAGE_SERVICE } from 'src/modules/communication/constants';

@Injectable()
export class UpdateBoardPhaseUseCase implements UseCase<BoardPhaseDto, void> {
constructor(
@Inject(BOARD_REPOSITORY)
private readonly boardRepository: BoardRepositoryInterface,
@Inject(CommunicationsType.TYPES.services.SlackSendMessageService)
@Inject(SLACK_SEND_MESSAGE_SERVICE)
private readonly slackSendMessageService: SendMessageServiceInterface,
private readonly eventEmitter: EventEmitter2,
private readonly configService: ConfigService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Test, TestingModule } from '@nestjs/testing';
import * as CommunicationsType from 'src/modules/communication/interfaces/types';
import { BoardRepositoryInterface } from '../repositories/board.repository.interface';
import { CommunicationServiceInterface } from 'src/modules/communication/interfaces/slack-communication.service.interface';
import { BoardFactory } from 'src/libs/test-utils/mocks/factories/board-factory.mock';
Expand Down Expand Up @@ -30,6 +29,7 @@ import {
UPDATE_BOARD_USER_SERVICE
} from 'src/modules/boardUsers/constants';
import { DELETE_VOTE_SERVICE } from 'src/modules/votes/constants';
import { SLACK_COMMUNICATION_SERVICE } from 'src/modules/communication/constants';

const regularBoard = BoardFactory.create({ isSubBoard: false, dividedBoards: [] });
const userId = faker.datatype.uuid();
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('UpdateBoardUseCase', () => {
providers: [
UpdateBoardUseCase,
{
provide: CommunicationsType.TYPES.services.SlackCommunicationService,
provide: SLACK_COMMUNICATION_SERVICE,
useValue: createMock<CommunicationServiceInterface>()
},
{
Expand All @@ -133,9 +133,7 @@ describe('UpdateBoardUseCase', () => {
updateBoardUserServiceMock = module.get(UPDATE_BOARD_USER_SERVICE);
getBoardUserServiceMock = module.get(GET_BOARD_USER_SERVICE);
deleteVoteServiceMock = module.get(DELETE_VOTE_SERVICE);
slackCommunicationServiceMock = module.get(
CommunicationsType.TYPES.services.SlackCommunicationService
);
slackCommunicationServiceMock = module.get(SLACK_COMMUNICATION_SERVICE);
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { UpdateBoardUserServiceInterface } from 'src/modules/boardUsers/interfac
import ColumnDto from 'src/modules/columns/dto/column.dto';
import Column from 'src/modules/columns/entities/column.schema';
import { CommunicationServiceInterface } from 'src/modules/communication/interfaces/slack-communication.service.interface';
import * as CommunicationsType from 'src/modules/communication/interfaces/types';
import User from 'src/modules/users/entities/user.schema';
import { DeleteVoteServiceInterface } from 'src/modules/votes/interfaces/services/delete.vote.service.interface';
import { UpdateBoardDto } from '../dto/update-board.dto';
Expand All @@ -23,6 +22,7 @@ import {
UPDATE_BOARD_USER_SERVICE
} from 'src/modules/boardUsers/constants';
import { DELETE_VOTE_SERVICE } from 'src/modules/votes/constants';
import { SLACK_COMMUNICATION_SERVICE } from 'src/modules/communication/constants';

@Injectable()
export class UpdateBoardUseCase implements UseCase<UpdateBoardDto, Board> {
Expand All @@ -35,7 +35,7 @@ export class UpdateBoardUseCase implements UseCase<UpdateBoardDto, Board> {
private readonly updateBoardUserService: UpdateBoardUserServiceInterface,
@Inject(DELETE_VOTE_SERVICE)
private readonly deleteVoteService: DeleteVoteServiceInterface,
@Inject(CommunicationsType.TYPES.services.SlackCommunicationService)
@Inject(SLACK_COMMUNICATION_SERVICE)
private readonly slackCommunicationService: CommunicationServiceInterface
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Test, TestingModule } from '@nestjs/testing';
import * as CommunicationsType from 'src/modules/communication/interfaces/types';
import { BoardRepositoryInterface } from '../repositories/board.repository.interface';
import { CommunicationServiceInterface } from 'src/modules/communication/interfaces/slack-communication.service.interface';
import { DeepMocked, createMock } from '@golevelup/ts-jest';
Expand Down Expand Up @@ -33,6 +32,7 @@ import { GET_TEAM_USER_SERVICE, UPDATE_TEAM_USER_SERVICE } from 'src/modules/tea
import { BOARD_REPOSITORY } from 'src/modules/boards/constants';
import { CREATE_BOARD_USER_SERVICE } from 'src/modules/boardUsers/constants';
import { CREATE_SCHEDULES_SERVICE } from 'src/modules/schedules/constants';
import { SLACK_COMMUNICATION_SERVICE } from 'src/modules/communication/constants';

const userId: string = faker.datatype.uuid();

Expand Down Expand Up @@ -220,7 +220,7 @@ describe('CreateBoardService', () => {
useValue: createMock<CreateSchedulesServiceInterface>()
},
{
provide: CommunicationsType.TYPES.services.SlackCommunicationService,
provide: SLACK_COMMUNICATION_SERVICE,
useValue: createMock<CommunicationServiceInterface>()
},
{
Expand All @@ -241,9 +241,7 @@ describe('CreateBoardService', () => {
getTeamUserServiceMock = module.get(GET_TEAM_USER_SERVICE);
updateTeamUserServiceMock = module.get(UPDATE_TEAM_USER_SERVICE);
createSchedulesServiceMock = module.get(CREATE_SCHEDULES_SERVICE);
slackCommunicationServiceMock = module.get(
CommunicationsType.TYPES.services.SlackCommunicationService
);
slackCommunicationServiceMock = module.get(SLACK_COMMUNICATION_SERVICE);
});

beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/modules/boards/services/create.board.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { getDay, getNextMonth } from 'src/libs/utils/dates';
import { generateBoardDtoData, generateSubBoardDtoData } from 'src/libs/utils/generateBoardData';
import { CommunicationServiceInterface } from 'src/modules/communication/interfaces/slack-communication.service.interface';
import * as CommunicationsType from 'src/modules/communication/interfaces/types';
import { AddCronJobDto } from 'src/modules/schedules/dto/add.cronjob.dto';
import { CreateSchedulesServiceInterface } from 'src/modules/schedules/interfaces/services/create.schedules.service.interface';
import { GetTeamServiceInterface } from 'src/modules/teams/interfaces/services/get.team.service.interface';
Expand Down Expand Up @@ -38,6 +37,7 @@ import { GET_TEAM_USER_SERVICE, UPDATE_TEAM_USER_SERVICE } from 'src/modules/tea
import { BOARD_REPOSITORY } from 'src/modules/boards/constants';
import { CREATE_BOARD_USER_SERVICE } from 'src/modules/boardUsers/constants';
import { CREATE_SCHEDULES_SERVICE } from 'src/modules/schedules/constants';
import { SLACK_COMMUNICATION_SERVICE } from 'src/modules/communication/constants';

type CreateBoardAndUsers = {
boardData: BoardDto;
Expand All @@ -57,7 +57,7 @@ export default class CreateBoardService implements CreateBoardServiceInterface {
private readonly updateTeamUserService: UpdateTeamUserServiceInterface,
@Inject(CREATE_SCHEDULES_SERVICE)
private readonly createSchedulesService: CreateSchedulesServiceInterface,
@Inject(CommunicationsType.TYPES.services.SlackCommunicationService)
@Inject(SLACK_COMMUNICATION_SERVICE)
private readonly slackCommunicationService: CommunicationServiceInterface,
@Inject(BOARD_REPOSITORY)
private readonly boardRepository: BoardRepositoryInterface,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { faker } from '@faker-js/faker';
import { Test, TestingModule } from '@nestjs/testing';
import { DeleteBoardServiceInterface } from '../interfaces/services/delete.board.service.interface';
import * as CommunicationTypes from 'src/modules/communication/interfaces/types';
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { BoardRepositoryInterface } from '../repositories/board.repository.interface';
import { BadRequestException } from '@nestjs/common';
Expand All @@ -13,6 +12,7 @@ import { ArchiveChannelServiceInterface } from 'src/modules/communication/interf
import { BOARD_REPOSITORY } from 'src/modules/boards/constants';
import { DELETE_BOARD_USER_SERVICE } from 'src/modules/boardUsers/constants';
import { DELETE_SCHEDULES_SERVICE } from 'src/modules/schedules/constants';
import { SLACK_ARCHIVE_CHANNEL_SERVICE } from 'src/modules/communication/constants';

const boards = BoardFactory.createMany(2, [{ slackEnable: true }, { slackEnable: true }]);
const board = BoardFactory.create({
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('DeleteBoardService', () => {
useValue: createMock<DeleteSchedulesServiceInterface>()
},
{
provide: CommunicationTypes.TYPES.services.SlackArchiveChannelService,
provide: SLACK_ARCHIVE_CHANNEL_SERVICE,
useValue: createMock<ArchiveChannelServiceInterface>()
}
]
Expand All @@ -62,9 +62,7 @@ describe('DeleteBoardService', () => {
boardRepositoryMock = module.get(BOARD_REPOSITORY);
deleteBoardUserServiceMock = module.get(DELETE_BOARD_USER_SERVICE);
deleteSchedulesServiceMock = module.get(DELETE_SCHEDULES_SERVICE);
archiveChannelServiceMock = module.get(
CommunicationTypes.TYPES.services.SlackArchiveChannelService
);
archiveChannelServiceMock = module.get(SLACK_ARCHIVE_CHANNEL_SERVICE);
});

beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/modules/boards/services/delete.board.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { DELETE_FAILED } from 'src/libs/exceptions/messages';
import { DeleteSchedulesServiceInterface } from 'src/modules/schedules/interfaces/services/delete.schedules.service.interface';
import { DeleteBoardServiceInterface } from '../interfaces/services/delete.board.service.interface';
import Board from '../entities/board.schema';
import * as CommunicationTypes from 'src/modules/communication/interfaces/types';
import { ArchiveChannelServiceInterface } from 'src/modules/communication/interfaces/archive-channel.service.interface';
import { ArchiveChannelDataOptions } from 'src/modules/communication/dto/types';
import { BoardRepositoryInterface } from '../repositories/board.repository.interface';
import { BOARD_REPOSITORY } from 'src/modules/boards/constants';
import { DELETE_BOARD_USER_SERVICE } from 'src/modules/boardUsers/constants';
import { DELETE_SCHEDULES_SERVICE } from 'src/modules/schedules/constants';
import { SLACK_ARCHIVE_CHANNEL_SERVICE } from 'src/modules/communication/constants';

@Injectable()
export default class DeleteBoardService implements DeleteBoardServiceInterface {
Expand All @@ -21,7 +21,7 @@ export default class DeleteBoardService implements DeleteBoardServiceInterface {
private readonly deleteBoardUserService: DeleteBoardUserServiceInterface,
@Inject(DELETE_SCHEDULES_SERVICE)
private readonly deleteScheduleService: DeleteSchedulesServiceInterface,
@Inject(CommunicationTypes.TYPES.services.SlackArchiveChannelService)
@Inject(SLACK_ARCHIVE_CHANNEL_SERVICE)
private readonly archiveChannelService: ArchiveChannelServiceInterface
) {}

Expand Down
30 changes: 20 additions & 10 deletions backend/src/modules/communication/communication.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ import { ConversationsSlackHandler } from 'src/modules/communication/handlers/co
import { ChatHandlerInterface } from 'src/modules/communication/interfaces/chat.handler.interface';
import { CommunicationGateAdapterInterface } from 'src/modules/communication/interfaces/communication-gate.adapter.interface';
import { ConversationsHandlerInterface } from 'src/modules/communication/interfaces/conversations.handler.interface';
import { TYPES } from 'src/modules/communication/interfaces/types';
import {
SLACK_ADD_USER_INTO_CHANNEL_APPLICATION,
SLACK_ARCHIVE_CHANNEL_APPLICATION,
SLACK_ARCHIVE_CHANNEL_SERVICE,
SLACK_COMMUNICATION_APPLICATION,
SLACK_COMMUNICATION_SERVICE,
SLACK_MERGE_BOARD_APPLICATION,
SLACK_RESPONSIBLE_APPLICATION,
SLACK_SEND_MESSAGE_APPLICATION,
SLACK_SEND_MESSAGE_SERVICE
} from 'src/modules/communication/constants';
import { UsersHandlerInterface } from 'src/modules/communication/interfaces/users.handler.interface';
import { SlackArchiveChannelService } from 'src/modules/communication/services/slack-archive-channel.service';
import { SlackCommunicationService } from 'src/modules/communication/services/slack-communication.service';
Expand Down Expand Up @@ -64,7 +74,7 @@ export const ChatHandler = {
};

export const CommunicationApplication = {
provide: TYPES.application.SlackCommunicationApplication,
provide: SLACK_COMMUNICATION_APPLICATION,
useFactory: (
configService: ConfigService,
conversationsHandler: ConversationsHandlerInterface,
Expand All @@ -87,15 +97,15 @@ export const CommunicationApplication = {
};

export const SendMessageApplication = {
provide: TYPES.application.SlackSendMessageApplication,
provide: SLACK_SEND_MESSAGE_APPLICATION,
useFactory: (chatHandler: ChatHandlerInterface) => {
return new SlackSendMessageApplication(chatHandler);
},
inject: [ChatSlackHandler]
};

export const AddUserIntoChannelApplication = {
provide: TYPES.application.SlackAddUserIntoChannelApplication,
provide: SLACK_ADD_USER_INTO_CHANNEL_APPLICATION,
useFactory: (
configService: ConfigService,
conversationsHandler: ConversationsHandlerInterface,
Expand All @@ -116,15 +126,15 @@ export const AddUserIntoChannelApplication = {
};

export const ArchiveChannelApplication = {
provide: TYPES.application.SlackArchiveChannelApplication,
provide: SLACK_ARCHIVE_CHANNEL_APPLICATION,
useFactory: (conversationsHandler: ConversationsHandlerInterface) => {
return new SlackArchiveChannelApplication(conversationsHandler);
},
inject: [ConversationsSlackHandler]
};

export const ResponsibleApplication = {
provide: TYPES.application.SlackResponsibleApplication,
provide: SLACK_RESPONSIBLE_APPLICATION,
useFactory: (
usersHandler: UsersHandlerInterface,
chatHandler: ChatHandlerInterface,
Expand All @@ -136,29 +146,29 @@ export const ResponsibleApplication = {
};

export const MergeBoardApplication = {
provide: TYPES.application.SlackMergeBoardApplication,
provide: SLACK_MERGE_BOARD_APPLICATION,
useFactory: (configService: ConfigService, chatHandler: ChatHandlerInterface) => {
return new SlackMergeBoardApplication(chatHandler, configService.getOrThrow(FRONTEND_URL));
},
inject: [ConfigService, ChatSlackHandler]
};

export const CommunicationService = {
provide: TYPES.services.SlackCommunicationService,
provide: SLACK_COMMUNICATION_SERVICE,
useClass: configuration().slack.enable
? SlackCommunicationService
: SlackDisabledCommunicationService
};

export const ArchiveChannelService = {
provide: TYPES.services.SlackArchiveChannelService,
provide: SLACK_ARCHIVE_CHANNEL_SERVICE,
useClass: configuration().slack.enable
? SlackArchiveChannelService
: SlackDisabledCommunicationService
};

export const SendMessageService = {
provide: TYPES.services.SlackSendMessageService,
provide: SLACK_SEND_MESSAGE_SERVICE,
useClass: configuration().slack.enable
? SlackSendMessageService
: SlackDisabledCommunicationService
Expand Down
Loading