Skip to content

Commit

Permalink
Fix Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
casparneumann-cap committed Jan 10, 2025
1 parent 97a3c2f commit f881972
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ConfigTestModule,
DatabaseTestModule,
DEFAULT_TIMEOUT_FOR_TESTCONTAINERS,
DoFactory,
LoggingTestModule,
MapperTestModule,
} from '../../../../../test/utils/index.js';
Expand All @@ -27,7 +26,6 @@ import { RolleFactory } from '../../../rolle/domain/rolle.factory.js';
import { RollenArt } from '../../../rolle/domain/rolle.enums.js';
import { RolleRepo } from '../../../rolle/repo/rolle.repo.js';
import { Rolle } from '../../../rolle/domain/rolle.js';
import { OrganisationDo } from '../../../organisation/domain/organisation.do.js';
import { Personenkontext } from '../../../personenkontext/domain/personenkontext.js';
import { DBiamPersonenkontextRepoInternal } from '../../../personenkontext/persistence/internal-dbiam-personenkontext.repo.js';
import { DBiamPersonenzuordnungResponse } from './dbiam-personenzuordnung.response.js';
Expand Down Expand Up @@ -350,87 +348,6 @@ describe('Personenuebersicht API', () => {
expect(response.status).toBe(404);
});
});

describe('when one or more organisations does not exist', () => {
it('should return Error', async () => {
const creationParams: PersonCreationParams = {
familienname: faker.person.lastName(),
vorname: faker.person.firstName(),
};

const person: Person<false> | DomainError = await Person.createNew(
usernameGeneratorService,
creationParams,
);
expect(person).not.toBeInstanceOf(DomainError);
if (person instanceof DomainError) {
return;
}
const savedPerson: Person<true> | DomainError = await personRepository.create(person);
expect(savedPerson).not.toBeInstanceOf(DomainError);
if (savedPerson instanceof DomainError) {
return;
}

const rolle1: Rolle<false> | DomainError = rolleFactory.createNew(
faker.string.alpha(5),
faker.string.uuid(),
RollenArt.LEHR,
[],
[],
[],
[],
false,
);

if (rolle1 instanceof DomainError) {
return;
}
const savedRolle1: Rolle<true> | DomainError = await rolleRepo.save(rolle1);
if (savedRolle1 instanceof DomainError) throw Error();

const rolle2: Rolle<false> | DomainError = rolleFactory.createNew(
faker.string.alpha(5),
faker.string.uuid(),
RollenArt.LERN,
[],
[],
[],
[],
false,
);

if (rolle2 instanceof DomainError) {
return;
}
const savedRolle2: Rolle<true> | DomainError = await rolleRepo.save(rolle2);
if (savedRolle2 instanceof DomainError) throw Error();

const unsavedOrganisation1: OrganisationDo<true> = DoFactory.createOrganisation(true);
const savedOrganisation2: OrganisationEntity = await createAndPersistOrganisation(
em,
undefined,
OrganisationsTyp.SONSTIGE,
true,
);

await dBiamPersonenkontextRepoInternal.save(
personenkontextFactory.createNew(savedPerson.id, unsavedOrganisation1.id, savedRolle1.id),
);
await dBiamPersonenkontextRepoInternal.save(
personenkontextFactory.createNew(savedPerson.id, unsavedOrganisation1.id, savedRolle2.id),
);
await dBiamPersonenkontextRepoInternal.save(
personenkontextFactory.createNew(savedPerson.id, savedOrganisation2.id, savedRolle2.id),
);

const response: Response = await request(app.getHttpServer() as App)
.get(`/dbiam/personenuebersicht/${savedPerson.id}`)
.send();

expect(response.status).toBe(404);
});
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { Personenkontext } from '../../personenkontext/domain/personenkontext.js
import { PersonID } from '../../../shared/types/aggregate-ids.types.js';
import { UserLock } from '../../keycloak-administration/domain/user-lock.js';
import { DownstreamKeycloakError } from '../domain/person-keycloak.error.js';
import { Organisation } from '../../organisation/domain/organisation.js';

describe('PersonRepository Integration', () => {
let module: TestingModule;
Expand All @@ -83,6 +84,7 @@ describe('PersonRepository Integration', () => {
let dbiamPersonenkontextRepoInternal: DBiamPersonenkontextRepoInternal;
let personenkontextFactory: PersonenkontextFactory;
let userLockRepository: UserLockRepository;
let organisationRepository: OrganisationRepository;

beforeAll(async () => {
module = await Test.createTestingModule({
Expand Down Expand Up @@ -137,6 +139,7 @@ describe('PersonRepository Integration', () => {
dbiamPersonenkontextRepoInternal = module.get(DBiamPersonenkontextRepoInternal);
personenkontextFactory = module.get(PersonenkontextFactory);
userLockRepository = module.get(UserLockRepository);
organisationRepository = module.get(OrganisationRepository);

await DatabaseTestModule.setupDatabase(orm);
}, DEFAULT_TIMEOUT_FOR_TESTCONTAINERS);
Expand Down Expand Up @@ -2229,6 +2232,14 @@ describe('PersonRepository Integration', () => {
merkmale: [RollenMerkmal.KOPERS_PFLICHT],
});

const organisation1: Organisation<true> = await organisationRepository.save(
DoFactory.createOrganisation(false),
);
const organisation2: Organisation<true> = await organisationRepository.save(
DoFactory.createOrganisation(false),
);


Check warning on line 2242 in src/modules/person/persistence/person.repository.integration-spec.ts

View workflow job for this annotation

GitHub Actions / Linting / Nest Lint

Delete `⏎`
const rolle1Result: Rolle<true> | DomainError = await rolleRepo.save(rolle1);
const rolle2Result: Rolle<true> | DomainError = await rolleRepo.save(rolle2);
if (rolle1Result instanceof DomainError) throw Error();
Expand All @@ -2239,16 +2250,19 @@ describe('PersonRepository Integration', () => {
const personenKontext1: Personenkontext<false> = DoFactory.createPersonenkontext(false, {
personId: person1.id,
rolleId: rolle1Result.id,
organisationId: organisation1.id,
});

const personenKontext2: Personenkontext<false> = DoFactory.createPersonenkontext(false, {
personId: person2.id,
rolleId: rolle2Result.id,
organisationId: organisation1.id,
});

const personenKontext3: Personenkontext<false> = DoFactory.createPersonenkontext(false, {
personId: person3.id,
rolleId: rolle2Result.id,
organisationId: organisation1.id,
});

await dbiamPersonenkontextRepoInternal.save(personenKontext1);
Expand All @@ -2261,10 +2275,12 @@ describe('PersonRepository Integration', () => {
const personenKontext4: Personenkontext<false> = DoFactory.createPersonenkontext(false, {
personId: person3.id,
rolleId: rolle2Result.id,
organisationId: organisation2.id,
});
const personenKontext5: Personenkontext<false> = DoFactory.createPersonenkontext(false, {
personId: person4.id,
rolleId: rolle2Result.id,
organisationId: organisation2.id,
});

await dbiamPersonenkontextRepoInternal.save(personenKontext4);
Expand Down Expand Up @@ -2310,9 +2326,14 @@ describe('PersonRepository Integration', () => {
const rolle1Result: Rolle<true> | DomainError = await rolleRepo.save(rolle1);
if (rolle1Result instanceof DomainError) throw Error();

const organisation1: Organisation<true> = await organisationRepository.save(
DoFactory.createOrganisation(false),
);

const personenKontext1: Personenkontext<false> = DoFactory.createPersonenkontext(false, {
personId: person3.id,
rolleId: rolle1Result.id,
organisationId: organisation1.id,
});
await dbiamPersonenkontextRepoInternal.save(personenKontext1);
// person without personenkontext but within the time limit for org_unassignment_Date
Expand Down Expand Up @@ -2345,9 +2366,14 @@ describe('PersonRepository Integration', () => {
const rolle1Result: Rolle<true> | DomainError = await rolleRepo.save(rolle1);
if (rolle1Result instanceof DomainError) throw Error();

const organisation1: Organisation<true> = await organisationRepository.save(
DoFactory.createOrganisation(false),
);

const personenKontext1: Personenkontext<false> = DoFactory.createPersonenkontext(false, {
personId: person1.id,
rolleId: rolle1Result.id,
organisationId: organisation1.id,
});
await dbiamPersonenkontextRepoInternal.save(personenKontext1);
//get admins
Expand Down
35 changes: 22 additions & 13 deletions src/modules/person/persistence/person.scope.integration-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { PersonenKontextModule } from '../../personenkontext/personenkontext.mod
import { OrganisationRepository } from '../../organisation/persistence/organisation.repository.js';
import { mapAggregateToData } from './person.repository.js';
import { DomainError } from '../../../shared/error/domain.error.js';
import { Organisation } from '../../organisation/domain/organisation.js';

describe('PersonScope', () => {
let module: TestingModule;
Expand All @@ -32,6 +33,7 @@ describe('PersonScope', () => {
let kontextRepoInternal: DBiamPersonenkontextRepoInternal;
let rolleRepo: RolleRepo;
let personenkontextFactory: PersonenkontextFactory;
let organisationRepository: OrganisationRepository;

const createPersonEntity = (): PersonEntity => {
const person: PersonEntity = new PersonEntity().assign(mapAggregateToData(DoFactory.createPerson(false)));
Expand Down Expand Up @@ -70,6 +72,7 @@ describe('PersonScope', () => {
kontextRepoInternal = module.get(DBiamPersonenkontextRepoInternal);
rolleRepo = module.get(RolleRepo);
personenkontextFactory = module.get(PersonenkontextFactory);
organisationRepository = module.get(OrganisationRepository);

await DatabaseTestModule.setupDatabase(orm);
}, DEFAULT_TIMEOUT_FOR_TESTCONTAINERS);
Expand Down Expand Up @@ -180,21 +183,22 @@ describe('PersonScope', () => {
});

describe('when filtering for organisation ID', () => {
const orgnisationID: string = faker.string.uuid();
let organisation: Organisation<true>;

beforeEach(async () => {
const person1: PersonEntity = createPersonEntity();
const person2: PersonEntity = createPersonEntity();
const rolle: Rolle<true> | DomainError = await rolleRepo.save(DoFactory.createRolle(false));
if (rolle instanceof DomainError) throw Error();
organisation = await organisationRepository.save(DoFactory.createOrganisation(false));

await em.persistAndFlush([person1, person2]);
await createPersonenkontext(person1.id, orgnisationID, rolle.id);
await createPersonenkontext(person1.id, organisation.id, rolle.id);
});

it('should return found persons', async () => {
const scope: PersonScope = new PersonScope()
.findBy({ organisationen: [orgnisationID] })
.findBy({ organisationen: [organisation.id] })
.sortBy('vorname', ScopeOrder.ASC);
const [persons, total]: Counted<PersonEntity> = await scope.executeQuery(em);

Expand All @@ -204,23 +208,23 @@ describe('PersonScope', () => {
});

describe('when filtering for organisation ID & Rollen ID', () => {
const orgnisationID: string = faker.string.uuid();
let organisation: Organisation<true>;
let rolleID: string;

beforeEach(async () => {
const person1: PersonEntity = createPersonEntity();
const person2: PersonEntity = createPersonEntity();
const rolle: Rolle<true> | DomainError = await rolleRepo.save(DoFactory.createRolle(false));
if (rolle instanceof DomainError) throw Error();

organisation = await organisationRepository.save(DoFactory.createOrganisation(false));
rolleID = rolle.id;
await em.persistAndFlush([person1, person2]);
await createPersonenkontext(person1.id, orgnisationID, rolle.id);
await createPersonenkontext(person1.id, organisation.id, rolle.id);
});

it('should return found persons', async () => {
const scope: PersonScope = new PersonScope()
.findByPersonenKontext([orgnisationID], [rolleID])
.findByPersonenKontext([organisation.id], [rolleID])
.sortBy('vorname', ScopeOrder.ASC);
const [persons, total]: Counted<PersonEntity> = await scope.executeQuery(em);

Expand All @@ -230,20 +234,21 @@ describe('PersonScope', () => {
});

describe('when filtering for organisation ID only', () => {
const organisationID: string = faker.string.uuid();
let organisation: Organisation<true>;

beforeEach(async () => {
const person1: PersonEntity = createPersonEntity();
const rolle: Rolle<true> | DomainError = await rolleRepo.save(DoFactory.createRolle(false));
if (rolle instanceof DomainError) throw Error();
organisation = await organisationRepository.save(DoFactory.createOrganisation(false));

await em.persistAndFlush([person1]);
await createPersonenkontext(person1.id, organisationID, rolle.id);
await createPersonenkontext(person1.id, organisation.id, rolle.id);
});

it('should return found persons', async () => {
const scope: PersonScope = new PersonScope()
.findByPersonenKontext([organisationID])
.findByPersonenKontext([organisation.id])
.sortBy('vorname', ScopeOrder.ASC);
const [persons, total]: Counted<PersonEntity> = await scope.executeQuery(em);

Expand All @@ -254,15 +259,17 @@ describe('PersonScope', () => {

describe('when filtering for Rolle ID only', () => {
let rolleID: string;
let organisation: Organisation<true>;

beforeEach(async () => {
const person1: PersonEntity = createPersonEntity();
const rolle: Rolle<true> | DomainError = await rolleRepo.save(DoFactory.createRolle(false));
if (rolle instanceof DomainError) throw Error();
organisation = await organisationRepository.save(DoFactory.createOrganisation(false));

rolleID = rolle.id;
await em.persistAndFlush([person1]);
await createPersonenkontext(person1.id, faker.string.uuid(), rolleID);
await createPersonenkontext(person1.id, organisation.id, rolleID);
});

it('should return found persons', async () => {
Expand Down Expand Up @@ -301,16 +308,18 @@ describe('PersonScope', () => {
});

it('should not return technical users', async () => {
const orgnisationID: string = faker.string.uuid();
const person1: PersonEntity = createPersonEntity();
const person2: PersonEntity = createPersonEntity();
const rolle: Rolle<true> | DomainError = await rolleRepo.save(
DoFactory.createRolle(false, { istTechnisch: true }),
);
if (rolle instanceof DomainError) throw Error();
const organisation: Organisation<true> = await organisationRepository.save(
DoFactory.createOrganisation(false),
);

await em.persistAndFlush([person1, person2]);
await createPersonenkontext(person1.id, orgnisationID, rolle.id);
await createPersonenkontext(person1.id, organisation.id, rolle.id);

const scope: PersonScope = new PersonScope()
.findBy({ ids: [person1.id, person2.id] })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,14 @@ describe('DbiamPersonenkontextWorkflowController Integration Test', () => {
if (rolle instanceof DomainError) {
throw rolle;
}
const organisation: Organisation<true> = await organisationRepo.save(
DoFactory.createOrganisation(false),
);
const savedPK: Personenkontext<true> = await personenkontextRepoInternal.save(
DoFactory.createPersonenkontext(false, {
personId: person.id,
rolleId: rolle.id,
organisationId: organisation.id,
updatedAt: new Date(),
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,29 @@ describe('dbiam Personenkontext API', () => {
if (personB instanceof DomainError) {
throw personB;
}

const organisation: Organisation<true> = await organisationRepo.save(DoFactory.createOrganisation(false));

await Promise.all([
personenkontextRepoInternal.save(
DoFactory.createPersonenkontext(false, {
personId: personA.id,
rolleId: rolleA.id,
organisationId: organisation.id,
}),
),
personenkontextRepoInternal.save(
DoFactory.createPersonenkontext(false, {
personId: personA.id,
rolleId: rolleB.id,
organisationId: organisation.id,
}),
),
personenkontextRepoInternal.save(
DoFactory.createPersonenkontext(false, {
personId: personB.id,
rolleId: rolleC.id,
organisationId: organisation.id,
}),
),
]);
Expand Down

0 comments on commit f881972

Please sign in to comment.