Skip to content

Commit

Permalink
SPSH-698: Personenkontexte bearbeiten: Weitere Zuordnung hinzufügen (#…
Browse files Browse the repository at this point in the history
…524)

* SPSH-658: Umbau des Personenkontextes nach DDD Richtlinien

* Create personenkontext factory and validity checks

* SPSH-658: Erste Iteration für die Filterung be der Rollenabfrage des eingeloggten Admins.

* Fix dependencies

* SPSH-658: Undone the first implementation for filtering roles, implemented the first draft for checking roles assignment.

* More permission checks

* SPSH-658: Extra Prüfung für die Systemrechte bei der Anlage eines Personenkontextes.

* SPSH-658: Tests wegen Dependencies & setups fixen.

* SPSH-658: Fixed Lint Warnungen

* SPSH-658: Fixed more tests

* SPSH-658: Fixed more tests

* SPSH-658: Fixed integration tests für den Personenkontext-Controller

* Move logic to permissions

* Fix tests

* Fix more tests

* Fix remaining non-api-tests

* Allow logged in user to see all personenkontexte of another user if authorized

* Fix more tests

* Fix all tests

* Merge remote-tracking branch 'origin/main' into spsh-606

* More code coverage

* SPSH-658: Unittests für den Personenkontext Aggregate, neue Error Klassen & OrganisationRepository, & Integrationtests für dbiam-personenkontext.repo

* Fix tests

* SPSH-658: Fixed unittests wegen merge conflicts

* move param and response files in personenkontext/api

* Add Repo to person module

* fix imports

* add PersonenkontexteUpdate as aggreate

* Mock keycloak in integration test

* Cover createAuthorized in tests

* Fix personenkontext.uc tests

* SPSH-658: Specification for landes-admin implemented and extra check for the creation of personenkontext.

* Fix personenkontext tests

* Fix tests

* add validation for Personenkontexte-Update aggregate

* add test for PersonenkontexteUpdate and corresponding classes

* SPSH-658: Changed the logic for the extra check for the permission of the current admin by the creation of the personenkontext. Refactored the OrganisationMatchesRollenart from the personenkontext-anlage in an helper class.

* SPSH-658: Fixed lint issues

* add exception-filter for PersonenkontexteUpdateErrors

* SPSH-658: Refactored the Personenkontext aggregate and changed the exception type for the check for the OrganisationMatchesRollenart

* Fix repo tests

* SPSH-658: Fixed tests for Personenkontext

* Add error to mapper

* Cover dbiam-personenkontext.repo

* Cover organisation-repository

* Fix dbiam-personenkontext-controller coverage

* Remove unused code

* SPSH-658: Corrected the unit tests for personenkontext

* Fix tests

* SPSH-658: Implemented unit-tests for the organisation-matches-rollenart

* Revert test timeout

* Fix OutOfMemory

* adjust PersonenkontexteUpdate to handle addtions of PK

* SPSH-606: Added a partial Personenkontext for the tests in order to fix the memory issue.

* adjust deletion of Personenkontext to be native

* adjust delete-method in PersonenkonteUpdate

* remove unused method

* adjust PersonenKontext.rolleId to reference Rolle

* SPSH-731: Implemented the restriction of roles that can be viewed for the creation of personenkontext, and made the parameter rollenName for the endpoint /GET/api/personenkontext/rollen optional

* SPSH-658: PR Review

* Rename createAuthorized

* SPSH-606: Fixed tests due to the error resulting from the sequence of setup data

* SPSH-731: Implemented integration tests for the DbiamPersonenkontextFilterController

* SPSH-731: Implemented unit tests for the PersonenkontextAnlage

* fix automapper issues in test

* adjust PersonenkontexteUpdate and tests

* add PersonenkontexteUpdate-event

* adjust events for Personenkontext

* adjust tests for LdapEventHandler

* SPSH-732: Implemented a new endpoint that checks the validity of personenkontext before saving the person and the personenkontext.

* SPSH-732: Undid the extra method for checkReferences in Personenkontext

* add DbiamPersonenUebersicht aggregate and implement persion check for PK-retrieval

* SPSH-732: Refactored error codes for FE.

* SPSH-732: Updated the payload for the request POST api/dbiam/personen

* move publishing of events for Personenkontext and Orga into the repos

