Skip to content

Commit

Permalink
refactor: change cards module types for constants (#1424)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatiaAntunes96 authored Apr 24, 2023
1 parent 4a7ac92 commit 86f68be
Show file tree
Hide file tree
Showing 25 changed files with 163 additions and 143 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing';
import { TYPES } from '../interfaces/types';
import { CARD_REPOSITORY } from '../constants';
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { CardRepositoryInterface } from '../repository/card.repository.interface';
import faker from '@faker-js/faker';
Expand All @@ -14,7 +14,7 @@ import User from 'src/modules/users/entities/user.schema';
import { BadRequestException, HttpException } from '@nestjs/common';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import CardCreationPresenter from '../dto/useCase/presenters/create-card-res.use-case.dto';
import { createCardUseCase } from '../cards.providers';
import { CreateCardUseCase } from 'src/modules/cards/applications/create-card.use-case';

//Create Card Items Mocks
const cardIdtemDto = CardItemDtoFactory.create({ text: 'New Card', comments: [] });
Expand Down Expand Up @@ -54,17 +54,15 @@ describe('CreateCardUseCase', () => {
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
createCardUseCase,
CreateCardUseCase,
{
provide: TYPES.repository.CardRepository,
provide: CARD_REPOSITORY,
useValue: createMock<CardRepositoryInterface>()
}
]
}).compile();
useCase = module.get<UseCase<CreateCardUseCaseDto, CardCreationPresenter>>(
TYPES.applications.CreateCardUseCase
);
cardRepositoryMock = module.get(TYPES.repository.CardRepository);
useCase = module.get(CreateCardUseCase);
cardRepositoryMock = module.get(CARD_REPOSITORY);
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BadRequestException, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
import { TYPES } from '../interfaces/types';
import { CARD_REPOSITORY } from '../constants';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import CreateCardUseCaseDto from '../dto/useCase/create-card.use-case.dto';
import { CardRepositoryInterface } from '../repository/card.repository.interface';
Expand All @@ -15,7 +15,7 @@ import CardDto from '../dto/card.dto';
@Injectable()
export class CreateCardUseCase implements UseCase<CreateCardUseCaseDto, CardCreationPresenter> {
constructor(
@Inject(TYPES.repository.CardRepository)
@Inject(CARD_REPOSITORY)
private readonly cardRepository: CardRepositoryInterface
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { CardRepositoryInterface } from '../repository/card.repository.interface';
import { TYPES } from '../interfaces/types';
import { CARD_REPOSITORY, GET_CARD_SERVICE } from '../constants';
import { GetCardServiceInterface } from '../interfaces/services/get.card.service.interface';
import { DeleteCardUseCase } from './delete-card.use-case';
import { UpdateBoardUserServiceInterface } from 'src/modules/boardUsers/interfaces/services/update.board.user.service.interface';
Expand Down Expand Up @@ -48,23 +48,23 @@ describe('DeleteCardUseCase', () => {
providers: [
DeleteCardUseCase,
{
provide: TYPES.services.GetCardService,
provide: GET_CARD_SERVICE,
useValue: createMock<GetCardServiceInterface>()
},
{
provide: UPDATE_BOARD_USER_SERVICE,
useValue: createMock<GetCardServiceInterface>()
},
{
provide: TYPES.repository.CardRepository,
provide: CARD_REPOSITORY,
useValue: createMock<UpdateBoardUserServiceInterface>()
}
]
}).compile();
useCase = module.get<UseCase<DeleteCardUseCaseDto, void>>(DeleteCardUseCase);
cardRepositoryMock = module.get(TYPES.repository.CardRepository);
useCase = module.get(DeleteCardUseCase);
cardRepositoryMock = module.get(CARD_REPOSITORY);
updateBoardUserServiceMock = module.get(UPDATE_BOARD_USER_SERVICE);
getCardServiceMock = module.get(TYPES.services.GetCardService);
getCardServiceMock = module.get(GET_CARD_SERVICE);
cardRepositoryMock.updateCardsFromBoard.mockResolvedValue(updateResult);
getCardServiceMock.getCardFromBoard.mockResolvedValue(cardMock);
updateBoardUserServiceMock.updateManyUserVotes.mockResolvedValue(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { TYPES } from '../interfaces/types';
import { CARD_REPOSITORY, GET_CARD_SERVICE } from '../constants';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { CardRepositoryInterface } from '../repository/card.repository.interface';
import DeleteCardUseCaseDto from '../dto/useCase/delete-card.use-case.dto';
Expand All @@ -21,9 +21,9 @@ import { UPDATE_BOARD_USER_SERVICE } from 'src/modules/boardUsers/constants';
@Injectable()
export class DeleteCardUseCase implements UseCase<DeleteCardUseCaseDto, void> {
constructor(
@Inject(TYPES.services.GetCardService)
@Inject(GET_CARD_SERVICE)
private readonly getCardService: GetCardServiceInterface,
@Inject(TYPES.repository.CardRepository)
@Inject(CARD_REPOSITORY)
private readonly cardRepository: CardRepositoryInterface,
@Inject(UPDATE_BOARD_USER_SERVICE)
private readonly updateBoardUserService: UpdateBoardUserServiceInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { CardRepositoryInterface } from '../repository/card.repository.interface';
import { TYPES } from '../interfaces/types';
import { CARD_REPOSITORY, GET_CARD_SERVICE } from '../constants';
import { GetCardServiceInterface } from '../interfaces/services/get.card.service.interface';
import { UpdateBoardUserServiceInterface } from 'src/modules/boardUsers/interfaces/services/update.board.user.service.interface';
import faker from '@faker-js/faker';
Expand Down Expand Up @@ -60,23 +60,23 @@ describe('DeleteFromCardGroupUseCase', () => {
providers: [
DeleteFromCardGroupUseCase,
{
provide: TYPES.services.GetCardService,
provide: GET_CARD_SERVICE,
useValue: createMock<GetCardServiceInterface>()
},
{
provide: UPDATE_BOARD_USER_SERVICE,
useValue: createMock<GetCardServiceInterface>()
},
{
provide: TYPES.repository.CardRepository,
provide: CARD_REPOSITORY,
useValue: createMock<UpdateBoardUserServiceInterface>()
}
]
}).compile();
useCase = module.get<UseCase<DeleteFromCardGroupUseCaseDto, void>>(DeleteFromCardGroupUseCase);
cardRepositoryMock = module.get(TYPES.repository.CardRepository);
useCase = module.get(DeleteFromCardGroupUseCase);
cardRepositoryMock = module.get(CARD_REPOSITORY);
updateBoardUserServiceMock = module.get(UPDATE_BOARD_USER_SERVICE);
getCardServiceMock = module.get(TYPES.services.GetCardService);
getCardServiceMock = module.get(GET_CARD_SERVICE);

updateBoardUserServiceMock.updateManyUserVotes.mockResolvedValue(
bulkWriteResult as unknown as BulkWriteResult
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inject, Injectable, Logger, NotFoundException } from '@nestjs/common';
import { TYPES } from '../interfaces/types';
import { CARD_REPOSITORY, GET_CARD_SERVICE } from '../constants';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { CardRepositoryInterface } from '../repository/card.repository.interface';
import { GetCardServiceInterface } from '../interfaces/services/get.card.service.interface';
Expand All @@ -24,9 +24,9 @@ import { UPDATE_BOARD_USER_SERVICE } from 'src/modules/boardUsers/constants';
@Injectable()
export class DeleteFromCardGroupUseCase implements UseCase<DeleteFromCardGroupUseCaseDto, void> {
constructor(
@Inject(TYPES.services.GetCardService)
@Inject(GET_CARD_SERVICE)
private readonly getCardService: GetCardServiceInterface,
@Inject(TYPES.repository.CardRepository)
@Inject(CARD_REPOSITORY)
private readonly cardRepository: CardRepositoryInterface,
@Inject(UPDATE_BOARD_USER_SERVICE)
private readonly updateBoardUserService: UpdateBoardUserServiceInterface
Expand Down
18 changes: 8 additions & 10 deletions backend/src/modules/cards/applications/merge-card.use-case.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { CardRepositoryInterface } from '../repository/card.repository.interface';
import { TYPES } from '../interfaces/types';
import { CARD_REPOSITORY, GET_CARD_SERVICE } from '../constants';
import { GetCardServiceInterface } from '../interfaces/services/get.card.service.interface';
import MergeCardUseCaseDto from '../dto/useCase/merge-card.use-case.dto';
import faker from '@faker-js/faker';
Expand All @@ -10,7 +10,7 @@ import { CardFactory } from 'src/libs/test-utils/mocks/factories/card-factory.mo
import { UpdateResult } from 'mongodb';
import { CardItemFactory } from 'src/libs/test-utils/mocks/factories/cardItem-factory.mock';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { mergeCardUseCase } from '../cards.providers';
import { MergeCardUseCase } from 'src/modules/cards/applications/merge-card.use-case';

const mergeCardDtoMock: MergeCardUseCaseDto = {
boardId: faker.datatype.uuid(),
Expand All @@ -36,22 +36,20 @@ describe('MergeCardUseCase', () => {
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
mergeCardUseCase,
MergeCardUseCase,
{
provide: TYPES.services.GetCardService,
provide: GET_CARD_SERVICE,
useValue: createMock<GetCardServiceInterface>()
},
{
provide: TYPES.repository.CardRepository,
provide: CARD_REPOSITORY,
useValue: createMock<CardRepositoryInterface>()
}
]
}).compile();
useCase = module.get<UseCase<MergeCardUseCaseDto, boolean>>(
TYPES.applications.MergeCardUseCase
);
getCardServiceMock = module.get(TYPES.services.GetCardService);
cardRepositoryMock = module.get(TYPES.repository.CardRepository);
useCase = module.get(MergeCardUseCase);
getCardServiceMock = module.get(GET_CARD_SERVICE);
cardRepositoryMock = module.get(CARD_REPOSITORY);

getCardServiceMock.getCardFromBoard
.mockResolvedValue(cardMock[0])
Expand Down
6 changes: 3 additions & 3 deletions backend/src/modules/cards/applications/merge-card.use-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { Inject, Injectable } from '@nestjs/common';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { GetCardServiceInterface } from '../interfaces/services/get.card.service.interface';
import { CardRepositoryInterface } from '../repository/card.repository.interface';
import { TYPES } from '../interfaces/types';
import { CARD_REPOSITORY, GET_CARD_SERVICE } from '../constants';
import MergeCardUseCaseDto from '../dto/useCase/merge-card.use-case.dto';
import { CARD_NOT_FOUND, CARD_NOT_REMOVED, UPDATE_FAILED } from 'src/libs/exceptions/messages';
import { UpdateFailedException } from 'src/libs/exceptions/updateFailedBadRequestException';

@Injectable()
export class MergeCardUseCase implements UseCase<MergeCardUseCaseDto, boolean> {
constructor(
@Inject(TYPES.services.GetCardService)
@Inject(GET_CARD_SERVICE)
private readonly getCardService: GetCardServiceInterface,
@Inject(TYPES.repository.CardRepository)
@Inject(CARD_REPOSITORY)
private readonly cardRepository: CardRepositoryInterface
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing';
import { TYPES } from '../interfaces/types';
import { CARD_REPOSITORY, GET_CARD_SERVICE } from '../constants';
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { CardRepositoryInterface } from '../repository/card.repository.interface';
import { GetCardServiceInterface } from '../interfaces/services/get.card.service.interface';
Expand All @@ -9,7 +9,7 @@ import { CardFactory } from 'src/libs/test-utils/mocks/factories/card-factory.mo
import { BoardFactory } from 'src/libs/test-utils/mocks/factories/board-factory.mock';
import { BadRequestException } from '@nestjs/common';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { unmergeCardUseCase } from '../cards.providers';
import { UnmergeCardUseCase } from 'src/modules/cards/applications/unmerge-card.use-case';

const unmergeCardDto: UnmergeCardUseCaseDto = {
boardId: faker.datatype.uuid(),
Expand Down Expand Up @@ -37,22 +37,20 @@ describe('UnmergeCardUseCase', () => {
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
unmergeCardUseCase,
UnmergeCardUseCase,
{
provide: TYPES.services.GetCardService,
provide: GET_CARD_SERVICE,
useValue: createMock<GetCardServiceInterface>()
},
{
provide: TYPES.repository.CardRepository,
provide: CARD_REPOSITORY,
useValue: createMock<CardRepositoryInterface>()
}
]
}).compile();
useCase = module.get<UseCase<UnmergeCardUseCaseDto, string>>(
TYPES.applications.UnmergeCardUseCase
);
cardRepositoryMock = module.get(TYPES.repository.CardRepository);
cardServiceMock = module.get(TYPES.services.GetCardService);
useCase = module.get(UnmergeCardUseCase);
cardRepositoryMock = module.get(CARD_REPOSITORY);
cardServiceMock = module.get(GET_CARD_SERVICE);
cardServiceMock.getCardItemFromGroup.mockResolvedValue(cardMock);
cardServiceMock.getCardFromBoard.mockResolvedValue(cardMock);
cardRepositoryMock.pullItem.mockResolvedValue(updateResultMock);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inject, Injectable } from '@nestjs/common';
import { TYPES } from '../interfaces/types';
import { CARD_REPOSITORY, GET_CARD_SERVICE } from '../constants';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { CardRepositoryInterface } from '../repository/card.repository.interface';
import { GetCardServiceInterface } from '../interfaces/services/get.card.service.interface';
Expand All @@ -15,9 +15,9 @@ import { UpdateFailedException } from 'src/libs/exceptions/updateFailedBadReques
@Injectable()
export class UnmergeCardUseCase implements UseCase<UnmergeCardUseCaseDto, string> {
constructor(
@Inject(TYPES.services.GetCardService)
@Inject(GET_CARD_SERVICE)
private readonly cardService: GetCardServiceInterface,
@Inject(TYPES.repository.CardRepository)
@Inject(CARD_REPOSITORY)
private readonly cardRepository: CardRepositoryInterface
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Test, TestingModule } from '@nestjs/testing';
import { TYPES } from '../../interfaces/types';
import { CARD_REPOSITORY } from '../../constants';
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { CardRepositoryInterface } from '../../repository/card.repository.interface';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { updateCardGroupTextUseCase } from '../../cards.providers';
import faker from '@faker-js/faker';
import { UpdateResult } from 'mongodb';
import { BoardFactory } from 'src/libs/test-utils/mocks/factories/board-factory.mock';
import { UpdateFailedException } from 'src/libs/exceptions/updateFailedBadRequestException';
import { Logger } from '@nestjs/common';
import UpdateCardGroupTextUseCaseDto from '../../dto/useCase/update-card-group-text.use-case.dto';
import { UpdateCardGroupTextUseCase } from 'src/modules/cards/applications/update/update-card-group-text.use-case';

const updateCardGroupTextDto: UpdateCardGroupTextUseCaseDto = {
boardId: faker.datatype.uuid(),
Expand Down Expand Up @@ -38,17 +38,15 @@ describe('UpdateCardGroupTextUseCase', () => {
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
updateCardGroupTextUseCase,
UpdateCardGroupTextUseCase,
{
provide: TYPES.repository.CardRepository,
provide: CARD_REPOSITORY,
useValue: createMock<CardRepositoryInterface>()
}
]
}).compile();
useCase = module.get<UseCase<UpdateCardGroupTextUseCaseDto, void>>(
TYPES.applications.UpdateCardGroupTextUseCase
);
cardRepositoryMock = module.get(TYPES.repository.CardRepository);
useCase = module.get(UpdateCardGroupTextUseCase);
cardRepositoryMock = module.get(CARD_REPOSITORY);
cardRepositoryMock.updateCardGroupText.mockResolvedValue(board);

jest.spyOn(Logger.prototype, 'error').mockImplementation(jest.fn);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { TYPES } from '../../interfaces/types';
import { CARD_REPOSITORY } from '../../constants';
import { CardRepositoryInterface } from '../../repository/card.repository.interface';
import { UseCase } from 'src/libs/interfaces/use-case.interface';
import { UpdateFailedException } from 'src/libs/exceptions/updateFailedBadRequestException';
Expand All @@ -9,7 +9,7 @@ import UpdateCardGroupTextUseCaseDto from '../../dto/useCase/update-card-group-t
@Injectable()
export class UpdateCardGroupTextUseCase implements UseCase<UpdateCardGroupTextUseCaseDto, void> {
constructor(
@Inject(TYPES.repository.CardRepository)
@Inject(CARD_REPOSITORY)
private readonly cardRepository: CardRepositoryInterface
) {}
private logger = new Logger(UpdateCardGroupTextUseCase.name);
Expand Down
Loading

0 comments on commit 86f68be

Please sign in to comment.