Skip to content

Commit

Permalink
feat(cb2-11925): remove /*/enquiry from path
Browse files Browse the repository at this point in the history
  • Loading branch information
naathanbrown committed Jun 7, 2024
1 parent 0ac1be7 commit a2d442b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 57 deletions.
30 changes: 15 additions & 15 deletions application/enquiry/src/infrastructure/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { SecretsManager } from '@aws-sdk/client-secrets-manager';
import express, { Request, Router } from 'express';
import mysql from 'mysql2/promise';
import moment from 'moment';
import vehicleQueryFunctionFactory from '../../app/vehicleQueryFunctionFactory';
import mysql from 'mysql2/promise';
import evlFeedQueryFunctionFactory from '../../app/evlFeedQueryFunctionFactory';
import testResultsQueryFunctionFactory from '../../app/testResultsQueryFunctionFactory';
import { getResultsDetails, getVehicleDetails, getFeedDetails } from '../../domain/enquiryService';
import tflFeedQueryFunctionFactory from '../../app/tflFeedQueryFunctionFactory';
import vehicleQueryFunctionFactory from '../../app/vehicleQueryFunctionFactory';
import { getFeedDetails, getResultsDetails, getVehicleDetails } from '../../domain/enquiryService';
import NotFoundError from '../../errors/NotFoundError';
import ParametersError from '../../errors/ParametersError';
import EvlEvent from '../../interfaces/EvlEvent';
import { FeedName } from '../../interfaces/FeedTypes';
import ResultsEvent from '../../interfaces/ResultsEvent';
import SecretsManagerServiceInterface from '../../interfaces/SecretsManagerService';
import VehicleEvent from '../../interfaces/VehicleEvent';
import EvlEvent from '../../interfaces/EvlEvent';
import EvlFeedData from '../../interfaces/queryResults/evlFeedData';
import TflFeedData from '../../interfaces/queryResults/tflFeedData';
import logger from '../../utils/logger';
import { processTFLFeedData } from '../../utils/tflHelpers';
import DatabaseService from '../databaseService';
import SecretsManagerService from '../secretsManagerService';
import NotFoundError from '../../errors/NotFoundError';
import SecretsManagerServiceInterface from '../../interfaces/SecretsManagerService';
import LocalSecretsManagerService from '../localSecretsManagerService';
import evlFeedQueryFunctionFactory from '../../app/evlFeedQueryFunctionFactory';
import { uploadToS3 } from '../s3BucketService';
import logger from '../../utils/logger';
import tflFeedQueryFunctionFactory from '../../app/tflFeedQueryFunctionFactory';
import { processTFLFeedData } from '../../utils/tflHelpers';
import { FeedName } from '../../interfaces/FeedTypes';
import EvlFeedData from '../../interfaces/queryResults/evlFeedData';
import TflFeedData from '../../interfaces/queryResults/tflFeedData';
import SecretsManagerService from '../secretsManagerService';

const app = express();
const router: Router = express.Router();
Expand Down Expand Up @@ -216,6 +216,6 @@ router.all('*', (_request, res) => {
res.status(404).send();
});

app.use('/*/enquiry/', router);
app.use('/', router);

export { app };
8 changes: 4 additions & 4 deletions application/enquiry/tests/unit/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { APIGatewayEvent, Context } from 'aws-lambda';
import Version from '../../local/data/version.json';
import { handler } from '../../src/handler';
import * as Utils from '../../src/utils';
import Version from '../../local/data/version.json';

