Skip to content

Commit

Permalink
[SELC-4684] Fix query to delete product in status ACTIVE
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminiaScarciofolo committed Apr 15, 2024
1 parent a74796a commit 8918f2d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ public Uni<Long> deleteUserInstitutionProduct(String userId, String institutionI

@Override
public Uni<Long> updateUserStatusWithOptionalFilterByInstitutionAndProduct(String userId, String institutionId, String productId, PartyRole role, String productRole, OnboardedProductState status) {
Map<String, Object> onboardedProductFilterMap;
if(status.equals(OnboardedProductState.ACTIVE)) {
onboardedProductFilterMap = OnboardedProductFilter.builder().productId(productId).role(role).productRole(productRole).status(SUSPENDED.name()).build().constructMap();
}else if(status.equals(SUSPENDED)) {
onboardedProductFilterMap = OnboardedProductFilter.builder().productId(productId).role(role).productRole(productRole).status(ACTIVE.name()).build().constructMap();
}else {
onboardedProductFilterMap = OnboardedProductFilter.builder().productId(productId).role(role).productRole(productRole).build().constructMap();
}
Map<String, Object> onboardedProductFilterMap = switch (status) {
case ACTIVE ->
OnboardedProductFilter.builder().productId(productId).role(role).productRole(productRole).status(SUSPENDED.name()).build().constructMap();
case SUSPENDED, DELETED ->
OnboardedProductFilter.builder().productId(productId).role(role).productRole(productRole).status(ACTIVE.name()).build().constructMap();
default ->
OnboardedProductFilter.builder().productId(productId).role(role).productRole(productRole).build().constructMap();
};
Map<String, Object> userInstitutionFilterMap = UserInstitutionFilter.builder().userId(userId).institutionId(institutionId).build().constructMap();
Map<String, Object> filterMap = userUtils.retrieveMapForFilter(onboardedProductFilterMap, userInstitutionFilterMap);
return updateUserStatusDao(filterMap, status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ void updateUserStatusToSuspendWithInstitutionAndOnboardedFilter() {
subscriber.assertCompleted().assertItem(1L);
}

@Test
void updateUserStatusToDeleteWithInstitutionAndOnboardedFilter() {
final String userId = "userId";
String institutionId = "institutionId";
String productId = "productId";
PanacheMock.mock(UserInstitution.class);
ReactivePanacheUpdate update = Mockito.mock(ReactivePanacheUpdate.class);
when(UserInstitution.update(any(Document.class)))
.thenReturn(update);
when(update.where(any())).thenReturn(Uni.createFrom().item(1L));
UniAssertSubscriber<Long> subscriber = userInstitutionService.updateUserStatusWithOptionalFilterByInstitutionAndProduct(userId, institutionId, productId, null, null, OnboardedProductState.DELETED)
.subscribe().withSubscriber(UniAssertSubscriber.create());
subscriber.assertCompleted().assertItem(1L);
}

@Test
void updateUserStatusToActiveWithInstitutionAndOnboardedFilter() {
final String userId = "userId";
Expand Down

0 comments on commit 8918f2d

Please sign in to comment.