From bad6179180df14eff3ceff094e62b6908eaf2ff5 Mon Sep 17 00:00:00 2001 From: taylorfries Date: Wed, 21 Feb 2024 08:56:21 -0800 Subject: [PATCH] linting fix --- .../src/services/parcels/parcelServices.ts | 42 +++++++++---------- express-api/tests/testUtils/factories.ts | 12 +++--- .../services/parcels/parcelsService.test.ts | 40 +++++++++--------- 3 files changed, 46 insertions(+), 48 deletions(-) diff --git a/express-api/src/services/parcels/parcelServices.ts b/express-api/src/services/parcels/parcelServices.ts index 430ec6226..412f79d47 100644 --- a/express-api/src/services/parcels/parcelServices.ts +++ b/express-api/src/services/parcels/parcelServices.ts @@ -1,6 +1,6 @@ -import { Parcel } from "@/typeorm/Entities/Parcel"; -import { AppDataSource } from "@/appDataSource"; -import { ErrorWithCode } from "@/utilities/customErrors/ErrorWithCode"; +import { Parcel } from '@/typeorm/Entities/Parcel'; +import { AppDataSource } from '@/appDataSource'; +import { ErrorWithCode } from '@/utilities/customErrors/ErrorWithCode'; const parcelRepo = AppDataSource.getRepository(Parcel); @@ -8,29 +8,29 @@ const parcelRepo = AppDataSource.getRepository(Parcel); * @description Adds a new parcel to the datasource. * @param parcel incoming parcel data to be added to the database * @returns {Response} A 201 status and the data of the role added. - * @throws ErrorWithCode If the parcel already exists or is unable to be added. + * @throws ErrorWithCode If the parcel already exists or is unable to be added. */ export const postParcel = async (parcel: Parcel) => { - const existingParcel = await getParcelById(parcel.Id); - if (existingParcel) { - throw new ErrorWithCode('Parcel already exists', 409); - }; - const newParcel = parcelRepo.save(parcel); - return newParcel; + const existingParcel = await getParcelById(parcel.Id); + if (existingParcel) { + throw new ErrorWithCode('Parcel already exists', 409); + } + const newParcel = parcelRepo.save(parcel); + return newParcel; }; /** - * @description Finds and returns a parcel with matching Id + * @description Finds and returns a parcel with matching Id * @param parcelId Number representing parcel we want to find. - * @returns findParcel Parcel data matching Id passed in. + * @returns findParcel Parcel data matching Id passed in. */ export const getParcelById = async (parcelId: number) => { - try{ - const findParcel = await parcelRepo.findOne({ - where: { Id: parcelId}, - }); - return findParcel; - } catch (e) { - throw new ErrorWithCode(e.message, e.status); - } -} \ No newline at end of file + try { + const findParcel = await parcelRepo.findOne({ + where: { Id: parcelId }, + }); + return findParcel; + } catch (e) { + throw new ErrorWithCode(e.message, e.status); + } +}; diff --git a/express-api/tests/testUtils/factories.ts b/express-api/tests/testUtils/factories.ts index 4adceaa91..694e70427 100644 --- a/express-api/tests/testUtils/factories.ts +++ b/express-api/tests/testUtils/factories.ts @@ -193,20 +193,20 @@ export const produceKeycloak = (): KeycloakUser => { }; export const produceParcel = (): Parcel => { - return { + return { Id: faker.number.int({ max: 10 }), CreatedOn: faker.date.anytime(), UpdatedOn: faker.date.anytime(), Name: faker.string.alphanumeric(), LandLegalDescription: faker.string.alphanumeric(), PID: undefined, - PIN: undefined, + PIN: undefined, LandArea: undefined, Zoning: undefined, ZoningPotential: undefined, NotOwned: undefined, ParentParcelId: undefined, - ParentParcel:undefined, + ParentParcel: undefined, Description: faker.string.alphanumeric(), ClassificationId: undefined, Classification: undefined, @@ -227,6 +227,6 @@ export const produceParcel = (): Parcel => { CreatedById: undefined, CreatedBy: undefined, UpdatedById: undefined, - UpdatedBy: undefined - } -} + UpdatedBy: undefined, + }; +}; diff --git a/express-api/tests/unit/services/parcels/parcelsService.test.ts b/express-api/tests/unit/services/parcels/parcelsService.test.ts index 08869d86f..0b1f59a9d 100644 --- a/express-api/tests/unit/services/parcels/parcelsService.test.ts +++ b/express-api/tests/unit/services/parcels/parcelsService.test.ts @@ -1,8 +1,8 @@ -import { AppDataSource } from "@/appDataSource"; -import { Parcel } from "@/typeorm/Entities/Parcel"; -import { produceParcel } from "tests/testUtils/factories"; -import { DeepPartial } from "typeorm"; -import * as parcelService from "@/services/parcels/parcelServices"; +import { AppDataSource } from '@/appDataSource'; +import { Parcel } from '@/typeorm/Entities/Parcel'; +import { produceParcel } from 'tests/testUtils/factories'; +import { DeepPartial } from 'typeorm'; +import * as parcelService from '@/services/parcels/parcelServices'; //jest.setTimeout(30000); @@ -16,21 +16,19 @@ const _parcelFindOne = jest .spyOn(parcelRepo, 'findOne') .mockImplementation(async () => produceParcel()); - describe('UNIT - Parcel Services', () => { - describe('addParcel', () => { - it('should add a new parcel and return it', async () => { - _parcelFindOne.mockResolvedValueOnce(null); - const parcel = produceParcel(); - const ret = await parcelService.postParcel(parcel); - expect(_parcelSave).toHaveBeenCalledTimes(1); - expect(ret.Id).toBe(parcel.Id); - }); - it('should throw an error if the agency already exists', () => { - const parcel = produceParcel(); - _parcelFindOne.mockResolvedValueOnce(parcel); - expect(async () => await parcelService.postParcel(parcel)).rejects.toThrow(); - }); - +describe('UNIT - Parcel Services', () => { + describe('addParcel', () => { + it('should add a new parcel and return it', async () => { + _parcelFindOne.mockResolvedValueOnce(null); + const parcel = produceParcel(); + const ret = await parcelService.postParcel(parcel); + expect(_parcelSave).toHaveBeenCalledTimes(1); + expect(ret.Id).toBe(parcel.Id); + }); + it('should throw an error if the agency already exists', () => { + const parcel = produceParcel(); + _parcelFindOne.mockResolvedValueOnce(parcel); + expect(async () => await parcelService.postParcel(parcel)).rejects.toThrow(); }); - }); +});