Skip to content
Snippets Groups Projects
Commit c26cd0ca authored by Felix Reichenbach's avatar Felix Reichenbach
Browse files

OZG-7474 check user role as itnended

parent 13ec98a7
Branches
Tags
1 merge request!11OZG-7474 OZG-7610 add forward by ozg cloud link, move forward by email into new processor
......@@ -39,15 +39,15 @@ class ForwardingVorgangWithEingangProcessor implements RepresentationModelProces
}
boolean isForwardableByOzgCloud(VorgangWithEingang vorgang) {
return featureToggleProperties.isForwardByOzgCloudEnabled() && isStatusNeu(vorgang) && isNeitherPoststelleNorEinheitlicherAnsprechpartner();
return featureToggleProperties.isForwardByOzgCloudEnabled() && isStatusNeu(vorgang) && isVerwaltungUser();
}
private boolean isStatusNeu(VorgangWithEingang vorgang) {
return vorgang.getStatus() == VorgangStatus.NEU;
}
boolean isNeitherPoststelleNorEinheitlicherAnsprechpartner() {
return !(userService.hasRole(UserRole.EINHEITLICHER_ANSPRECHPARTNER) || userService.hasRole(UserRole.VERWALTUNG_POSTSTELLE));
private boolean isVerwaltungUser() {
return userService.hasRole(UserRole.VERWALTUNG_USER);
}
private Link buildForwardByOzgCloudLink(VorgangWithEingang vorgang) {
......
......@@ -185,12 +185,12 @@ class ForwardingVorgangWithEingangProcessorTest {
@ParameterizedTest
@EnumSource
void shouldNotCallIsNeitherPoststelleNorEinheitlicherAnsprechpartner(VorgangStatus status) {
void shouldNotCallUserService(VorgangStatus status) {
var vorgang = VorgangWithEingangTestFactory.createBuilder().status(status).build();
processor.isForwardableByOzgCloud(vorgang);
verify(processor, never()).isNeitherPoststelleNorEinheitlicherAnsprechpartner();
verify(userService, never()).hasRole(any());
}
}
......@@ -216,12 +216,12 @@ class ForwardingVorgangWithEingangProcessorTest {
@ParameterizedTest
@EnumSource(mode = Mode.EXCLUDE, names = { "NEU" })
void shouldNotCallisNeitherPoststelleNorEinheitlicherAnsprechpartner(VorgangStatus status) {
void shouldNotCallUserService(VorgangStatus status) {
var vorgang = VorgangWithEingangTestFactory.createBuilder().status(status).build();
processor.isForwardableByOzgCloud(vorgang);
verify(processor, never()).isNeitherPoststelleNorEinheitlicherAnsprechpartner();
verify(userService, never()).hasRole(any());
}
}
......@@ -231,104 +231,20 @@ class ForwardingVorgangWithEingangProcessorTest {
private final VorgangWithEingang newVorgang = VorgangWithEingangTestFactory.createBuilder().status(VorgangStatus.NEU).build();
@Test
void shouldCallisNeitherPoststelleNorEinheitlicherAnsprechpartner() {
void shouldCheckUserRole() {
processor.isForwardableByOzgCloud(newVorgang);
verify(processor).isNeitherPoststelleNorEinheitlicherAnsprechpartner();
verify(userService).hasRole(UserRole.VERWALTUNG_USER);
}
@ParameterizedTest
@ValueSource(booleans = { true, false })
void shouldReturnValueOfisNeitherPoststelleNorEinheitlicherAnsprechpartner(
boolean isNeitherPoststelleNorEinheitlicherAnsprechpartner) {
doReturn(isNeitherPoststelleNorEinheitlicherAnsprechpartner).when(processor).isNeitherPoststelleNorEinheitlicherAnsprechpartner();
void shouldReturnValueOfHasVerwaltungUserRole(boolean isVerwaltungUser) {
when(userService.hasRole(UserRole.VERWALTUNG_USER)).thenReturn(isVerwaltungUser);
var forwardableByOzgCloud = processor.isForwardableByOzgCloud(newVorgang);
assertThat(forwardableByOzgCloud).isEqualTo(isNeitherPoststelleNorEinheitlicherAnsprechpartner);
}
}
}
}
@Nested
class TestIsNeitherPoststelleNorEinheitlicherAnsprechpartner {
@BeforeEach
void mock() {
when(userService.hasRole(any())).thenAnswer(invocation -> {
var role = invocation.getArgument(0, String.class);
return role == UserRole.EINHEITLICHER_ANSPRECHPARTNER || role == UserRole.VERWALTUNG_POSTSTELLE;
});
}
@Test
void shouldCallUserServiceForCurrentRole() {
processor.isNeitherPoststelleNorEinheitlicherAnsprechpartner();
verify(userService).hasRole(UserRole.EINHEITLICHER_ANSPRECHPARTNER);
}
@Nested
class TestOnIsEinheitlicherAnsprechpartner {
@BeforeEach
void givenIsEinheitlicherAnsprechpartner() {
when(userService.hasRole(UserRole.EINHEITLICHER_ANSPRECHPARTNER)).thenReturn(true);
}
@Test
void shouldReturnFalse() {
var isNeitherPoststelleNorEinheitlicherAnsprechpartner = processor.isNeitherPoststelleNorEinheitlicherAnsprechpartner();
assertThat(isNeitherPoststelleNorEinheitlicherAnsprechpartner).isFalse();
}
}
@Nested
class TestOnIsNotEinheitlicherAnsprechpartner {
@BeforeEach
void givenIsNotEinheitlicherAnsprechpartner() {
when(userService.hasRole(UserRole.EINHEITLICHER_ANSPRECHPARTNER)).thenReturn(false);
}
@Test
void shouldCallUserServiceForCurrentRole() {
processor.isNeitherPoststelleNorEinheitlicherAnsprechpartner();
verify(userService).hasRole(UserRole.VERWALTUNG_POSTSTELLE);
}
@Nested
class TestOnIsPoststelle {
@BeforeEach
void givenIsEinheitlicherAnsprechpartner() {
when(userService.hasRole(UserRole.VERWALTUNG_POSTSTELLE)).thenReturn(true);
}
@Test
void shouldReturnFalse() {
var isNeitherPoststelleNorEinheitlicherAnsprechpartner = processor.isNeitherPoststelleNorEinheitlicherAnsprechpartner();
assertThat(isNeitherPoststelleNorEinheitlicherAnsprechpartner).isFalse();
}
}
@Nested
class TestOnIsNotPoststelle {
@BeforeEach
void givenIsEinheitlicherAnsprechpartner() {
when(userService.hasRole(UserRole.VERWALTUNG_POSTSTELLE)).thenReturn(false);
}
@Test
void shouldReturnTrue() {
var isNeitherPoststelleNorEinheitlicherAnsprechpartner = processor.isNeitherPoststelleNorEinheitlicherAnsprechpartner();
assertThat(isNeitherPoststelleNorEinheitlicherAnsprechpartner).isTrue();
assertThat(forwardableByOzgCloud).isEqualTo(isVerwaltungUser);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment