From 0e958e1afebef9cf7d92ff9c65e1e5400de31fbf Mon Sep 17 00:00:00 2001 From: LawrenceLau2020 <68400651+LawrenceLau2020@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:22:46 -0700 Subject: [PATCH] PIMS-2086: Remove getPIDs function (#2677) Co-authored-by: dbarkowsky --- .../src/controllers/tools/toolsController.ts | 12 ------- express-api/src/routes/tools.swagger.yaml | 31 ------------------- express-api/src/routes/toolsRouter.ts | 3 +- .../src/services/geocoder/geocoderService.ts | 25 --------------- .../controllers/tools/toolsController.test.ts | 10 ------ .../services/geocoder/geocoderService.test.ts | 26 ---------------- 6 files changed, 1 insertion(+), 106 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/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: diff --git a/express-api/src/routes/toolsRouter.ts b/express-api/src/routes/toolsRouter.ts index 6d7b8d3f1..9d714f8a1 100644 --- a/express-api/src/routes/toolsRouter.ts +++ b/express-api/src/routes/toolsRouter.ts @@ -4,9 +4,8 @@ import express from 'express'; const router = express.Router(); -const { searchGeocoderAddresses, searchGeocoderSiteId } = controllers; +const { searchGeocoderAddresses } = controllers; router.route(`/geocoder/addresses`).get(catchErrors(searchGeocoderAddresses)); -router.route(`/geocoder/parcels/pids/:siteId`).get(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; diff --git a/express-api/tests/unit/controllers/tools/toolsController.test.ts b/express-api/tests/unit/controllers/tools/toolsController.test.ts index c965b8f3e..bb4e5b259 100644 --- a/express-api/tests/unit/controllers/tools/toolsController.test.ts +++ b/express-api/tests/unit/controllers/tools/toolsController.test.ts @@ -5,8 +5,6 @@ import { MockRes, getRequestHandlerMocks, produceEmailStatus, - produceGeocoderAddress, - producePidsResponse, } from '../../../testUtils/factories'; import { randomUUID } from 'crypto'; @@ -36,14 +34,6 @@ jest.mock('@/services/ches/chesServices.ts', () => ({ sendEmailAsync: () => _sendEmailAsync(), })); -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(); - }); - }); });