IM
Size: a a a
VG
VG
RP
RP
AP
BO
RP
RP
RP
HttpException(
Check if Books id's are correct and not a duplicate or Books exist,
HttpStatus.NO
T_FOUND,
);
BO
RP
RP
checkIfBooksExist(books: (
string | ObjectID)[]): Promise<Book[]> {
const ids = books.map(it =>
new ObjectID(it));
const booksExist =
await this.bookRepository.findByIds(ids, {});
if (ids.length !== booksExist.length) {
throw new HttpException(
Check if Books id's are correct and not a duplicate or Books exist,
HttpStatus.NO
T_FOUND,
);
}
return booksExist;
}
RP
BO
RP
Check if Books id's are correct and not a duplicate or Books exist
RP
jest
.spyOn(bookRepository, 'findByIds')
.mockImplementation(
async () =>
await books);
await authorService.checkIfBooksExist(booksIds);
await expect(bookRepository.findByIds).toHaveBeenCalled();
await expect(() => authorService.checkIfBooksExist(booksIds)).toThrow();
});
RP
RP
RP
{
await authorService.checkIfBooksExist(booksIds);
await expect(bookRepository.findByIds).toHaveBeenCalled();
}
catch (e) {
await expect(e).toEqual(
new HttpException(
Check if Books id's are correct and not a duplicate or Books exist,
HttpStatus.NO
T_FOUND,
),
);
}