Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marode-cap committed Nov 16, 2023
1 parent 8189765 commit 23dbd60
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/modules/organisation/api/organisation.uc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,19 @@ 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<true>[] = DoFactory.createMany(
2,
true,
DoFactory.createOrganisation,
);

organisationServiceMock.findOrganisationById.mockResolvedValueOnce({
ok: true,
value: DoFactory.createOrganisation(true),
});

organisationServiceMock.findAllVerwaltetVon.mockResolvedValue({
total: organisationDos.length,
offset: 0,
Expand All @@ -227,32 +232,32 @@ 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<OrganisationResponse> = 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<true>[] = DoFactory.createMany(
2,
true,
DoFactory.createOrganisation,
);

organisationServiceMock.findOrganisationById.mockResolvedValueOnce({
ok: true,
value: DoFactory.createOrganisation(true),
});

organisationServiceMock.findAllZugehoerigZu.mockResolvedValue({
total: organisationDos.length,
offset: 0,
Expand All @@ -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<OrganisationResponse> = await organisationUc.findZugehoerigZu('');

expect(emptyResult.total).toBe(0);
expect(emptyResult.items).toHaveLength(0);
await expect(organisationUc.findZugehoerigZu('')).rejects.toThrow(EntityNotFoundError);
});
});
});
Expand Down

0 comments on commit 23dbd60

Please sign in to comment.