From 23dbd6011c8305e46b3baf57171b6fecd4365e6c Mon Sep 17 00:00:00 2001 From: Marvin Rode Date: Thu, 16 Nov 2023 08:20:49 +0100 Subject: [PATCH] Fix tests --- .../organisation/api/organisation.uc.spec.ts | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/modules/organisation/api/organisation.uc.spec.ts b/src/modules/organisation/api/organisation.uc.spec.ts index 38e0d2459..693f2fc35 100644 --- a/src/modules/organisation/api/organisation.uc.spec.ts +++ b/src/modules/organisation/api/organisation.uc.spec.ts @@ -199,7 +199,7 @@ describe('OrganisationUc', () => { }); describe('findVerwaltetVon', () => { - describe('when matching organizations were found', () => { + describe('when parent organisation exists', () => { it('should return all found organisations', async () => { const organisationDos: OrganisationDo[] = DoFactory.createMany( 2, @@ -207,6 +207,11 @@ describe('OrganisationUc', () => { DoFactory.createOrganisation, ); + organisationServiceMock.findOrganisationById.mockResolvedValueOnce({ + ok: true, + value: DoFactory.createOrganisation(true), + }); + organisationServiceMock.findAllVerwaltetVon.mockResolvedValue({ total: organisationDos.length, offset: 0, @@ -227,25 +232,20 @@ describe('OrganisationUc', () => { }); }); - describe('when no matching organisations were found', () => { - it('should return an empty array', async () => { - organisationServiceMock.findAllVerwaltetVon.mockResolvedValue({ - total: 0, - offset: 0, - limit: 0, - items: [], + describe('when no parent organisation exists', () => { + it('should throw error', async () => { + organisationServiceMock.findOrganisationById.mockResolvedValueOnce({ + ok: false, + error: new EntityNotFoundError(), }); - const emptyResult: Paged = await organisationUc.findVerwaltetVon(''); - - expect(emptyResult.total).toBe(0); - expect(emptyResult.items).toHaveLength(0); + await expect(organisationUc.findVerwaltetVon('')).rejects.toThrow(EntityNotFoundError); }); }); }); describe('findZugehoerigZu', () => { - describe('when matching organizations were found', () => { + describe('when parent organisation exists', () => { it('should return all found organisations', async () => { const organisationDos: OrganisationDo[] = DoFactory.createMany( 2, @@ -253,6 +253,11 @@ describe('OrganisationUc', () => { DoFactory.createOrganisation, ); + organisationServiceMock.findOrganisationById.mockResolvedValueOnce({ + ok: true, + value: DoFactory.createOrganisation(true), + }); + organisationServiceMock.findAllZugehoerigZu.mockResolvedValue({ total: organisationDos.length, offset: 0, @@ -273,19 +278,14 @@ describe('OrganisationUc', () => { }); }); - describe('when no matching organisations were found', () => { - it('should return an empty array', async () => { - organisationServiceMock.findAllZugehoerigZu.mockResolvedValue({ - total: 0, - offset: 0, - limit: 0, - items: [], + describe('when no parent organisation exists', () => { + it('should throw error', async () => { + organisationServiceMock.findOrganisationById.mockResolvedValueOnce({ + ok: false, + error: new EntityNotFoundError(), }); - const emptyResult: Paged = await organisationUc.findZugehoerigZu(''); - - expect(emptyResult.total).toBe(0); - expect(emptyResult.items).toHaveLength(0); + await expect(organisationUc.findZugehoerigZu('')).rejects.toThrow(EntityNotFoundError); }); }); });