Skip to content

Commit

Permalink
BC-7298 - refactor failure actions (#5041)
Browse files Browse the repository at this point in the history
Simplify all failure-payloads of BoardCollaborationSocket-Actions to no longer carry ErrorType and BoardNodeType in order  to remove redundancy between action-name and carried data. This way refactorings on the backend-side are enabled.
  • Loading branch information
hoeppner-dataport authored Jun 3, 2024
1 parent b19b9db commit 5504f93
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { getSocketApiClient, waitForEvent } from '@shared/testing/test-socket-ap
import { Socket } from 'socket.io-client';
import { BoardCollaborationTestingModule } from '../../board-collaboration.testing.module';
import { BoardCollaborationGateway } from '../board-collaboration.gateway';
import { BoardObjectType, ErrorType } from '../types';

describe(BoardCollaborationGateway.name, () => {
let app: INestApplication;
Expand Down Expand Up @@ -107,11 +106,7 @@ describe(BoardCollaborationGateway.name, () => {
ioClient.emit('create-card-request', { columnId });
const failure = await waitForEvent(ioClient, 'create-card-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_CARD,
errorType: ErrorType.NOT_CREATED,
requestPayload: { columnId },
});
expect(failure).toEqual({ columnId });
});
});
});
Expand All @@ -137,11 +132,7 @@ describe(BoardCollaborationGateway.name, () => {
ioClient.emit('fetch-board-request', { boardId });
const failure = await waitForEvent(ioClient, 'fetch-board-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD,
errorType: ErrorType.NOT_LOADED,
requestPayload: { boardId },
});
expect(failure).toEqual({ boardId });
});
});
});
Expand Down Expand Up @@ -206,11 +197,7 @@ describe(BoardCollaborationGateway.name, () => {
ioClient.emit('move-card-request', moveCardProps);
const failure = await waitForEvent(ioClient, 'move-card-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_CARD,
errorType: ErrorType.NOT_UPDATED,
requestPayload: moveCardProps,
});
expect(failure).toEqual(moveCardProps);
});
});
});
Expand All @@ -235,11 +222,7 @@ describe(BoardCollaborationGateway.name, () => {
ioClient.emit('update-column-title-request', updateColumnProps);
const failure = await waitForEvent(ioClient, 'update-column-title-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_COLUMN,
errorType: ErrorType.NOT_UPDATED,
requestPayload: updateColumnProps,
});
expect(failure).toEqual(updateColumnProps);
});
});
});
Expand All @@ -260,16 +243,12 @@ describe(BoardCollaborationGateway.name, () => {
describe('when board does not exist', () => {
it('should answer with failure', async () => {
await setup();
const boardId = new ObjectId().toHexString();
const payload = { boardId: new ObjectId().toHexString() };

ioClient.emit('delete-board-request', { boardId });
ioClient.emit('delete-board-request', payload);
const failure = await waitForEvent(ioClient, 'delete-board-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD,
errorType: ErrorType.NOT_DELETED,
requestPayload: { boardId },
});
expect(failure).toEqual(payload);
});
});
});
Expand All @@ -290,17 +269,13 @@ describe(BoardCollaborationGateway.name, () => {
describe('when board does not exist', () => {
it('should answer with failure', async () => {
await setup();
const updateTitleProps = { boardId: new ObjectId().toHexString(), newTitle: 'new title' };
const payload = { boardId: new ObjectId().toHexString(), newTitle: 'new title' };

ioClient.emit('update-board-title-request', updateTitleProps);
ioClient.emit('update-board-title-request', payload);
const failure = await waitForEvent(ioClient, 'update-board-title-failure');

expect(failure).toBeDefined();
expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD,
errorType: ErrorType.NOT_UPDATED,
requestPayload: updateTitleProps,
});
expect(failure).toEqual(payload);
});
});
});
Expand All @@ -321,16 +296,12 @@ describe(BoardCollaborationGateway.name, () => {
describe('when board does not exist', () => {
it('should answer with failure', async () => {
await setup();
const boardId = new ObjectId().toHexString();
const payload = { boardId: new ObjectId().toHexString() };

ioClient.emit('create-column-request', { boardId });
ioClient.emit('create-column-request', payload);
const failure = await waitForEvent(ioClient, 'create-column-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_COLUMN,
errorType: ErrorType.NOT_CREATED,
requestPayload: { boardId },
});
expect(failure).toEqual(payload);
});
});
});
Expand All @@ -356,11 +327,7 @@ describe(BoardCollaborationGateway.name, () => {
ioClient.emit('update-board-visibility-request', { boardId, isVisible: false });
const failure = await waitForEvent(ioClient, 'update-board-visibility-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD,
errorType: ErrorType.NOT_UPDATED,
requestPayload: { boardId, isVisible: false },
});
expect(failure).toEqual({ boardId, isVisible: false });
});
});
});
Expand All @@ -386,11 +353,7 @@ describe(BoardCollaborationGateway.name, () => {
ioClient.emit('delete-column-request', { columnId });
const failure = await waitForEvent(ioClient, 'delete-column-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_COLUMN,
errorType: ErrorType.NOT_DELETED,
requestPayload: { columnId },
});
expect(failure).toEqual({ columnId });
});
});
});
Expand All @@ -400,7 +363,7 @@ describe(BoardCollaborationGateway.name, () => {
it('should answer with success', async () => {
const { columnBoardNode, columnNode } = await setup();

const moveColumnProps = {
const payload = {
targetBoardId: columnBoardNode.id,
columnMove: {
addedIndex: 1,
Expand All @@ -409,18 +372,18 @@ describe(BoardCollaborationGateway.name, () => {
},
};

ioClient.emit('move-column-request', moveColumnProps);
ioClient.emit('move-column-request', payload);
const success = await waitForEvent(ioClient, 'move-column-success');

expect(success).toEqual(expect.objectContaining(moveColumnProps));
expect(success).toEqual(expect.objectContaining(payload));
});
});

describe('when column does not exist', () => {
it('should answer with failure', async () => {
const { columnBoardNode } = await setup();

const moveColumnProps = {
const payload = {
targetBoardId: columnBoardNode.id,
columnMove: {
addedIndex: 1,
Expand All @@ -429,14 +392,10 @@ describe(BoardCollaborationGateway.name, () => {
},
};

ioClient.emit('move-column-request', moveColumnProps);
ioClient.emit('move-column-request', payload);
const failure = await waitForEvent(ioClient, 'move-column-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_COLUMN,
errorType: ErrorType.NOT_UPDATED,
requestPayload: moveColumnProps,
});
expect(failure).toEqual(payload);
});
});
});
Expand All @@ -457,16 +416,12 @@ describe(BoardCollaborationGateway.name, () => {
describe('when card does not exist', () => {
it('should answer with failure', async () => {
await setup();
const updateCardTitleProps = { cardId: new ObjectId().toHexString(), newTitle: 'new title' };
const payload = { cardId: new ObjectId().toHexString(), newTitle: 'new title' };

ioClient.emit('update-card-title-request', updateCardTitleProps);
ioClient.emit('update-card-title-request', payload);
const failure = await waitForEvent(ioClient, 'update-card-title-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_CARD,
errorType: ErrorType.NOT_UPDATED,
requestPayload: updateCardTitleProps,
});
expect(failure).toEqual(payload);
});
});
});
Expand All @@ -488,16 +443,12 @@ describe(BoardCollaborationGateway.name, () => {
describe('when card does not exist', () => {
it('should answer with failure', async () => {
await setup();
const updateCardHeightProps = { cardId: new ObjectId().toHexString(), newHeight: 200 };
const payload = { cardId: new ObjectId().toHexString(), newHeight: 200 };

ioClient.emit('update-card-height-request', updateCardHeightProps);
ioClient.emit('update-card-height-request', payload);
const failure = await waitForEvent(ioClient, 'update-card-height-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_CARD,
errorType: ErrorType.NOT_UPDATED,
requestPayload: updateCardHeightProps,
});
expect(failure).toEqual(payload);
});
});
});
Expand All @@ -518,16 +469,12 @@ describe(BoardCollaborationGateway.name, () => {
describe('when card does not exist', () => {
it('should answer with failure', async () => {
await setup();
const cardId = new ObjectId().toHexString();
const payload = { cardIds: [new ObjectId().toHexString()] };

ioClient.emit('fetch-card-request', { cardIds: [cardId] });
ioClient.emit('fetch-card-request', payload);
const failure = await waitForEvent(ioClient, 'fetch-card-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_CARD,
errorType: ErrorType.NOT_LOADED,
requestPayload: { cardIds: [cardId] },
});
expect(failure).toEqual(payload);
});
});
});
Expand All @@ -548,16 +495,12 @@ describe(BoardCollaborationGateway.name, () => {
describe('when card does not exist', () => {
it('should answer with failure', async () => {
await setup();
const cardId = new ObjectId().toHexString();
const payload = { cardId: new ObjectId().toHexString() };

ioClient.emit('delete-card-request', { cardId });
ioClient.emit('delete-card-request', payload);
const failure = await waitForEvent(ioClient, 'delete-card-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_CARD,
errorType: ErrorType.NOT_DELETED,
requestPayload: { cardId },
});
expect(failure).toEqual(payload);
});
});
});
Expand All @@ -581,14 +524,12 @@ describe(BoardCollaborationGateway.name, () => {
await setup();
const cardId = new ObjectId().toHexString();

ioClient.emit('create-element-request', { cardId, type: ContentElementType.RICH_TEXT });
const payload = { cardId, type: ContentElementType.RICH_TEXT };

ioClient.emit('create-element-request', payload);
const failure = await waitForEvent(ioClient, 'create-element-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_ELEMENT,
errorType: ErrorType.NOT_CREATED,
requestPayload: { cardId, type: ContentElementType.RICH_TEXT },
});
expect(failure).toEqual(payload);
});
});
});
Expand All @@ -610,16 +551,12 @@ describe(BoardCollaborationGateway.name, () => {
describe('when element does not exist', () => {
it('should answer with failure', async () => {
const { cardNodes } = await setup();
const deleteElementProps = { cardId: cardNodes[0].id, elementId: new ObjectId().toHexString() };
const payload = { cardId: cardNodes[0].id, elementId: new ObjectId().toHexString() };

ioClient.emit('delete-element-request', deleteElementProps);
ioClient.emit('delete-element-request', payload);
const failure = await waitForEvent(ioClient, 'delete-element-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_ELEMENT,
errorType: ErrorType.NOT_DELETED,
requestPayload: deleteElementProps,
});
expect(failure).toEqual(payload);
});
});
});
Expand Down Expand Up @@ -648,22 +585,18 @@ describe(BoardCollaborationGateway.name, () => {
describe('when element does not exist', () => {
it('should answer with failure', async () => {
await setup();
const updateElementProps = {
const payload = {
elementId: new ObjectId().toHexString(),
data: {
type: ContentElementType.RICH_TEXT,
content: { text: 'some new text', inputFormat: InputFormat.PLAIN_TEXT },
},
};

ioClient.emit('update-element-request', updateElementProps);
ioClient.emit('update-element-request', payload);
const failure = await waitForEvent(ioClient, 'update-element-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_ELEMENT,
errorType: ErrorType.NOT_UPDATED,
requestPayload: updateElementProps,
});
expect(failure).toEqual(payload);
});
});
});
Expand All @@ -672,28 +605,24 @@ describe(BoardCollaborationGateway.name, () => {
describe('when element exists', () => {
it('should answer with success', async () => {
const { cardNodes, elementNodes } = await setup();
const data = { elementId: elementNodes[0].id, toCardId: cardNodes[0].id, toPosition: 2 };
const payload = { elementId: elementNodes[0].id, toCardId: cardNodes[0].id, toPosition: 2 };

ioClient.emit('move-element-request', data);
ioClient.emit('move-element-request', payload);
const success = await waitForEvent(ioClient, 'move-element-success');

expect(success).toEqual(expect.objectContaining(data));
expect(success).toEqual(expect.objectContaining(payload));
});
});

describe('when element does not exist', () => {
it('should answer with failure', async () => {
const { cardNodes } = await setup();
const data = { elementId: new ObjectId().toHexString(), toCardId: cardNodes[0].id, toPosition: 2 };
const payload = { elementId: new ObjectId().toHexString(), toCardId: cardNodes[0].id, toPosition: 2 };

ioClient.emit('move-element-request', data);
ioClient.emit('move-element-request', payload);
const failure = await waitForEvent(ioClient, 'move-element-failure');

expect(failure).toEqual({
boardObjectType: BoardObjectType.BOARD_ELEMENT,
errorType: ErrorType.NOT_UPDATED,
requestPayload: data,
});
expect(failure).toEqual(payload);
});
});
});
Expand Down
Loading

0 comments on commit 5504f93

Please sign in to comment.