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

chore(cb2-11271): upgrade cvs-svc-test-results from aws sdk v2 to v3 #406

Merged
merged 12 commits into from
May 20, 2024
2 changes: 1 addition & 1 deletion src/handlers/VehicleTestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class VehicleTestController implements IVehicleTestController {
} catch (error) {
if (
error.statusCode === 400 &&
error.message === enums.MESSAGES.CONDITIONAL_REQUEST_FAILED
error.body === enums.MESSAGES.CONDITIONAL_REQUEST_FAILED
) {
console.info(
'TestResultService.insertTestResult: Test Result id already exists',
Expand Down
28 changes: 20 additions & 8 deletions src/handlers/expiry/providers/TestDataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConditionalCheckFailedException } from '@aws-sdk/client-dynamodb';
import { ServiceException } from '@smithy/smithy-client';
import * as enums from '../../../assets/Enums';
import * as models from '../../../models';
import { Service } from '../../../models/injector/ServiceDecorator';
Expand Down Expand Up @@ -29,6 +29,12 @@ export class TestDataProvider implements ITestDataProvider {
'TestDataProvider.getTestResultBySystemNumber: error-> ',
error,
);
if (error instanceof ServiceException) {
throw new models.HTTPError(
error.$metadata.httpStatusCode ?? 500,
error.message,
);
}
throw error;
}
}
Expand All @@ -47,6 +53,12 @@ export class TestDataProvider implements ITestDataProvider {
'TestDataProvider.getTestResultBySystemNumber: error-> ',
error,
);
if (error instanceof ServiceException) {
throw new models.HTTPError(
error.$metadata.httpStatusCode ?? 500,
error.message,
);
}
throw error;
}
}
Expand All @@ -73,6 +85,12 @@ export class TestDataProvider implements ITestDataProvider {
);
} catch (error) {
console.log('TestDataProvider.getTestHistory: error -> ', error);
if (error instanceof ServiceException) {
throw new models.HTTPError(
error.$metadata.httpStatusCode ?? 500,
error.message,
);
}
throw error;
}
}
Expand Down Expand Up @@ -242,13 +260,7 @@ export class TestDataProvider implements ITestDataProvider {
return result.Attributes as models.ITestResult[];
} catch (error) {
console.error('TestDataProvider.insertTestResult -> ', error);
if (
error instanceof ConditionalCheckFailedException &&
error.$response?.statusCode
) {
throw new models.HTTPError(error.$response?.statusCode, error.message);
}
throw error;
throw new models.HTTPError(error.$metadata.httpStatusCode, error.message);
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/expiry/TestDataProvider.unitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ describe('TestDataProvider', () => {

it('should throw the error once it fails', async () => {
testDataProvider = new TestDataProvider();
const errorMsg = 'boom';
const error = { $metadata: { httpStatusCode: 400 }, message: 'boom' };
MockTestResultsDAO = jest.fn().mockImplementation(() => ({
createSingle: (something: any) => Promise.reject(errorMsg),
createSingle: (something: any) => Promise.reject(error),
}));

testDataProvider.testResultsDAO = new MockTestResultsDAO();
Expand All @@ -354,7 +354,7 @@ describe('TestDataProvider', () => {
{} as models.ITestResultPayload,
);
} catch (e) {
expect(e).toBe(errorMsg);
expect(e.body).toEqual(error.message);
}
});
});
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/insertTestResult.unitTest.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import fs from 'fs';
import path from 'path';
import { cloneDeep } from 'lodash';
import { TestResultsService } from '../../src/services/TestResultsService';
import { HTTPError } from '../../src/models/HTTPError';
import path from 'path';
import {
MESSAGES,
ERRORS,
VEHICLE_TYPES,
TEST_STATUS,
TEST_RESULT,
MESSAGES,
TESTING_ERRORS,
TEST_RESULT,
TEST_STATUS,
VEHICLE_TYPES,
} from '../../src/assets/Enums';
import { HTTPResponse } from '../../src/models';
import { HTTPError } from '../../src/models/HTTPError';
import { ITestResultPayload } from '../../src/models/ITestResultPayload';
import { HTTPResponse } from '../../src/models/HTTPResponse';
import { TestResultsService } from '../../src/services/TestResultsService';
import { ValidationUtil } from '../../src/utils/validationUtil';

describe('insertTestResult', () => {
Expand Down Expand Up @@ -244,7 +244,7 @@ describe('insertTestResult', () => {
getBySystemNumber: (systemNumber: any) => Promise.resolve([]),
createSingle: () =>
Promise.reject({
statusCode: 400,
$metadata: { httpStatusCode: 400 },
message: MESSAGES.CONDITIONAL_REQUEST_FAILED,
}),
}));
Expand Down
Loading