Skip to content

Commit

Permalink
fix: Handle NotFoundException in ReciterService
Browse files Browse the repository at this point in the history
  • Loading branch information
the-sabra committed Aug 6, 2024
1 parent fdf583b commit 16ca68a
Showing 2 changed files with 10 additions and 13 deletions.
11 changes: 4 additions & 7 deletions src/reciter/reciter.service.spec.ts
Original file line number Diff line number Diff line change
@@ -199,10 +199,9 @@ describe('ReciterService', () => {

it('should throw NotFoundException if tilawa not found', async () => {
jest.spyOn(tilawaRepository, 'findOneBy').mockResolvedValueOnce(null);
const result = service.getReciterTilawaId(1);

await expect(service.getReciterTilawaId(1)).rejects.toThrow(
NotFoundException,
);
expect(result).rejects.toThrow(NotFoundException);
});
});

@@ -224,10 +223,8 @@ describe('ReciterService', () => {

it('should throw NotFoundException if no tilawas found', async () => {
jest.spyOn(tilawaRepository, 'find').mockResolvedValue([]);

await expect(service.getReciterTilawa(1)).rejects.toThrow(
NotFoundException,
);
const result = service.getReciterTilawa(1);
await expect(result).rejects.toThrow(NotFoundException);
});
});

12 changes: 6 additions & 6 deletions src/reciter/reciter.service.ts
Original file line number Diff line number Diff line change
@@ -76,15 +76,15 @@ export class ReciterService {
const tilawa = await this.tilawaRepository.find({
where: { reciter_id: reciterId },
});

if (!tilawa) throw new NotFoundException('Tilawa not found');

if (!tilawa.length) throw new NotFoundException('Tilawa not found');
return tilawa;
}

addReciterTilawa(id: number, addTilawaDto: AddTilawaDto) {
const tilawa = this.tilawaRepository.create(addTilawaDto);
tilawa.reciter_id = id;
addReciterTilawa(id: number, addTilawaDto: Omit<AddTilawaDto, 'reciter_id'>) {
const tilawa = this.tilawaRepository.create({
...addTilawaDto,
reciter_id: id,
});
return this.tilawaRepository.save(tilawa);
}
}

0 comments on commit 16ca68a

Please sign in to comment.