Skip to content

Commit

Permalink
adding tests for geocoderService
Browse files Browse the repository at this point in the history
  • Loading branch information
TaylorFries committed Feb 16, 2024
1 parent fabc1c1 commit b8c4eaf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions express-api/src/services/geocoder/geocoderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const mapFeatureToAddress = (feature: IFeatureModel): IAddressModel => {
* @returns address information matching IAddressModel format
* @throws ErrorWithCode if the response is not 200 OK
*/
export const getSiteAddressesAsync = async (address: string) => {
export const getSiteAddresses = async (address: string) => {
const url = new URL('/addresses.json', constants.GEOCODER.HOSTURI);
url.searchParams.append('addressString', address);

Expand All @@ -53,7 +53,7 @@ export const getSiteAddressesAsync = async (address: string) => {
* @returns Valid 'siteId' values for an address
* @throws ErrorWithCode if result is not 200 OK
*/
const getPids = async (siteId: string) => {
export const getPids = async (siteId: string) => {
const url = new URL('/parcels/pids/'.concat(siteId).concat('.json'), constants.GEOCODER.HOSTURI);
const result = await fetch(url.toString(), {
headers: {
Expand All @@ -71,6 +71,6 @@ const getPids = async (siteId: string) => {
};

export const GeocoderService = {
getSiteAddressesAsync,
getSiteAddresses,
getPids,
};
23 changes: 23 additions & 0 deletions express-api/tests/unit/services/geocoder/geocoderService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import { AppDataSource } from "@/appDataSource";
import { GeocoderService } from "@/services/geocoder/geocoderService";

describe('UNIT - Geoserver services', () => {
describe('getSiteAddresses', () => {
it('should get an address from Geocoder service.', async () => {
const address = await GeocoderService.getSiteAddresses('4000 Seymour pl BC');
expect(typeof(address) === 'object' &&
!Array.isArray(address) &&
address !== null ).toBe(true);
expect(address.siteId != '').toBe(true);
});
});

describe('getPids', () => {
it('should get a list of PIDs connected to the site address.', async () => {
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);
});
});
})

0 comments on commit b8c4eaf

Please sign in to comment.