-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPSH-1288 #774
Open
he-meyer
wants to merge
30
commits into
main
Choose a base branch
from
SPSH-1288
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
SPSH-1288 #774
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
cda389c
Log creation of Schule and Klasse
he-meyer 3edd75f
Log update of Klasse name
he-meyer b5443a7
Add logger
he-meyer 5b2b6d3
Log deletion of Klasse
he-meyer 3131ac3
Log update of Schule and Klasse
he-meyer 7339c6c
Log creation, update and deletion of Rolle
he-meyer 93753d3
Add logger to tests
he-meyer a783823
Add logger to test
he-meyer 8b69ca7
Adapt test
he-meyer 775c1f0
Adapt test
he-meyer 0962b43
Adapt test
he-meyer c9c601d
Adapt test
he-meyer c41858b
Adapt helper function and log statements
he-meyer 2297f3d
Adapt tests
he-meyer 491e369
Fix tests
he-meyer f1a9c6d
Adapt tests to increase coverage
he-meyer eda234a
Add and adapt tests to increase coverage
he-meyer 7b4d908
Add tests for coverage
he-meyer 8ab0fb6
Adapt for coverage
he-meyer f7edf92
Log username
he-meyer 829975a
Use empty mock in tests
he-meyer 1e02e15
Use empty mocks in tests
he-meyer 68f0bad
Avoid undefined checks and adapt tests
he-meyer 514829a
Don't log Organisation name
he-meyer 2964f72
Merge branch 'main' of https://github.com/dBildungsplattform/dbildung…
he-meyer 8dd1055
Fix duplicate
he-meyer 1751955
Add log for a new error case
he-meyer ea40302
Fix tests
he-meyer 00ee643
Avoid undefined checks
he-meyer ac8c1df
Use correct log level
he-meyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ import { OrganisationByIdBodyParams } from './organisation-by-id.body.params.js' | |
import { OrganisationRepository } from '../persistence/organisation.repository.js'; | ||
import { Organisation } from '../domain/organisation.js'; | ||
import { OrganisationResponse } from './organisation.response.js'; | ||
import { PersonPermissions } from '../../authentication/domain/person-permissions.js'; | ||
import { PersonenkontextRolleFields, PersonPermissions } from '../../authentication/domain/person-permissions.js'; | ||
import { EventService } from '../../../core/eventbus/index.js'; | ||
import { OrganisationRootChildrenResponse } from './organisation.root-children.response.js'; | ||
import { OrganisationSpecificationError } from '../specification/error/organisation-specification.error.js'; | ||
|
@@ -30,6 +30,7 @@ import { OrganisationByNameQueryParams } from './organisation-by-name.query.js'; | |
import { DBiamPersonenkontextRepo } from '../../personenkontext/persistence/dbiam-personenkontext.repo.js'; | ||
import { ParentOrganisationenResponse } from './organisation.parents.response.js'; | ||
import { ParentOrganisationsByIdsBodyParams } from './parent-organisations-by-ids.body.params.js'; | ||
import { Person } from '../../person/domain/person.js'; | ||
|
||
function getFakeParamsAndBody(): [OrganisationByIdParams, OrganisationByIdBodyParams] { | ||
const params: OrganisationByIdParams = { | ||
|
@@ -88,6 +89,20 @@ describe('OrganisationController', () => { | |
}); | ||
|
||
describe('createOrganisation', () => { | ||
const permissionsMock: PersonPermissions = createMock<PersonPermissions>({ | ||
get personFields(): Person<true> { | ||
return createMock<Person<true>>({ | ||
familienname: 'current-user', | ||
}); | ||
}, | ||
getPersonenkontextewithRoles: (): Promise<PersonenkontextRolleFields[]> => | ||
Promise.resolve([ | ||
{ | ||
organisationsId: '', | ||
rolle: { systemrechte: [], serviceProviderIds: [] }, | ||
}, | ||
]), | ||
}); | ||
describe('when usecase returns a DTO', () => { | ||
it('should not throw an error', async () => { | ||
const params: CreateOrganisationBodyParams = { | ||
|
@@ -101,7 +116,7 @@ describe('OrganisationController', () => { | |
const returnedValue: Organisation<true> = DoFactory.createOrganisation(true); | ||
|
||
organisationServiceMock.createOrganisation.mockResolvedValueOnce({ ok: true, value: returnedValue }); | ||
await expect(organisationController.createOrganisation(params)).resolves.not.toThrow(); | ||
await expect(organisationController.createOrganisation(permissionsMock, params)).resolves.not.toThrow(); | ||
expect(organisationServiceMock.createOrganisation).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
@@ -153,7 +168,7 @@ describe('OrganisationController', () => { | |
organisationRepositoryMock.findRootDirectChildren.mockResolvedValue(mockedRepoResponse); | ||
|
||
try { | ||
await organisationController.createOrganisation(params); | ||
await organisationController.createOrganisation(permissionsMock, params); | ||
|
||
fail('Expected error was not thrown'); | ||
} catch (error) { | ||
|
@@ -202,7 +217,7 @@ describe('OrganisationController', () => { | |
error: new OrganisationSpecificationError('error', undefined), | ||
}); | ||
await expect( | ||
organisationController.createOrganisation({} as CreateOrganisationBodyParams), | ||
organisationController.createOrganisation(permissionsMock, {} as CreateOrganisationBodyParams), | ||
).rejects.toThrow(OrganisationSpecificationError); | ||
expect(organisationServiceMock.createOrganisation).toHaveBeenCalledTimes(1); | ||
}); | ||
|
@@ -249,7 +264,7 @@ describe('OrganisationController', () => { | |
error: {} as EntityNotFoundError, | ||
}); | ||
await expect( | ||
organisationController.createOrganisation({} as CreateOrganisationBodyParams), | ||
organisationController.createOrganisation(permissionsMock, {} as CreateOrganisationBodyParams), | ||
).rejects.toThrow(HttpException); | ||
expect(organisationServiceMock.createOrganisation).toHaveBeenCalledTimes(1); | ||
}); | ||
|
@@ -719,6 +734,20 @@ describe('OrganisationController', () => { | |
}); | ||
|
||
describe('updateOrganisationName', () => { | ||
const permissionsMock: PersonPermissions = createMock<PersonPermissions>({ | ||
get personFields(): Person<true> { | ||
return createMock<Person<true>>({ | ||
familienname: 'current-user', | ||
}); | ||
}, | ||
getPersonenkontextewithRoles: (): Promise<PersonenkontextRolleFields[]> => | ||
Promise.resolve([ | ||
{ | ||
organisationsId: '', | ||
rolle: { systemrechte: [], serviceProviderIds: [] }, | ||
}, | ||
]), | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Siehe oben |
||
describe('when usecase succeeds', () => { | ||
it('should not throw an error', async () => { | ||
const oeffentlich: Organisation<true> = Organisation.construct( | ||
|
@@ -745,7 +774,9 @@ describe('OrganisationController', () => { | |
|
||
organisationRepositoryMock.updateKlassenname.mockResolvedValueOnce(oeffentlich); | ||
|
||
await expect(organisationController.updateOrganisationName(params, body)).resolves.not.toThrow(); | ||
await expect( | ||
organisationController.updateOrganisationName(params, body, permissionsMock), | ||
).resolves.not.toThrow(); | ||
}); | ||
}); | ||
|
||
|
@@ -760,9 +791,9 @@ describe('OrganisationController', () => { | |
}; | ||
organisationRepositoryMock.updateKlassenname.mockResolvedValueOnce(new NameRequiredForKlasseError()); | ||
|
||
await expect(organisationController.updateOrganisationName(params, body)).rejects.toThrow( | ||
NameRequiredForKlasseError, | ||
); | ||
await expect( | ||
organisationController.updateOrganisationName(params, body, permissionsMock), | ||
).rejects.toThrow(NameRequiredForKlasseError); | ||
}); | ||
}); | ||
|
||
|
@@ -778,14 +809,28 @@ describe('OrganisationController', () => { | |
|
||
organisationRepositoryMock.updateKlassenname.mockResolvedValueOnce(new EntityNotFoundError()); | ||
|
||
await expect(organisationController.updateOrganisationName(params, body)).rejects.toThrow( | ||
HttpException, | ||
); | ||
await expect( | ||
organisationController.updateOrganisationName(params, body, permissionsMock), | ||
).rejects.toThrow(HttpException); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('updateOrganisationName', () => { | ||
const permissionsMock: PersonPermissions = createMock<PersonPermissions>({ | ||
get personFields(): Person<true> { | ||
return createMock<Person<true>>({ | ||
familienname: 'current-user', | ||
}); | ||
}, | ||
getPersonenkontextewithRoles: (): Promise<PersonenkontextRolleFields[]> => | ||
Promise.resolve([ | ||
{ | ||
organisationsId: '', | ||
rolle: { systemrechte: [], serviceProviderIds: [] }, | ||
}, | ||
]), | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Siehe oben |
||
describe('when usecase succeeds', () => { | ||
it('should not throw an error', async () => { | ||
const oeffentlich: Organisation<true> = Organisation.construct( | ||
|
@@ -812,7 +857,9 @@ describe('OrganisationController', () => { | |
|
||
organisationRepositoryMock.updateKlassenname.mockResolvedValueOnce(oeffentlich); | ||
|
||
await expect(organisationController.updateOrganisationName(params, body)).resolves.not.toThrow(); | ||
await expect( | ||
organisationController.updateOrganisationName(params, body, permissionsMock), | ||
).resolves.not.toThrow(); | ||
}); | ||
}); | ||
|
||
|
@@ -827,9 +874,9 @@ describe('OrganisationController', () => { | |
}; | ||
organisationRepositoryMock.updateKlassenname.mockResolvedValueOnce(new NameRequiredForKlasseError()); | ||
|
||
await expect(organisationController.updateOrganisationName(params, body)).rejects.toThrow( | ||
NameRequiredForKlasseError, | ||
); | ||
await expect( | ||
organisationController.updateOrganisationName(params, body, permissionsMock), | ||
).rejects.toThrow(NameRequiredForKlasseError); | ||
}); | ||
}); | ||
|
||
|
@@ -845,9 +892,9 @@ describe('OrganisationController', () => { | |
|
||
organisationRepositoryMock.updateKlassenname.mockResolvedValueOnce(new EntityNotFoundError()); | ||
|
||
await expect(organisationController.updateOrganisationName(params, body)).rejects.toThrow( | ||
HttpException, | ||
); | ||
await expect( | ||
organisationController.updateOrganisationName(params, body, permissionsMock), | ||
).rejects.toThrow(HttpException); | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leeres Permissions-Objekt sollte an dieser Stelle ausreichend sein.