Skip to content

Commit

Permalink
PIMS-2086: Remove getPIDs function (#2677)
Browse files Browse the repository at this point in the history
Co-authored-by: dbarkowsky <dylanbarkowsky@gmail.com>
  • Loading branch information
LawrenceLau2020 and dbarkowsky committed Sep 17, 2024
1 parent b070b2a commit 0e958e1
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 106 deletions.
12 changes: 0 additions & 12 deletions express-api/src/controllers/tools/toolsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
31 changes: 0 additions & 31 deletions express-api/src/routes/tools.swagger.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 1 addition & 2 deletions express-api/src/routes/toolsRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
25 changes: 0 additions & 25 deletions express-api/src/services/geocoder/geocoderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
10 changes: 0 additions & 10 deletions express-api/tests/unit/controllers/tools/toolsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
MockRes,
getRequestHandlerMocks,
produceEmailStatus,
produceGeocoderAddress,
producePidsResponse,
} from '../../../testUtils/factories';
import { randomUUID } from 'crypto';

Expand Down Expand Up @@ -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;

Expand Down
26 changes: 0 additions & 26 deletions express-api/tests/unit/services/geocoder/geocoderService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

0 comments on commit 0e958e1

Please sign in to comment.