Skip to content

Commit

Permalink
test: add test to isValid BoardNotValidError
Browse files Browse the repository at this point in the history
  • Loading branch information
GoncaloCanteiro committed Mar 17, 2023
1 parent 6b684ca commit 328f02b
Showing 1 changed file with 102 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
SLACK_MASTER_CHANNEL_ID
} from 'src/libs/constants/slack';
import configService from 'src/libs/test-utils/mocks/configService.mock';
import { BoardFactory } from 'src/libs/test-utils/mocks/factories/board-factory.mock';
import { UserFactory } from 'src/libs/test-utils/mocks/factories/user-factory';
import {
fillDividedBoardsUsersWithTeamUsers,
Expand All @@ -25,7 +24,6 @@ import { SlackCommunicationApplication } from 'src/modules/communication/applica
import { ChatSlackHandler } from 'src/modules/communication/handlers/chat-slack.handler';
import { ConversationsSlackHandler } from 'src/modules/communication/handlers/conversations-slack.handler';
import { UsersSlackHandler } from 'src/modules/communication/handlers/users-slack.handler';
import { BoardType } from '../dto/types';
import { BoardNotValidError } from '../errors/board-not-valid.error';

const slackUsersIds = [
Expand Down Expand Up @@ -552,12 +550,109 @@ describe('SlackCommunicationApplication', () => {

expect(result.length).toBe(expectedTotalTeamsToBe);
});
it('should throw BoardNotValidError', async () => {
const board = BoardFactory.create();
it('should throw BoardNotValidError when board is not valid', async () => {
let givenBoard: any = {
_id: 'main-board',
title: 'Main Board',
dividedBoards: [
{
_id: 'sub-team-board-1',
title: 'Sub-team board 1',
dividedBoards: [],
isSubBoard: true,
users: [
{
role: 'member',
user: null,
board: 'sub-team-board-1'
},
{
role: 'responsible',
user: null,
board: 'sub-team-board-1'
},
{
role: 'member',
user: null,
board: 'sub-team-board-1'
}
]
},
{
_id: 'sub-team-board-2',
title: 'Sub-team board 2',
dividedBoards: null,
isSubBoard: true,
users: [
{
role: 'member',
user: slackUsersIds[3],
board: 'sub-team-board-2'
},
{
role: 'member',
user: slackUsersIds[4],
board: 'sub-team-board-2'
},
{
role: 'responsible',
user: slackUsersIds[5],
board: 'sub-team-board-2'
}
]
},
{
_id: 'sud-team-board-3',
title: 'Sub-team board 3',
dividedBoards: [],
isSubBoard: true,
users: [
{
role: 'responsible',
user: slackUsersIds[6],
board: 'sud-team-board-3'
},
{
role: 'member',
user: slackUsersIds[7],
board: 'sud-team-board-3'
},
{
role: 'member',
user: slackUsersIds[8],
board: 'sud-team-board-3'
}
]
}
],
team: {
users: [
...slackUsersIds.map((i) => ({
role: 'member',
user: {
_id: i,
firstName: `first_name_${i}`,
lastName: `last_name_${i}`,
email: `${i}@email.com`
}
})),
{
role: 'stakeholder',
user: {
_id: 'any_id',
firstName: 'any_first_name',
lastName: 'any_last_name',
email: 'any_email@gmail.com'
}
}
]
},
isSubBoard: false
};
givenBoard = translateBoard(givenBoard);
givenBoard = fillDividedBoardsUsersWithTeamUsers(givenBoard);

await expect(application.execute(board as unknown as BoardType)).rejects.toThrowError(
BoardNotValidError
);
await expect(application.execute(givenBoard)).rejects.toThrowError(BoardNotValidError);
});

it('should returns all teams (one for each sub-board plus the team for responsibles) even if create slack channels fails for some ', async () => {
Expand Down

0 comments on commit 328f02b

Please sign in to comment.