From 96a1a9b1d3c30ada80b222dc9712dad8d6d31f07 Mon Sep 17 00:00:00 2001 From: Lawrence Lau Date: Fri, 13 Sep 2024 10:46:12 -0700 Subject: [PATCH 1/5] removing unused functions --- .../src/controllers/tools/toolsController.ts | 12 --------- express-api/src/routes/toolsRouter.ts | 5 +--- .../src/services/geocoder/geocoderService.ts | 25 ------------------- 3 files changed, 1 insertion(+), 41 deletions(-) diff --git a/express-api/src/controllers/tools/toolsController.ts b/express-api/src/controllers/tools/toolsController.ts index 5bd96fe41..0924c0317 100644 --- a/express-api/src/controllers/tools/toolsController.ts +++ b/express-api/src/controllers/tools/toolsController.ts @@ -90,15 +90,3 @@ export const searchGeocoderAddresses = async (req: Request, res: Response) => { const geoReturn = await geocoderService.getSiteAddresses(address, minScore, maxResults); return res.status(200).send(geoReturn); }; - -/** - * @description Search Geocoder for the pid of a certain siteId. - * @param {Request} req Incoming request. - * @param {Response} res Outgoing response. - * @returns {Response} A 200 status with a siteId object. - */ -export const searchGeocoderSiteId = async (req: Request, res: Response) => { - const siteId = String(req.params.siteId); - const result = await geocoderService.getPids(siteId); - return res.status(200).send(result); -}; diff --git a/express-api/src/routes/toolsRouter.ts b/express-api/src/routes/toolsRouter.ts index 0624b4ba7..cebce19fa 100644 --- a/express-api/src/routes/toolsRouter.ts +++ b/express-api/src/routes/toolsRouter.ts @@ -5,11 +5,8 @@ import express from 'express'; const router = express.Router(); -const { searchGeocoderAddresses, searchGeocoderSiteId } = controllers; +const { searchGeocoderAddresses } = controllers; router.route(`/geocoder/addresses`).get(activeUserCheck, catchErrors(searchGeocoderAddresses)); -router - .route(`/geocoder/parcels/pids/:siteId`) - .get(activeUserCheck, catchErrors(searchGeocoderSiteId)); export default router; diff --git a/express-api/src/services/geocoder/geocoderService.ts b/express-api/src/services/geocoder/geocoderService.ts index 29d0249ac..a70352885 100644 --- a/express-api/src/services/geocoder/geocoderService.ts +++ b/express-api/src/services/geocoder/geocoderService.ts @@ -4,7 +4,6 @@ import constants from '@/constants'; import { IFeatureModel } from '@/services/geocoder/interfaces/IFeatureModel'; import { getLongitude, getLatitude, getAddress1 } from './geocoderUtils'; import { ErrorWithCode } from '@/utilities/customErrors/ErrorWithCode'; -import { ISitePidsResponseModel } from './interfaces/ISitePidsResponseModel'; const mapFeatureToAddress = (feature: IFeatureModel): IAddressModel => { return { @@ -55,32 +54,8 @@ export const getSiteAddresses = async ( return addressInformation; }; -/** - * @description Sends a request to Geocoder for all parcel identifiers (PIDs) associated with an individual site. - * @param siteId a unique identifier assigned to every site in B.C. - * @returns Valid 'siteId' values for an address - * @throws ErrorWithCode if result is not 200 OK - */ -export const getPids = async (siteId: string) => { - const url = new URL(`/parcels/pids/${siteId}.json`, constants.GEOCODER.HOSTURI); - const result = await fetch(url.toString(), { - headers: { - apiKey: constants.GEOCODER.KEY, - }, - }); - - if (result.status != 200) { - throw new ErrorWithCode(result.statusText, result.status); - } - - const resultData = await result.json(); - const pidInformation: ISitePidsResponseModel = resultData; - return pidInformation; -}; - const geocoderService = { getSiteAddresses, - getPids, }; export default geocoderService; From f8f915ab0494fafbdd9b46c804a428466d0bf4a2 Mon Sep 17 00:00:00 2001 From: Lawrence Lau Date: Fri, 13 Sep 2024 10:53:45 -0700 Subject: [PATCH 2/5] removing tests --- .../controllers/tools/toolsController.test.ts | 7 ----- .../services/geocoder/geocoderService.test.ts | 26 ------------------- 2 files changed, 33 deletions(-) diff --git a/express-api/tests/unit/controllers/tools/toolsController.test.ts b/express-api/tests/unit/controllers/tools/toolsController.test.ts index c965b8f3e..0626f2c69 100644 --- a/express-api/tests/unit/controllers/tools/toolsController.test.ts +++ b/express-api/tests/unit/controllers/tools/toolsController.test.ts @@ -37,13 +37,6 @@ jest.mock('@/services/ches/chesServices.ts', () => ({ })); const _getSiteAddresses = jest.fn().mockImplementation(() => [produceGeocoderAddress()]); -const _getPids = jest.fn().mockImplementation(() => producePidsResponse()); - -jest.mock('@/services/geocoder/geocoderService', () => ({ - getSiteAddresses: () => _getSiteAddresses(), - getPids: () => _getPids(), -})); - describe('UNIT - Tools', () => { let mockRequest: Request & MockReq, mockResponse: Response & MockRes; diff --git a/express-api/tests/unit/services/geocoder/geocoderService.test.ts b/express-api/tests/unit/services/geocoder/geocoderService.test.ts index cf905b4f5..8448e3d86 100644 --- a/express-api/tests/unit/services/geocoder/geocoderService.test.ts +++ b/express-api/tests/unit/services/geocoder/geocoderService.test.ts @@ -99,30 +99,4 @@ describe('UNIT - Geoserver services', () => { }).rejects.toThrow(); }); }); - - describe('getPids', () => { - const pidData = { - siteID: 'eccd759a-8476-46b0-af5d-e1c071f8e78e', - pids: '000382345', - }; - const stringPids = JSON.stringify(pidData); - - it('should get a list of PIDs connected to the site address.', async () => { - jest - .spyOn(global, 'fetch') - .mockImplementationOnce(() => Promise.resolve(new Response(stringPids))); - const pids = await geocoderService.getPids('eccd759a-8476-46b0-af5d-e1c071f8e78e'); - expect(typeof pids === 'object' && !Array.isArray(pids) && pids !== null).toBe(true); - expect(typeof pids.pids === 'string' && pids.pids === '000382345').toBe(true); - }); - - it('should thow an error if geocoder service is down.', async () => { - jest - .spyOn(global, 'fetch') - .mockImplementationOnce(() => Promise.resolve(new Response('', { status: 500 }))); - expect(async () => { - await geocoderService.getPids(''); - }).rejects.toThrow(); - }); - }); }); From 6285f4b9b8960a1234d3f368cd2ed61104dec95a Mon Sep 17 00:00:00 2001 From: Lawrence Lau Date: Fri, 13 Sep 2024 10:56:41 -0700 Subject: [PATCH 3/5] fixing lint issue --- .../tests/unit/controllers/tools/toolsController.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/express-api/tests/unit/controllers/tools/toolsController.test.ts b/express-api/tests/unit/controllers/tools/toolsController.test.ts index 0626f2c69..2eaff1fe2 100644 --- a/express-api/tests/unit/controllers/tools/toolsController.test.ts +++ b/express-api/tests/unit/controllers/tools/toolsController.test.ts @@ -6,7 +6,6 @@ import { getRequestHandlerMocks, produceEmailStatus, produceGeocoderAddress, - producePidsResponse, } from '../../../testUtils/factories'; import { randomUUID } from 'crypto'; @@ -36,7 +35,6 @@ jest.mock('@/services/ches/chesServices.ts', () => ({ sendEmailAsync: () => _sendEmailAsync(), })); -const _getSiteAddresses = jest.fn().mockImplementation(() => [produceGeocoderAddress()]); describe('UNIT - Tools', () => { let mockRequest: Request & MockReq, mockResponse: Response & MockRes; From 10f3ef392b16c855eedd0eae298f7e258f77cec7 Mon Sep 17 00:00:00 2001 From: Lawrence Lau Date: Fri, 13 Sep 2024 11:00:26 -0700 Subject: [PATCH 4/5] fixing another lint issue --- express-api/tests/unit/controllers/tools/toolsController.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/express-api/tests/unit/controllers/tools/toolsController.test.ts b/express-api/tests/unit/controllers/tools/toolsController.test.ts index 2eaff1fe2..bb4e5b259 100644 --- a/express-api/tests/unit/controllers/tools/toolsController.test.ts +++ b/express-api/tests/unit/controllers/tools/toolsController.test.ts @@ -5,7 +5,6 @@ import { MockRes, getRequestHandlerMocks, produceEmailStatus, - produceGeocoderAddress, } from '../../../testUtils/factories'; import { randomUUID } from 'crypto'; From 50f2049d6173ee296301a5ba12719c77e2f014ea Mon Sep 17 00:00:00 2001 From: dbarkowsky Date: Fri, 13 Sep 2024 11:12:43 -0700 Subject: [PATCH 5/5] update swagger docs --- express-api/src/routes/tools.swagger.yaml | 31 ----------------------- 1 file changed, 31 deletions(-) diff --git a/express-api/src/routes/tools.swagger.yaml b/express-api/src/routes/tools.swagger.yaml index 37c42389e..0d8178fea 100644 --- a/express-api/src/routes/tools.swagger.yaml +++ b/express-api/src/routes/tools.swagger.yaml @@ -1,36 +1,5 @@ ### PATHS ### paths: - /tools/geocoder/parcels/pids/{siteID}: - get: - security: - - bearerAuth: [] - tags: - - Tools - summary: Returns an object with the siteID and a pids property. - description: > - The `pids` property seems to only be a single PID string. - This response comes from the BC Geocoder Service. - Capable of any error code from BC Geocoder. - parameters: - - in: path - name: siteID - schema: - type: string - format: uuid - responses: - '200': - content: - application/json: - schema: - type: object - properties: - siteID: - type: string - format: uuid - pids: - type: string - example: 014128446 - description: Has leading zeroes. Seemingly only one PID despite pluralization. /tools/geocoder/addresses: get: security: