Skip to content

Commit

Permalink
feat(DTFS2-7052): fixed lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
avaitonis committed Apr 10, 2024
1 parent 14a6a08 commit 17fea54
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 121 deletions.
9 changes: 6 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
"plugin:eslint-comments/recommended",
"plugin:optimize-regex/recommended",
"plugin:switch-case/recommended",
"plugin:security/recommended",
"plugin:security/recommended-legacy",
"plugin:import/recommended",
"plugin:import/typescript",
"prettier"
],
"parserOptions": {
"project": "tsconfig.json",
"ecmaVersion": 2020,
"ecmaVersion": "latest",
"sourceType": "module"
},
"env": {
Expand Down Expand Up @@ -110,7 +110,10 @@
"consistent-return": "off",
"no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": "error",
"unused-imports/no-unused-vars": [
"error",
{ "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
],
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "off",
Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const defaultSettings = {
'@ukef/config/(.*)': '<rootDir>/../src/config/$1',
'@ukef/database/(.*)': '<rootDir>/../src/modules/database/$1',
'@ukef/helpers/(.*)': '<rootDir>/../src/helpers/$1',
'@ukef/helper-modules/(.*)': '<rootDir>/../src/helper-modules/$1',
'@ukef/modules/(.*)': '<rootDir>/../src/modules/$1',
'@ukef/auth/(.*)': '<rootDir>/../src/modules/auth/$1',
'@ukef/(.*)': '<rootDir>/../src/$1',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
export type GetAddressResponse = {
header: {
uri: string;
query: string;
offset: number;
totalresults: number;
format: string;
dataset: string;
lr: string;
maxresults: number;
epoch: string;
lastupdate: string;
output_srs: string;
};
results?: GetAddressResponseItem[];
};

interface GetAddressResponseItem {
DPA: GetAddressResponseAddress;
}

interface GetAddressResponseAddress {
UPRN: string;
UDPRN: string;
ADDRESS: string;
BUILDING_NAME?: string;
BUILDING_NUMBER?: string;
ORGANISATION_NAME?: string;
DEPENDENT_LOCALITY?: string;
THOROUGHFARE_NAME: string;
POST_TOWN: string;
POSTCODE: string;
RPC: string;
X_COORDINATE: number;
Y_COORDINATE: number;
STATUS: string;
LOGICAL_STATUS_CODE: string;
CLASSIFICATION_CODE: string;
CLASSIFICATION_CODE_DESCRIPTION: string;
LOCAL_CUSTODIAN_CODE: number;
LOCAL_CUSTODIAN_CODE_DESCRIPTION: string;
COUNTRY_CODE: string;
COUNTRY_CODE_DESCRIPTION: string;
POSTAL_ADDRESS_CODE: string;
POSTAL_ADDRESS_CODE_DESCRIPTION: string;
BLPU_STATE_CODE: string;
BLPU_STATE_CODE_DESCRIPTION: string;
TOPOGRAPHY_LAYER_TOID: string;
LAST_UPDATE_DATE: string;
ENTRY_DATE: string;
BLPU_STATE_DATE: string;
LANGUAGE: string;
MATCH: number;
MATCH_DESCRIPTION: string;
DELIVERY_POINT_SUFFIX: string;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { OrdnanceSurveyConfig, KEY as ORDNANCE_SURVEY_CONFIG_KEY } from '@ukef/config/ordnance-survey.config';
import { KEY as ORDNANCE_SURVEY_CONFIG_KEY, OrdnanceSurveyConfig } from '@ukef/config/ordnance-survey.config';
import { HttpModule } from '@ukef/modules/http/http.module';

import { OrdnanceSurveyService } from './ordnance-survey.service';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { HttpService } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
import { RandomValueGenerator } from '@ukef-test/support/generator/random-value-generator';
import { AxiosError } from 'axios';
import { when } from 'jest-when';
import { of, throwError } from 'rxjs';
import expectedResponse = require('./examples/example-response-for-search-places-v1-postcode.json');
import noResultsResponse = require('./examples/example-response-for-search-places-v1-postcode-no-results.json');

import { OrdnanceSurveyException } from './exception/ordnance-survey.exception';
import { OrdnanceSurveyService } from './ordnance-survey.service';
import { ConfigService } from '@nestjs/config';

const expectedResponse = require('./examples/example-response-for-search-places-v1-postcode.json');
const noResultsResponse = require('./examples/example-response-for-search-places-v1-postcode.json');

describe('OrdnanceSurveyService', () => {
const valueGenerator = new RandomValueGenerator();
Expand All @@ -19,7 +18,7 @@ describe('OrdnanceSurveyService', () => {
let service: OrdnanceSurveyService;

const testPostcode = 'W1A 1AA';
const testKey = valueGenerator.string({length: 10});
const testKey = valueGenerator.string({ length: 10 });
const basePath = '/search/places/v1/postcode';

beforeEach(() => {
Expand All @@ -28,16 +27,14 @@ describe('OrdnanceSurveyService', () => {
httpServiceGet = jest.fn();
httpService.get = httpServiceGet;

configServiceGet = jest.fn().mockReturnValue({key: testKey});
configServiceGet = jest.fn().mockReturnValue({ key: testKey });
configService.get = configServiceGet;

service = new OrdnanceSurveyService(httpService, configService);
});



describe('getAddressesByPostcode', () => {
const expectedPath = `${basePath}?postcode=${testPostcode}&key=${testKey}`;
const expectedPath = `${basePath}?postcode=${encodeURIComponent(testPostcode)}&key=${encodeURIComponent(testKey)}`;

const expectedHttpServiceGetArgs: [string, object] = [expectedPath, { headers: { 'Content-Type': 'application/json' } }];

Expand Down Expand Up @@ -70,9 +67,8 @@ describe('OrdnanceSurveyService', () => {
expectedUrlQueryPart: '?postcode=W1A1AA',
},
])('call Ordnance Survey API with correct and safe query parameters "$expectedUrlQueryPart"', async ({ postcode, expectedUrlQueryPart }) => {
// const expectedPath = `${basePath}${expectedUrlQueryPart}&key=${testKey}`;

// const expectedHttpServiceGetArgs: [string, object] = [expectedPath, { headers: { 'Content-Type': 'application/json' } }];
const expectedPath = `${basePath}${expectedUrlQueryPart}&key=${encodeURIComponent(testKey)}`;
const expectedHttpServiceGetArgs: [string, object] = [expectedPath, { headers: { 'Content-Type': 'application/json' } }];

when(httpServiceGet)
.calledWith(...expectedHttpServiceGetArgs)
Expand All @@ -86,13 +82,13 @@ describe('OrdnanceSurveyService', () => {
}),
);

await service.getAddressesByPostcode(testPostcode);
await service.getAddressesByPostcode(postcode);

expect(httpServiceGet).toHaveBeenCalledTimes(1);
expect(httpServiceGet).toHaveBeenCalledWith(...expectedHttpServiceGetArgs);
});

it("no results - returns 200 without results", async () => {
it('no results - returns 200 without results', async () => {
when(httpServiceGet)
.calledWith(...expectedHttpServiceGetArgs)
.mockReturnValueOnce(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { HttpService } from '@nestjs/axios';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { KEY as ORDNANCE_SURVEY_CONFIG_KEY, OrdnanceSurveyConfig } from '@ukef/config/ordnance-survey.config';
import { HttpClient } from '@ukef/modules/http/http.client';

import { GetAddressResponse } from './dto/get-addresses-response.dto';
// import { getCustomersNotFoundKnownOrdnanceSurveyError } from './known-errors';
import { createWrapOrdnanceSurveyHttpGetErrorCallback } from './wrap-ordnance-survey-http-error-callback';
import { ConfigService } from '@nestjs/config';
import { OrdnanceSurveyConfig, KEY as ORDNANCE_SURVEY_CONFIG_KEY } from '@ukef/config/ordnance-survey.config';

@Injectable()
export class OrdnanceSurveyService {
Expand All @@ -20,7 +20,8 @@ export class OrdnanceSurveyService {
}

async getAddressesByPostcode(postcode): Promise<GetAddressResponse> {
const path = '/search/places/v1/postcode?postcode=' + postcode + '&key=' + this.key;
const path = `/search/places/v1/postcode?postcode=${encodeURIComponent(postcode)}&key=${encodeURIComponent(this.key)}`;

const { data } = await this.httpClient.get<GetAddressResponse>({
path,
headers: { 'Content-Type': 'application/json' },
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { Matches, MaxLength, MinLength } from 'class-validator';

const UK_POSTCODE = /^[A-Za-z]{1,2}[0-9Rr][0-9A-Za-z]?\s?[0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}$/;
const UK_POSTCODE = /^[A-Za-z]{1,2}[\dRr][\dA-Za-z]?\s?\d[ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}$/;

export class GetAddressByPostcodeQueryDto {
@ApiProperty({
Expand All @@ -13,4 +13,3 @@ export class GetAddressByPostcodeQueryDto {
@Matches(UK_POSTCODE)
public postcode: string;
}

8 changes: 4 additions & 4 deletions src/modules/geospatial/geospatial.controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { BadRequestException, Controller, Get, Query } from '@nestjs/common';
import { Controller, Get, Query } from '@nestjs/common';
import { ApiNotFoundResponse, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';

import { GetSearchPostcodeOrdnanceSurveyQueryDto } from '@ukef/helper-modules/ordnance-survey/dto/get-search-postcode-query.dto';
import { GeospatialService } from './geospatial.service';
import { GetAddressByPostcodeQueryDto } from './dto/get-address-by-postcode-query.dto';
import { GetSearchAddressesResponse, GetSearchAddressesResponseItem } from './dto/get-search-addresses-response.dto';
import { GeospatialService } from './geospatial.service';

@ApiTags('geospatial')
@Controller('geospatial')
Expand All @@ -17,7 +16,8 @@ export class GeospatialController {
})
@ApiResponse({
status: 200,
description: 'AddressBase® Premium Basic Land and Property Units (BLPUs) can reference two types of address and with the OS Places API it is possible to search for one at a time, or both. These are the Delivery Point Address (DPA) and the Land and Property Identifier (LPI).',
description:
'AddressBase® Premium Basic Land and Property Units (BLPUs) can reference two types of address and with the OS Places API it is possible to search for one at a time, or both. These are the Delivery Point Address (DPA) and the Land and Property Identifier (LPI).',
type: [GetSearchAddressesResponseItem],
})
@ApiNotFoundResponse({
Expand Down
5 changes: 2 additions & 3 deletions src/modules/geospatial/geospatial.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ export class GeospatialService {
constructor(private readonly ordnanceSurveyService: OrdnanceSurveyService) {}

async getAddressesByPostcode(postcode: string): Promise<GetSearchAddressesResponse> {
let addresses = [];
const addresses = [];
const response = await this.ordnanceSurveyService.getAddressesByPostcode(postcode);

response.results.forEach((item) => {
// if (item.DPA.LANGUAGE === (req.query.language ? req.query.language : 'EN')) {
// Ordnance survey sends duplicated results with the welsh version too via 'CY'
if (item.DPA.LANGUAGE === 'EN') {
// Ordnance survey sends duplicated results with the welsh version too via 'CY'

addresses.push({
organisationName: item.DPA.ORGANISATION_NAME || null,
addressLine1: `${item.DPA.BUILDING_NAME || ''} ${item.DPA.BUILDING_NUMBER || ''} ${item.DPA.THOROUGHFARE_NAME || ''}`.trim(),
Expand Down
6 changes: 6 additions & 0 deletions src/modules/mdm.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Module } from '@nestjs/common';
import { AuthModule } from '@ukef/auth/auth.module';
import { DatabaseModule } from '@ukef/database/database.module';
import { OrdnanceSurveyModule } from '@ukef/helper-modules/ordnance-survey/ordnance-survey.module';
import { CurrenciesModule } from '@ukef/modules/currencies/currencies.module';
import { CustomersModule } from '@ukef/modules/customers/customers.module';
import { ExposurePeriodModule } from '@ukef/modules/exposure-period/exposure-period.module';
import { GeospatialModule } from '@ukef/modules/geospatial/geospatial.module';
import { HealthcheckModule } from '@ukef/modules/healthcheck/healthcheck.module';
import { InterestRatesModule } from '@ukef/modules/interest-rates/interest-rates.module';
import { MarketsModule } from '@ukef/modules/markets/markets.module';
Expand All @@ -26,6 +28,8 @@ import { YieldRatesModule } from '@ukef/modules/yield-rates/yield-rates.module';
PremiumSchedulesModule,
SectorIndustriesModule,
YieldRatesModule,
OrdnanceSurveyModule,
GeospatialModule,
],
exports: [
AuthModule,
Expand All @@ -40,6 +44,8 @@ import { YieldRatesModule } from '@ukef/modules/yield-rates/yield-rates.module';
PremiumSchedulesModule,
SectorIndustriesModule,
YieldRatesModule,
OrdnanceSurveyModule,
GeospatialModule,
],
})
export class MdmModule {}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@ukef/config/*": ["src/config/*"],
"@ukef/database/*": ["src/modules/database/*"],
"@ukef/helpers/*": ["src/helpers/*"],
"@ukef/helper-modules/*": ["src/helper-modules/*"],
"@ukef/modules/*": ["src/modules/*"],
"@ukef/auth/*": ["src/modules/auth/*"],
"@ukef/swagger/*": ["src/swagger"],
Expand All @@ -41,7 +42,7 @@
"include": [
"src",
"test",
"jest.config.ts"
"jest.config.ts",
],
"exclude": [
"node_modules",
Expand Down

0 comments on commit 17fea54

Please sign in to comment.