* SPSH-732: Implemented unit tests

* SPSH-732: Fixed lint

* SPSH-732: Fixed dependency issue for the dbiam person controller

* SPSH-732: Implemented the integration tests

* SPSH-732: Fixed tests for Keycloak

* adjusted DbiamPersonenkontext controller and tests

* SPSH-732: Added more unit tests and removed unused specifications

* SPSH-732: Fixed KC issues for the integration tests

* SPSH-732: Fixed the KC issue for the integration tests

* SPSH-732: PR review

* fixed linting

* Event published after creating the kontext hold personId, OrgaId and RolleId

* Introduced the workflow controller

* Enhanced new error class that is thrown at commit time.

* Added necessary classes to the person module

* Fixed linting

* Fixed response and test

* Search by string is possible for both ssk and rolle now

* fixed test and renamed aggregate

* Fixed tests

* remvoed log statement

* Handled error in commit endpoint and fixed test

* Catch error in the commit controller

* can commit method now also returns errors instead of boolean to propagate errors to controlelr

* Fixed person service test

* fix

* test for commit method

* more tests

* fixed test

* Covered all lines for workflow aggregate

* Test for find method

* errors test

* covered more lines

* fixed linting

* covered badrequestexception line

* Fixed tests

* Fixed test

* covered last line

* added types to test for the orga and rolle to match

* Test for handling request with no orgaId

* trigger rollen method if orga is provided

* made use of class properties instead of method parameters

* added initiazer to test

* last test

* fixed lint

* modified rollen logic

* fixed test

* added roles to array in test

* Fixed test

* fixed litning

* return orgas also if the orgaId was provided

* fixed tests after merge

* linting

* added test for error

* another test for error

* changed path to workflow and added description of the API

* Not considering child orgas while fetching for rollen.

* Sorting Rollen b y name, Orgas by kennng And Name and Klassen by name

* Removed unncesseary assertions as now orgas are sorted and can't be compared to unsorted orgas

* tests for sorting

* covered last line

* added another Rolle to the spec to sort

* fixed assert

* test for undefined name while sorting

* test for undefined kennung and undefined rolle

* fixed assertion

* test for undefined everything

* more coverage

* couple more tests to reach 100% coverage

* undefined kennung but present name

* test

* removed the only

* check for rollen

* remove check for rollen

* changed the logic for sorting

* more test for sorting

* test

* linting

* fixed linting

* last test

* linting

* SPSH-698: Refactoring, moved the creation of persons with personenkontext in the PersonenkontextModule

* SPSH-698: Renamed the route of the POST method createPersonWithKontext to fix integration tests.

* SPSH-698: Fixed the issue with integration tests failing in the pipeline due to KC test-container.

* SPSH-698: PR Review

* SPSH-698: Removed the sort unit test for the organisation.uc.spec

* SPSH-698: Added unit tests for the limit parameter & updated the logic for returned allowedRollen when the limit is set.

* SPSH-698: Changed the endpoint for the request CreatePersonWithPersonenkontext

* SPSH-698: Changed the logic for the findAllSchulstrukturknoten() method.

* SPSH-698: Implemented the query filter for requesting organisations from the DB and updated the unit tests

* SPSH-698: Fixed KC issues

* SPSH-698: Fixed integration tests failing due modules setup

* SPSH-698: Moved the OrganisationScope for querying the DB from the domain  to the repository.

* SPSH-698: PR Review 2

---------

Co-authored-by: Phael Mouko <[email protected]>
Co-authored-by: Marvin Rode <[email protected]>
Co-authored-by: Marvin Rode (Cap) <[email protected]>
Co-authored-by: Haby-Phael Mouko <[email protected]>
Co-authored-by: godtierbatuhan <[email protected]>
Co-authored-by: Youssef Bouchara <[email protected]>
  • Loading branch information
7 people authored Jul 10, 2024
1 parent 9ccbfd9 commit 28b742a
Show file tree
Hide file tree
Showing 37 changed files with 3,228 additions and 1,772 deletions.
68 changes: 50 additions & 18 deletions src/modules/organisation/api/organisation.uc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,6 @@ describe('OrganisationUc', () => {

expect(result.total).toBe(2);
expect(result.items).toHaveLength(2);
expect(result.items[0]?.name).toEqual(organisationDos[0]?.name);
expect(result.items[1]?.name).toEqual(organisationDos[1]?.name);
expect(result.items[0]?.kennung).toEqual(organisationDos[0]?.kennung);
expect(result.items[1]?.kennung).toEqual(organisationDos[1]?.kennung);
expect(result.items[0]?.typ).toEqual(organisationDos[0]?.typ);
expect(result.items[1]?.typ).toEqual(organisationDos[1]?.typ);
});
});

