Skip to content

Commit

Permalink
undo not needed requestBody middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
mariscalromeroalejandro committed Jan 29, 2025
1 parent 99579e9 commit cf12d57
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 90 deletions.
2 changes: 0 additions & 2 deletions QualityControl/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { UserRole } from './../common/library/userRole.enum.js';
import { layoutOwnerMiddleware } from './middleware/layouts/layoutOwner.middleware.js';
import { layoutIdMiddleware } from './middleware/layouts/layoutId.middleware.js';
import { layoutServiceMiddleware } from './middleware/layouts/layoutService.middleware.js';
import { requestBodyMiddleware } from './middleware/requestBody.middleware.js';

/**
* Adds paths and binds websocket to instance of HttpServer passed
Expand Down Expand Up @@ -48,7 +47,6 @@ export const setup = (http, ws) => {
'/layout/:id',
layoutServiceMiddleware(jsonDb),
layoutIdMiddleware(jsonDb),
requestBodyMiddleware,
layoutOwnerMiddleware(jsonDb),
layoutService.putLayoutHandler.bind(layoutService),
);
Expand Down
9 changes: 8 additions & 1 deletion QualityControl/lib/controllers/LayoutController.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,18 @@ export class LayoutController {
try {
let layoutProposed = {};
try {
if (!req.body) {
updateAndSendExpressResponseFromNativeError(
res,
new InvalidInputError('Missing request body to update layout'),
);
return;
}
layoutProposed = await LayoutDto.validateAsync(req.body);
} catch (error) {
updateAndSendExpressResponseFromNativeError(
res,
new Error(`Failed to update layout ${error?.details?.[0]?.message || ''}`),
new InvalidInputError(`Failed to update layout ${error?.details?.[0]?.message || ''}`),
);
return;

Check warning on line 142 in QualityControl/lib/controllers/LayoutController.js

View check run for this annotation

Codecov / codecov/patch

QualityControl/lib/controllers/LayoutController.js#L138-L142

Added lines #L138 - L142 were not covered by tests
}
Expand Down
33 changes: 0 additions & 33 deletions QualityControl/lib/middleware/requestBody.middleware.js

This file was deleted.

12 changes: 12 additions & 0 deletions QualityControl/test/lib/controllers/LayoutController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ export const layoutControllerTestSuite = async () => {
};
});

test('should respond with 400 error if request did not contain body id', async () => {
const req = { params: { id: 'someid' } };
const layoutConnector = new LayoutController({});
await layoutConnector.putLayoutHandler(req, res);
ok(res.status.calledWith(400), 'Response status was not 400');
ok(res.json.calledWith({
message: 'Missing request body to update layout',
status: 400,
title: 'Invalid Input',
}), 'Error message was incorrect');
});

test('should successfully return the id of the updated layout', async () => {
const expectedMockWithDefaults = {
id: 'mylayout',
Expand Down
52 changes: 0 additions & 52 deletions QualityControl/test/lib/middlewares/requestBody.middleware.test.js

This file was deleted.

2 changes: 0 additions & 2 deletions QualityControl/test/test-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import { commonLibraryUtilsDateTimeTestSuite } from './common/library/utils/date
import { layoutIdMiddlewareTest } from './lib/middlewares/layouts/layoutId.middleware.test.js';
import { layoutOwnerMiddlewareTest } from './lib/middlewares/layouts/layoutOwner.middleware.test.js';
import { layoutServiceMiddlewareTest } from './lib/middlewares/layouts/layoutService.middleware.test.js';
import { requestBodyMiddlewareTest } from './lib/middlewares/requestBody.middleware.test.js';

const FRONT_END_PER_TEST_TIMEOUT = 5000; // each front-end test is allowed this timeout
// remaining tests are based on the number of individual tests in each suite
Expand Down Expand Up @@ -166,7 +165,6 @@ suite('All Tests - QCG', { timeout: FRONT_END_TIMEOUT + BACK_END_TIMEOUT }, asyn
suite('LayoutServiceMiddleware test suite', async () => layoutServiceMiddlewareTest());
suite('LayoutIdMiddleware test suite', async () => layoutIdMiddlewareTest());
suite('LayoutOwnerMiddleware test suite', async () => layoutOwnerMiddlewareTest());
suite('RequestBodyMiddleware test suite', async () => requestBodyMiddlewareTest());
});

suite('Controllers - Test Suite', async () => {
Expand Down

0 comments on commit cf12d57

Please sign in to comment.