describe('Application entry', () => {
const OLD_ENV = process.env;
Expand All @@ -25,7 +25,7 @@ describe('Application entry', () => {

describe('Handler', () => {
it('should call the express wrapper', async () => {
event = { body: 'Test Body', path: '/v1/enquiry/' };
event = { body: 'Test Body', path: '/' };

const response = await handler(event, context);
expect(response.statusCode).toEqual(200);
Expand All @@ -35,7 +35,7 @@ describe('Application entry', () => {
describe('when the service is running', () => {
describe('without proxy', () => {
it("should return a body response when the handler has event with the '/' as path", async () => {
event = { httpMethod: 'GET', path: '/v1/enquiry/' };
event = { httpMethod: 'GET', path: '/' };

const response = await handler(event, context);
const parsedBody = JSON.parse(response.body ?? '') as { ok: boolean };
Expand All @@ -61,7 +61,7 @@ describe('Application entry', () => {
it("should call the service/lambda when the path contains '/version' and return the app version following the semver convention", async () => {
event = {
...Version,
path: '/v1/enquiry/version',
path: '/version',
};

const response = await handler(event, context);
Expand Down
76 changes: 38 additions & 38 deletions application/enquiry/tests/unit/infrastructure/api/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import supertest from 'supertest';
import { app } from '../../../../src/infrastructure/api';
import * as enquiryService from '../../../../src/domain/enquiryService';
import NotFoundError from '../../../../src/errors/NotFoundError';
import ParametersError from '../../../../src/errors/ParametersError';
import { app } from '../../../../src/infrastructure/api';
import DatabaseService from '../../../../src/infrastructure/databaseService';
import VehicleDetails from '../../../../src/interfaces/queryResults/technical/vehicleDetails';
import * as upload from '../../../../src/infrastructure/s3BucketService';
import DatabaseServiceInterface from '../../../../src/interfaces/DatabaseService';
import ParametersError from '../../../../src/errors/ParametersError';
import TestResult from '../../../../src/interfaces/queryResults/test/testResult';
import NotFoundError from '../../../../src/errors/NotFoundError';
import EvlFeedData from '../../../../src/interfaces/queryResults/evlFeedData';
import * as upload from '../../../../src/infrastructure/s3BucketService';
import VehicleDetails from '../../../../src/interfaces/queryResults/technical/vehicleDetails';
import TestResult from '../../../../src/interfaces/queryResults/test/testResult';
import TflFeedData from '../../../../src/interfaces/queryResults/tflFeedData';

// TODO Define Mock strategy
Expand All @@ -19,7 +19,7 @@ describe('API', () => {

describe('GET', () => {
it("should return '{ok: true}' when hitting '/' route", async () => {
const result = await supertest(app).get('/v1/enquiry/');
const result = await supertest(app).get('/');
const resultContent = JSON.parse(result.text) as { ok: boolean };

expect(result.status).toEqual(200);
Expand All @@ -28,7 +28,7 @@ describe('API', () => {
});

it(`should return '{version: ${process.env.API_VERSION}}' when hitting '/version' route`, async () => {
const result = await supertest(app).get('/v1/enquiry/version');
const result = await supertest(app).get('/version');
const resultContent = JSON.parse(result.text) as { version: string };

expect(result.status).toEqual(200);
Expand All @@ -37,7 +37,7 @@ describe('API', () => {
});

it('returns a 404 if the method is not supported', async () => {
const resultPost = await supertest(app).post('/v1/enquiry/not-a-route');
const resultPost = await supertest(app).post('/not-a-route');

expect(resultPost.status).toEqual(404);
});
Expand All @@ -53,7 +53,7 @@ describe('API', () => {
};
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getVehicleDetails').mockResolvedValue(vehicleDetails as VehicleDetails);
const result = await supertest(app).get('/v1/enquiry/vehicle?vinNumber=123456789');
const result = await supertest(app).get('/vehicle?vinNumber=123456789');
const resultContent = JSON.parse(result.text) as VehicleDetails;

expect(resultContent.vin).toEqual('vin1');
Expand All @@ -62,31 +62,31 @@ describe('API', () => {
it('returns the error message if there is an error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getVehicleDetails').mockRejectedValue(new Error('This is an error'));
const result = await supertest(app).get('/v1/enquiry/vehicle?vinNumber=123456789');
const result = await supertest(app).get('/vehicle?vinNumber=123456789');

expect(result.text).toEqual('This is an error');
});

it('sets the status to 400 for a parameters error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getVehicleDetails').mockRejectedValue(new ParametersError('This is an error'));
const result = await supertest(app).get('/v1/enquiry/vehicle?vinNumber=123456789');
const result = await supertest(app).get('/vehicle?vinNumber=123456789');

expect(result.status).toEqual(400);
});

it('sets the status to 404 for a not found error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getVehicleDetails').mockRejectedValue(new NotFoundError());
const result = await supertest(app).get('/v1/enquiry/vehicle?vinNumber=123456789');
const result = await supertest(app).get('/vehicle?vinNumber=123456789');

expect(result.status).toEqual(404);
});

it('sets the status to 500 for a generic error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getVehicleDetails').mockRejectedValue(new Error('This is an error'));
const result = await supertest(app).get('/v1/enquiry/vehicle?vinNumber=123456789');
const result = await supertest(app).get('/vehicle?vinNumber=123456789');

expect(result.status).toEqual(500);
});
Expand All @@ -95,25 +95,25 @@ describe('API', () => {
process.env.IS_OFFLINE = 'true';
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getVehicleDetails').mockRejectedValue(new Error('This is an error'));
const result = await supertest(app).get('/v1/enquiry/vehicle?vinNumber=123456789');
const result = await supertest(app).get('/vehicle?vinNumber=123456789');

expect(result.status).toEqual(500);
});

it('returns a 405 if the method is not supported', async () => {
const resultPost = await supertest(app).post('/v1/enquiry/vehicle?vinNumber=123456789');
const resultPost = await supertest(app).post('/vehicle?vinNumber=123456789');

expect(resultPost.status).toEqual(405);

const resultPut = await supertest(app).put('/v1/enquiry/vehicle?vinNumber=123456789');
const resultPut = await supertest(app).put('/vehicle?vinNumber=123456789');

expect(resultPut.status).toEqual(405);

const resultPatch = await supertest(app).patch('/v1/enquiry/vehicle?vinNumber=123456789');
const resultPatch = await supertest(app).patch('/vehicle?vinNumber=123456789');

expect(resultPatch.status).toEqual(405);

const resultDelete = await supertest(app).delete('/v1/enquiry/vehicle?vinNumber=123456789');
const resultDelete = await supertest(app).delete('/vehicle?vinNumber=123456789');

expect(resultDelete.status).toEqual(405);
});
Expand All @@ -126,7 +126,7 @@ describe('API', () => {
} as TestResult;
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getResultsDetails').mockResolvedValue([resultDetails]);
const result = await supertest(app).get('/v1/enquiry/testResults?vinNumber=123456789');
const result = await supertest(app).get('/testResults?vinNumber=123456789');
const resultContent = JSON.parse(result.text) as [TestResult];

expect(resultContent[0].testStatus).toEqual('Success');
Expand All @@ -135,49 +135,49 @@ describe('API', () => {
it('returns the error message if there is an error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getResultsDetails').mockRejectedValue(new Error('This is an error'));
const result = await supertest(app).get('/v1/enquiry/testResults?vinNumber=123456789');
const result = await supertest(app).get('/testResults?vinNumber=123456789');

expect(result.text).toEqual('This is an error');
});

it('sets the status to 400 for a parameters error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getResultsDetails').mockRejectedValue(new ParametersError('This is an error'));
const result = await supertest(app).get('/v1/enquiry/testResults?vinNumber=123456789');
const result = await supertest(app).get('/testResults?vinNumber=123456789');

expect(result.status).toEqual(400);
});

it('sets the status to 404 for a not found error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getResultsDetails').mockRejectedValue(new NotFoundError('This is an error'));
const result = await supertest(app).get('/v1/enquiry/testResults?vinNumber=123456789');
const result = await supertest(app).get('/testResults?vinNumber=123456789');

expect(result.status).toEqual(404);
});

it('sets the status to 500 for a generic error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getResultsDetails').mockRejectedValue(new Error('This is an error'));
const result = await supertest(app).get('/v1/enquiry/testResults?vinNumber=123456789');
const result = await supertest(app).get('/testResults?vinNumber=123456789');

expect(result.status).toEqual(500);
});

it('returns a 405 if the method is not supported', async () => {
const resultPost = await supertest(app).post('/v1/enquiry/testResults?vinNumber=123456789');
const resultPost = await supertest(app).post('/testResults?vinNumber=123456789');

expect(resultPost.status).toEqual(405);

const resultPut = await supertest(app).put('/v1/enquiry/testResults?vinNumber=123456789');
const resultPut = await supertest(app).put('/testResults?vinNumber=123456789');

expect(resultPut.status).toEqual(405);

const resultPatch = await supertest(app).patch('/v1/enquiry/testResults?vinNumber=123456789');
const resultPatch = await supertest(app).patch('/testResults?vinNumber=123456789');

expect(resultPatch.status).toEqual(405);

const resultDelete = await supertest(app).delete('/v1/enquiry/testResults?vinNumber=123456789');
const resultDelete = await supertest(app).delete('/testResults?vinNumber=123456789');

expect(resultDelete.status).toEqual(405);
});
Expand All @@ -193,38 +193,38 @@ describe('API', () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(upload, 'uploadToS3').mockImplementation((_data, _fileName, callback) => new Promise((resolve) => resolve(callback())));
jest.spyOn(enquiryService, 'getFeedDetails').mockResolvedValue([evlFeedData]);
const result = await supertest(app).get('/v1/enquiry/evl');
const result = await supertest(app).get('/evl');
expect(result.status).toEqual(200);
});

it('returns the error message if there is an error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getFeedDetails').mockRejectedValue(new Error('This is an error'));
const result = await supertest(app).get('/v1/enquiry/evl');
const result = await supertest(app).get('/evl');

expect(result.text).toEqual('Error Generating EVL Feed Data: This is an error');
});

it('sets the status to 400 for a parameters error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getFeedDetails').mockRejectedValue(new ParametersError('This is an error'));
const result = await supertest(app).get('/v1/enquiry/evl');
const result = await supertest(app).get('/evl');

expect(result.status).toEqual(400);
});

it('sets the status to 404 for a not found error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getFeedDetails').mockRejectedValue(new NotFoundError('This is an error'));
const result = await supertest(app).get('/v1/enquiry/evl');
const result = await supertest(app).get('/evl');

expect(result.status).toEqual(404);
});

it('sets the status to 500 for a generic error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getFeedDetails').mockRejectedValue(new Error('This is an error'));
const result = await supertest(app).get('/v1/enquiry/evl');
const result = await supertest(app).get('/evl');

expect(result.status).toEqual(500);
});
Expand All @@ -247,22 +247,22 @@ describe('API', () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(upload, 'uploadToS3').mockImplementation((_data, _fileName, callback) => new Promise((resolve) => resolve(callback())));
jest.spyOn(enquiryService, 'getFeedDetails').mockResolvedValue([tflFeedData]);
const result = await supertest(app).get('/v1/enquiry/tfl');
const result = await supertest(app).get('/tfl');
expect(result.status).toEqual(200);
});

it('returns the error message if there is an error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getFeedDetails').mockRejectedValue(new Error('This is an error'));
const result = await supertest(app).get('/v1/enquiry/tfl');
const result = await supertest(app).get('/tfl');

expect(result.text).toEqual('Error Generating TFL Feed Data: This is an error');
});

it('sets the status to 400 for a parameters error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getFeedDetails').mockRejectedValue(new ParametersError('This is an error'));
const result = await supertest(app).get('/v1/enquiry/tfl');
const result = await supertest(app).get('/tfl');

expect(result.status).toEqual(400);
});
Expand All @@ -271,15 +271,15 @@ describe('API', () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(upload, 'uploadToS3').mockImplementation((_data, _fileName, callback) => new Promise((resolve) => resolve(callback())));
jest.spyOn(enquiryService, 'getFeedDetails').mockRejectedValue(new NotFoundError('This is an error'));
const result = await supertest(app).get('/v1/enquiry/tfl');
const result = await supertest(app).get('/tfl');

expect(result.status).toEqual(200);
});

it('sets the status to 500 for a generic error', async () => {
DatabaseService.build = jest.fn().mockResolvedValue({} as DatabaseServiceInterface);
jest.spyOn(enquiryService, 'getFeedDetails').mockRejectedValue(new Error('This is an error'));
const result = await supertest(app).get('/v1/enquiry/tfl');
const result = await supertest(app).get('/tfl');

expect(result.status).toEqual(500);
});
Expand Down

0 comments on commit a2d442b

Please sign in to comment.