Skip to content

Commit

Permalink
linting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TaylorFries committed Feb 21, 2024
1 parent 578e9a6 commit bad6179
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 48 deletions.
42 changes: 21 additions & 21 deletions express-api/src/services/parcels/parcelServices.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
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);

/**
* @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);
}
}
try {
const findParcel = await parcelRepo.findOne({
where: { Id: parcelId },
});
return findParcel;
} catch (e) {
throw new ErrorWithCode(e.message, e.status);
}
};
12 changes: 6 additions & 6 deletions express-api/tests/testUtils/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -227,6 +227,6 @@ export const produceParcel = (): Parcel => {
CreatedById: undefined,
CreatedBy: undefined,
UpdatedById: undefined,
UpdatedBy: undefined
}
}
UpdatedBy: undefined,
};
};
40 changes: 19 additions & 21 deletions express-api/tests/unit/services/parcels/parcelsService.test.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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();
});

});
});

0 comments on commit bad6179

Please sign in to comment.