Expand Down Expand Up @@ -321,12 +315,56 @@ describe('OrganisationUc', () => {
if (!(result instanceof SchulConnexError)) {
expect(result.total).toBe(2);
expect(result.items).toHaveLength(2);
expect(result.items[0]?.name).toEqual(organisationDos[0]?.name);
expect(result.items[1]?.name).toEqual(organisationDos[1]?.name);
expect(result.items[0]?.kennung).toEqual(organisationDos[0]?.kennung);
expect(result.items[1]?.kennung).toEqual(organisationDos[1]?.kennung);
expect(result.items[0]?.typ).toEqual(organisationDos[0]?.typ);
expect(result.items[1]?.typ).toEqual(organisationDos[1]?.typ);
}
});

it('should handle undefined names during sorting', async () => {
const org1: OrganisationDo<true> = DoFactory.createOrganisation(true, { name: undefined });
const org2: OrganisationDo<true> = DoFactory.createOrganisation(true, { name: 'Alpha' });
const org3: OrganisationDo<true> = DoFactory.createOrganisation(true, { name: 'Beta' });

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

organisationServiceMock.findAllAdministriertVon.mockResolvedValue({
total: 3,
offset: 0,
limit: 3,
items: [org1, org2, org3],
});

const result: Paged<OrganisationResponseLegacy> | SchulConnexError =
await organisationUc.findAdministriertVon('parent-id');

if (!(result instanceof SchulConnexError)) {
expect(result.items.map((o: OrganisationResponseLegacy) => o.name)).toEqual([
undefined,
'Alpha',
'Beta',
]);
}
});

