-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
efb0ef8
commit 2df94a3
Showing
2 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 23 additions & 4 deletions
27
express-api/tests/unit/services/parcels/parcelsService.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,36 @@ | ||
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); | ||
|
||
const parcelRepo = AppDataSource.getRepository(Parcel); | ||
|
||
const _parcelSave = jest | ||
.spyOn(parcelRepo, 'save') | ||
.mockImplementation(async (parcel: DeepPartial<Parcel> & Parcel) => parcel); | ||
|
||
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', async => { | ||
const parcel = produceParcel(); | ||
_parcelFindOne.mockResolvedValueOnce(parcel); | ||
expect(async () => await parcelService.postParcel(parcel)).rejects.toThrow(); | ||
}); | ||
|
||
}); | ||
|
||
}); |