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

PIMS-2086: Remove getPIDs function #2677

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 1 addition & 4 deletions express-api/src/routes/toolsRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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;
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
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();
});
});
});
Loading