it('should handle empty list of organisations', async () => {
organisationServiceMock.findAllAdministriertVon.mockResolvedValue({
total: 0,
offset: 0,
limit: 0,
items: [],
});

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

const result: Paged<OrganisationResponseLegacy> | SchulConnexError =
await organisationUc.findAdministriertVon('parent-id');

if (!(result instanceof SchulConnexError)) {
expect(result.items).toHaveLength(0);
}
});
});
Expand Down Expand Up @@ -372,12 +410,6 @@ describe('OrganisationUc', () => {
if (!(result instanceof SchulConnexError)) {
expect(result.total).toBe(2);
expect(result.items).toHaveLength(2);
expect(result.items[0]?.name).toEqual(organisationDos[0]?.name);
expect(result.items[1]?.name).toEqual(organisationDos[1]?.name);
expect(result.items[0]?.kennung).toEqual(organisationDos[0]?.kennung);
expect(result.items[1]?.kennung).toEqual(organisationDos[1]?.kennung);
expect(result.items[0]?.typ).toEqual(organisationDos[0]?.typ);
expect(result.items[1]?.typ).toEqual(organisationDos[1]?.typ);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { OrganisationScope } from './organisation.scope.js';
import { Mapper } from '@automapper/core';
import { getMapperToken } from '@automapper/nestjs';
import { EventModule } from '../../../core/eventbus/index.js';
import { OrganisationsTyp } from '../domain/organisation.enums.js';

describe('OrganisationRepo', () => {
let module: TestingModule;
Expand Down Expand Up @@ -104,6 +105,16 @@ describe('OrganisationRepo', () => {
});
});

describe('find', () => {
it('should find all organizations', async () => {
const organisationDo: OrganisationDo<false> = DoFactory.createOrganisation(false);
await sut.save(organisationDo);
const foundOrganisations: OrganisationDo<boolean>[] = await sut.find(25);

expect(foundOrganisations).toHaveLength(1);
});
});

describe('findByIds', () => {
it('should find organizations by IDs', async () => {
const organisationDo: OrganisationDo<false> = DoFactory.createOrganisation(false);
Expand Down Expand Up @@ -259,4 +270,59 @@ describe('OrganisationRepo', () => {
});
});
});

describe('findByNameOrKennungAndExcludeByOrganisationType', () => {
describe('when matching organisations by name were found', () => {
it('should return found organizations', async () => {
const orgaName: string = 'Test-Orga';
const excludeOrgaType: OrganisationsTyp = OrganisationsTyp.KLASSE;
const organisationDoSchule: OrganisationDo<false> = DoFactory.createOrganisation(false, {
name: orgaName,
typ: OrganisationsTyp.SCHULE,
});
await sut.save(organisationDoSchule);

const organisationDoKlasse: OrganisationDo<false> = DoFactory.createOrganisation(false, {
name: orgaName + '1',
typ: excludeOrgaType,
});
await sut.save(organisationDoKlasse);

const organisationDoSchule2: OrganisationDo<false> = DoFactory.createOrganisation(false, {
typ: OrganisationsTyp.SCHULE,
});
await sut.save(organisationDoSchule2);

const foundOrganisations: Option<OrganisationDo<true>[]> =
await sut.findByNameOrKennungAndExcludeByOrganisationType(excludeOrgaType, orgaName);
expect(foundOrganisations).toBeInstanceOf(Array);
expect(foundOrganisations).toHaveLength(1);
});
});

describe('when matching organisations were found and search is limit', () => {
it('should return limited found organizations', async () => {
const excludeOrgaType: OrganisationsTyp = OrganisationsTyp.KLASSE;
const organisationDoSchule: OrganisationDo<false> = DoFactory.createOrganisation(false, {
typ: OrganisationsTyp.SCHULE,
});
await sut.save(organisationDoSchule);

const organisationDoSchule2: OrganisationDo<false> = DoFactory.createOrganisation(false, {
typ: OrganisationsTyp.SCHULE,
});
await sut.save(organisationDoSchule2);

const organisationDoKlasse: OrganisationDo<false> = DoFactory.createOrganisation(false, {
typ: excludeOrgaType,
});
await sut.save(organisationDoKlasse);

const foundOrganisations: Option<OrganisationDo<true>[]> =
await sut.findByNameOrKennungAndExcludeByOrganisationType(excludeOrgaType, undefined, 1);
expect(foundOrganisations).toBeInstanceOf(Array);
expect(foundOrganisations).toHaveLength(1);
});
});
});
});
30 changes: 30 additions & 0 deletions src/modules/organisation/persistence/organisation.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { OrganisationID } from '../../../shared/types/aggregate-ids.types.js';
import { SchuleCreatedEvent } from '../../../shared/events/schule-created.event.js';
import { EventService } from '../../../core/eventbus/index.js';
import { OrganisationsTyp } from '../domain/organisation.enums.js';
import { ScopeOperator } from '../../../shared/persistence/scope.enums.js';

@Injectable()
export class OrganisationRepo {
Expand Down Expand Up @@ -66,6 +67,14 @@ export class OrganisationRepo {
return !!organisation;
}

public async find(limit?: number, offset?: number): Promise<OrganisationDo<boolean>[]> {
const organisations: OrganisationEntity[] = await this.em.findAll(OrganisationEntity, {
limit: limit,
offset: offset,
});
return this.mapper.mapArray(organisations, OrganisationEntity, OrganisationDo);
}

public async findById(id: string): Promise<Option<OrganisationDo<true>>> {
const organisation: Option<OrganisationEntity> = await this.em.findOne(OrganisationEntity, { id });
if (organisation) {
Expand Down Expand Up @@ -135,4 +144,25 @@ export class OrganisationRepo {
}
return [];
}

public async findByNameOrKennungAndExcludeByOrganisationType(
excludeOrganisationType: OrganisationsTyp,
searchStr?: string,
limit?: number,
): Promise<OrganisationDo<true>[]> {
const scope: OrganisationScope = new OrganisationScope();
if (searchStr) {
scope
.searchString(searchStr)
.setScopeWhereOperator(ScopeOperator.AND)
.excludeTyp([excludeOrganisationType]);
} else {
scope.excludeTyp([excludeOrganisationType]).paged(0, limit);
}

let foundOrganisations: OrganisationDo<true>[] = [];
[foundOrganisations] = await this.findBy(scope);

return foundOrganisations;
}
}
Loading

0 comments on commit 28b742a

Please sign in to comment.