Skip to content
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

[SELC-5400] fix: Added check on getUserFromPdv for check manager API #440

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1064,17 +1064,20 @@ public Uni<Boolean> checkManager(OnboardingUserRequest onboardingUserRequest) {
.collect().asList()
.onItem().transformToUni(this::getOnboardingList)
.onItem().ifNull().failWith(resourceNotFoundExceptionSupplier(onboardingUserRequest))
.onItem().transform(items ->
items.stream().map(onboarding -> onboarding.getUsers().stream()
.filter(userToOnboard -> PartyRole.MANAGER == userToOnboard.getRole())
.map(User::getId)
.findAny().orElse(null)).toList())
.onItem().transform(this::getManagerIds)
.onItem().transformToUni(uuids -> {
if (uuids.contains(uuid.toString())) {
return Uni.createFrom().item(true);
}
return Uni.createFrom().item(false);
}));
}))
.onFailure().recoverWithUni(ex -> {
if (ex instanceof ResourceNotFoundException
|| ((WebApplicationException) ex).getResponse().getStatus() != 404) {
return Uni.createFrom().failure(ex);
}
return Uni.createFrom().item(false);
});
}

public Uni<CustomError> checkRecipientCode(String recipientCode, String originId) {
Expand Down Expand Up @@ -1110,4 +1113,12 @@ private Uni<List<Onboarding>> getOnboardingList(List<Onboarding> onboardings) {
}
return Uni.createFrom().item(onboardings);
}

// Retrieve manager uuids from previous onboardings in case of workflowType USERS
private List<String> getManagerIds(List<Onboarding> onboardings) {
return onboardings.stream().map(onboarding -> onboarding.getUsers().stream()
.filter(userToOnboard -> PartyRole.MANAGER == userToOnboard.getRole())
.map(User::getId)
.findAny().orElse(null)).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,39 @@ void testCheckManager() {
assertFalse(subscriber.getItem());
}

@Test
void testCheckManagerWith404FromUserRegistry() {
OnboardingUserRequest request = createDummyUserRequest();
WebApplicationException exception = mock(WebApplicationException.class);
Response response = mock(Response.class);
when(response.getStatus()).thenReturn(404);
when(exception.getResponse()).thenReturn(response);
when(userRegistryApi.searchUsingPOST(any(), any()))
.thenReturn(Uni.createFrom().failure(exception));
UniAssertSubscriber<Boolean> subscriber = onboardingService
.checkManager(request)
.subscribe()
.withSubscriber(UniAssertSubscriber.create());
subscriber.assertCompleted();
assertFalse(subscriber.getItem());
}

@Test
void testCheckManagerWith500FromUserRegistry() {
OnboardingUserRequest request = createDummyUserRequest();
WebApplicationException exception = mock(WebApplicationException.class);
Response response = mock(Response.class);
when(response.getStatus()).thenReturn(500);
when(exception.getResponse()).thenReturn(response);
when(userRegistryApi.searchUsingPOST(any(), any()))
.thenReturn(Uni.createFrom().failure(exception));
UniAssertSubscriber<Boolean> subscriber = onboardingService
.checkManager(request)
.subscribe()
.withSubscriber(UniAssertSubscriber.create());
subscriber.assertFailedWith(WebApplicationException.class);
}

@Test
void testCheckManagerWithTrueCheck() {
final UUID uuid = UUID.randomUUID();
Expand Down
Loading