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

test: update board service #1259

Merged
merged 16 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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,8 +3,6 @@ import { ColumnFactory } from './column-factory.mock';
import Board from 'src/modules/boards/entities/board.schema';
import { buildTestFactory } from './generic-factory.mock';

const userId = faker.datatype.uuid();

const mockBoardData = () => {
return {
_id: faker.database.mongodbObjectId(),
Expand All @@ -26,7 +24,7 @@ const mockBoardData = () => {
slackEnable: faker.datatype.boolean(),
addCards: faker.datatype.boolean(),
responsibles: ['1'],
createdBy: userId,
createdBy: faker.datatype.uuid(),
addcards: faker.datatype.boolean(),
postAnonymously: faker.datatype.boolean(),
createdAt: faker.datatype.datetime().toISOString()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import faker from '@faker-js/faker';
import { BoardPhases } from 'src/libs/enum/board.phases';
import BoardDto from 'src/modules/boards/dto/board.dto';
import { buildTestFactory } from '../generic-factory.mock';
import { ColumnDtoFactory } from './columnDto-factory.mock';

const mockBoardDto = () => {
return {
_id: faker.database.mongodbObjectId(),
title: faker.lorem.words(),
columns: ColumnDtoFactory.createMany(3),
isPublic: faker.datatype.boolean(),
maxVotes: faker.datatype.number({ min: 0, max: 6 }),
maxUsers: 0,
maxTeams: '1',
hideCards: faker.datatype.boolean(),
hideVotes: faker.datatype.boolean(),
dividedBoards: [],
team: '1',
socketId: faker.datatype.uuid(),
users: [],
recurrent: faker.datatype.boolean(),
isSubBoard: faker.datatype.boolean(),
boardNumber: 0,
slackEnable: faker.datatype.boolean(),
addCards: faker.datatype.boolean(),
responsibles: ['1'],
createdBy: faker.datatype.uuid(),
addcards: faker.datatype.boolean(),
postAnonymously: faker.datatype.boolean(),
createdAt: faker.datatype.datetime().toISOString(),
phase: faker.helpers.arrayElement([
BoardPhases.ADDCARDS,
BoardPhases.SUBMITTED,
BoardPhases.VOTINGPHASE
])
};
};

export const BoardDtoFactory = buildTestFactory<BoardDto>(() => {
return mockBoardDto();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import faker from '@faker-js/faker';
import { BoardRoles } from 'src/libs/enum/board.roles';
import BoardUserDto from 'src/modules/boards/dto/board.user.dto';
import { buildTestFactory } from '../generic-factory.mock';
import { UserFactory } from '../user-factory';

const mockBoardUserDto = () => {
return {
id: faker.datatype.uuid(),
role: faker.helpers.arrayElement([BoardRoles.MEMBER, BoardRoles.RESPONSIBLE]),
user: UserFactory.create(),
board: faker.datatype.uuid(),
votesCount: Math.random() * 10,
isNewJoiner: faker.datatype.boolean()
};
};

export const BoardUserDtoFactory = buildTestFactory<BoardUserDto>(() => {
return mockBoardUserDto();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import faker from '@faker-js/faker';
import CardDto from 'src/modules/cards/dto/card.dto';
import { buildTestFactory } from '../generic-factory.mock';
import { CardItemDtoFactory } from './cardItemDto-factory.mock';
import { CommentDtoFactory } from './commentsDto-factory.mock';

const mockCardDto = () => {
return {
items: [CardItemDtoFactory.create()],
id: faker.database.mongodbObjectId(),
text: faker.lorem.words(),
createdBy: faker.datatype.uuid(),
comments: [CommentDtoFactory.create()],
votes: [],
anonymous: faker.datatype.boolean()
};
};

export const CardDtoFactory = buildTestFactory<CardDto>(() => {
return mockCardDto();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import faker from '@faker-js/faker';
import CardItemDto from 'src/modules/cards/dto/card.item.dto';
import { buildTestFactory } from '../generic-factory.mock';
import { CommentDtoFactory } from './commentsDto-factory.mock';

const mockCardItemDto = () => {
return {
id: faker.database.mongodbObjectId(),
text: faker.lorem.words(),
createdBy: faker.datatype.uuid(),
comments: [CommentDtoFactory.create()],
votes: [],
anonymous: faker.datatype.boolean()
};
};

export const CardItemDtoFactory = buildTestFactory<CardItemDto>(() => {
return mockCardItemDto();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import faker from '@faker-js/faker';
import ColumnDto from 'src/modules/columns/dto/column.dto';
import { buildTestFactory } from '../generic-factory.mock';
import { CardDtoFactory } from './cardDto-factory.mock';

const mockColumnDto = () => {
return {
_id: faker.database.mongodbObjectId(),
title: faker.lorem.words(),
color: faker.helpers.arrayElement([
'#CDFAE0',
'#DEB7FF',
'#9BFDFA',
'#FE9EBF',
'#9DCAFF',
'#FEB9A9'
]),
cards: [CardDtoFactory.create()],
cardText: faker.lorem.words(),
isDefaultText: faker.datatype.boolean()
};
};

export const ColumnDtoFactory = buildTestFactory<ColumnDto>(() => {
return mockColumnDto();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import faker from '@faker-js/faker';
import CommentDto from 'src/modules/comments/dto/comment.dto';
import { buildTestFactory } from '../generic-factory.mock';

const mockCommentDto = () => {
return {
text: faker.lorem.words(),
createdBy: faker.datatype.uuid(),
anonymous: faker.datatype.boolean()
};
};

export const CommentDtoFactory = buildTestFactory<CommentDto>(() => {
return mockCommentDto();
});
22 changes: 22 additions & 0 deletions backend/src/libs/test-utils/mocks/factories/dto/teamDto-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import faker from '@faker-js/faker';
import { ForTeamDtoEnum, TeamDto } from 'src/modules/communication/dto/team.dto';
import { BoardRoles } from 'src/modules/communication/dto/types';
import { buildTestFactory } from '../generic-factory.mock';
import { UserCommunicationDtoFactory } from './userCommunicationDto-factory.mock';

const mockTeamCommunicationDto = () => {
return {
name: faker.company.companyName(),
normalName: faker.company.companyName(),
boardId: faker.datatype.uuid(),
channelId: faker.datatype.uuid(),
type: faker.helpers.arrayElement([ForTeamDtoEnum.SUBTEAM, ForTeamDtoEnum.TEAM]),
for: faker.helpers.arrayElement([BoardRoles.MEMBER, BoardRoles.RESPONSIBLE]),
participants: UserCommunicationDtoFactory.createMany(2),
teamNumber: Math.random() * 10
};
};

export const TeamCommunicationDtoFactory = buildTestFactory<TeamDto>(() => {
return mockTeamCommunicationDto();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { UpdateBoardDto } from 'src/modules/boards/dto/update-board.dto';
import { BoardUserFactory } from '../boardUser-factory.mock';
import { buildTestFactory } from '../generic-factory.mock';
import { BoardDtoFactory } from './boardDto-factory.mock';

const mockUpdateBoardDto = () => {
return {
responsible: BoardUserFactory.create(),
...BoardDtoFactory.create()
};
};

export const UpdateBoardDtoFactory = buildTestFactory<UpdateBoardDto>(() => {
return mockUpdateBoardDto();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import faker from '@faker-js/faker';
import { UserDto } from 'src/modules/communication/dto/user.dto';
import { buildTestFactory } from '../generic-factory.mock';

const mockUserCommunicationDto = () => {
return {
id: faker.datatype.uuid(),
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
email: faker.internet.email(),
responsible: faker.datatype.boolean(),
boardId: faker.datatype.uuid(),
slackId: faker.datatype.uuid()
};
};

export const UserCommunicationDtoFactory = buildTestFactory<UserDto>(() => {
return mockUserCommunicationDto();
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class UpdateBoardApplication implements UpdateBoardApplicationInterface {
return this.updateBoardService.update(boardId, boardData);
}

mergeBoards(subBoardId: string, userId: string) {
return this.updateBoardService.mergeBoards(subBoardId, userId);
mergeBoards(subBoardId: string, userId: string, socketId?: string) {
return this.updateBoardService.mergeBoards(subBoardId, userId, socketId);
}

updateBoardParticipants(boardData: UpdateBoardUserDto) {
Expand Down
18 changes: 4 additions & 14 deletions backend/src/modules/boards/controller/boards.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
import { BaseParam } from 'src/libs/dto/param/base.param';
import { PaginationParams } from 'src/libs/dto/param/pagination.params';
import { BaseParamWSocket } from 'src/libs/dto/param/socket.param';
import { BOARD_NOT_FOUND, INSERT_FAILED, UPDATE_FAILED } from 'src/libs/exceptions/messages';
import { BOARD_NOT_FOUND, INSERT_FAILED } from 'src/libs/exceptions/messages';
import JwtAuthenticationGuard from 'src/libs/guards/jwtAuth.guard';
import RequestWithUser from 'src/libs/interfaces/requestWithUser.interface';
import { BadRequestResponse } from 'src/libs/swagger/errors/bad-request.swagger';
Expand Down Expand Up @@ -328,22 +328,12 @@ export default class BoardsController {
type: InternalServerErrorResponse
})
@Put(':boardId/merge')
async mergeBoard(
mergeBoard(
@Param() { boardId }: BaseParam,
@Query() { socketId }: BaseParamWSocket,
@Req() request: RequestWithUser
) {
const result = await this.updateBoardApp.mergeBoards(boardId, request.user._id);

if (!result) {
throw new BadRequestException(UPDATE_FAILED);
}

if (socketId) {
this.socketService.sendUpdatedAllBoard(boardId, socketId);
}

return result;
return this.updateBoardApp.mergeBoards(boardId, request.user._id, socketId);
}

@ApiOperation({ summary: 'Update board phase' })
Expand Down Expand Up @@ -371,7 +361,7 @@ export default class BoardsController {
type: UnauthorizedResponse
})
@Put(':boardId/phase')
async updateBoardPhase(@Body() boardPhaseDto: BoardPhaseDto) {
updateBoardPhase(@Body() boardPhaseDto: BoardPhaseDto) {
this.updateBoardApp.updatePhase(boardPhaseDto);
}
}
5 changes: 3 additions & 2 deletions backend/src/modules/boards/dto/board.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export default class BoardDto {
@ApiProperty({ type: BoardDto, isArray: true })
@ValidateNested({ each: true })
@Type(() => BoardDto)
@IsOptional()
dividedBoards!: BoardDto[] | string[];

@ApiPropertyOptional({ type: String })
Expand All @@ -92,22 +91,24 @@ export default class BoardDto {
socketId?: string;

@ApiPropertyOptional({ type: BoardUserDto, isArray: true })
@IsOptional()
@Validate(CheckUniqueUsers)
users!: BoardUserDto[];

@ApiPropertyOptional({ default: true })
@IsNotEmpty()
@IsOptional()
@IsBoolean()
recurrent?: boolean;

@ApiPropertyOptional({ default: false })
@IsNotEmpty()
@IsOptional()
@IsBoolean()
isSubBoard?: boolean;

@ApiPropertyOptional({ default: 0 })
@IsNotEmpty()
@IsOptional()
@IsNumber()
boardNumber?: number;

Expand Down
5 changes: 2 additions & 3 deletions backend/src/modules/boards/dto/board.user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
IsString
} from 'class-validator';
import { BoardRoles } from 'src/libs/enum/board.roles';
import User from 'src/modules/users/entities/user.schema';

export default class BoardUserDto {
@ApiPropertyOptional()
Expand All @@ -23,10 +24,8 @@ export default class BoardUserDto {
role!: string;

@ApiProperty()
@IsMongoId()
@IsString()
@IsNotEmpty()
user!: string;
user!: string | User;

@ApiProperty()
@IsMongoId()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { LeanDocument } from 'mongoose';
import { UpdateBoardDto } from '../../dto/update-board.dto';
import { BoardDocument } from '../../entities/board.schema';
import Board, { BoardDocument } from '../../entities/board.schema';
import BoardUser from '../../entities/board.user.schema';
import UpdateBoardUserDto from 'src/modules/boards/dto/update-board-user.dto';
import { BoardPhaseDto } from 'src/libs/dto/board-phase.dto';

export interface UpdateBoardApplicationInterface {
update(boardId: string, boardData: UpdateBoardDto): Promise<LeanDocument<BoardDocument> | null>;
update(boardId: string, boardData: UpdateBoardDto): Promise<Board>;

mergeBoards(subBoardId: string, userId: string): Promise<LeanDocument<BoardDocument> | null>;
mergeBoards(
subBoardId: string,
userId: string,
socketId?: string
): Promise<LeanDocument<BoardDocument> | null>;

updateBoardParticipants(boardData: UpdateBoardUserDto): Promise<BoardUser[] | BoardUser | null>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import BoardUserDto from 'src/modules/boards/dto/board.user.dto';
import { LeanDocument } from 'mongoose';
import { TeamDto } from 'src/modules/communication/dto/team.dto';
import { UpdateBoardDto } from '../../dto/update-board.dto';
import { BoardDocument } from '../../entities/board.schema';
import Board, { BoardDocument } from '../../entities/board.schema';
import BoardUser from '../../entities/board.user.schema';
import { BoardPhaseDto } from 'src/libs/dto/board-phase.dto';

export interface UpdateBoardServiceInterface {
update(boardId: string, boardData: UpdateBoardDto): Promise<LeanDocument<BoardDocument> | null>;
update(boardId: string, boardData: UpdateBoardDto): Promise<Board>;

mergeBoards(subBoardId: string, userId: string): Promise<LeanDocument<BoardDocument> | null>;
mergeBoards(
subBoardId: string,
userId: string,
socketId?: string
): Promise<LeanDocument<BoardDocument> | null>;
updateChannelId(teams: TeamDto[]);

updateBoardParticipants(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export interface BoardRepositoryInterface extends BaseInterfaceRepository<Board>
): Promise<number>;
deleteBoard(boardId: string, withSession: boolean): Promise<Board>;
updateBoard(boardId: string, board: Board, isNew: boolean): Promise<Board>;
updateMergedSubBoard(subBoardId: string, userId: string): Promise<Board>;
updateMergedBoard(boardId: string, newColumns: Column[]): Promise<Board>;
updateMergedSubBoard(subBoardId: string, userId: string, withSession: boolean): Promise<Board>;
updateMergedBoard(boardId: string, newColumns: Column[], withSession: boolean): Promise<Board>;
updatedChannelId(boardId: string, channelId: string): Promise<Board>;
updatePhase(boardId: string, phase: BoardPhases): Promise<Board>;
}
Loading