INFRA-3232 | Dhruv | fixes issue with same token request and change request id

This commit is contained in:
dhruvjoshi
2024-08-26 20:33:21 +05:30
parent d0d6f68152
commit ba456bd230
4 changed files with 7 additions and 4 deletions

View File

@@ -21,6 +21,9 @@ public interface ApprovalRequestRepository extends CrudRepository<ApprovalReques
@Query(value = "SELECT ar.* FROM approval_request ar WHERE request_id = :requestId", nativeQuery = true)
List<ApprovalRequest> findByRequestId(Long requestId);
@Query(value = "SELECT ar.* FROM approval_request ar WHERE request_id = :requestId AND request_type = :requestType", nativeQuery = true)
List<ApprovalRequest> findByRequestIdAndType(Long requestId, int requestType);
@Query(value = "SELECT ar.* FROM approval_request ar WHERE status = 100 AND team_id IN :teamIds AND request_type = :requestType",
nativeQuery = true)
List<ApprovalRequest> findAllPendingByRequestTypeAndTeamIds(int requestType,

View File

@@ -129,7 +129,8 @@ public class ApprovalRequestServiceImpl implements ApprovalRequestService {
public Iterable<ApprovalRequest> createApprovals(ChangeRequest changeRequest) {
final var manifest = findManifestById(changeRequest.getManifestId());
final var oldApprovalList = repository.findByRequestId(changeRequest.getId());
final var oldApprovalList = repository.findByRequestIdAndType(changeRequest.getId(),
CHANGE_REQUEST.code);
final var newApprovalList = getRequiredApprovalList(changeRequest,
manifest.getEnvironment(),
(String) ((HashMap<String, Object>) manifest.getData().get("team")).get("name"));

View File

@@ -299,7 +299,6 @@ public class ChangeRequestSlackServiceImpl implements ChangeRequestSlackService
var teamList = approvalRequests.stream().map(ApprovalRequest::getTeamId)
.collect(Collectors.toList());
var teamUserPrivilegesMap = teamService.findTeamBasedUserPrivilegesForEachTeam(teamList);
log.info("Team based user privileges map: {}", objectMapper.writeValueAsString(teamUserPrivilegesMap));
var teamApproversMap = findApproversForEachTeam(teamUserPrivilegesMap, manifest);
log.info("Team based approvers map: {}", objectMapper.writeValueAsString(teamApproversMap));
var teamsWithNoReviewers = findTeamsWithNoReviewers(teamApproversMap);

View File

@@ -231,7 +231,7 @@ public class ApprovalRequestServiceImplTest {
final var savedNewApprovalRequest2 = new ApprovalRequestBuilder().from(newApprovalRequest2)
.setId(3L).createApprovalRequest();
when(repo.findByRequestId(changeRequest.getId())).thenReturn(oldApprovals);
when(repo.findByRequestIdAndType(changeRequest.getId(), RequestType.CHANGE_REQUEST.code)).thenReturn(oldApprovals);
when(teamService.findByNames(argThat(
listMatches(List.of(team1.getName(), team2.getName(), team3.getName()))))).thenReturn(
List.of(team1, team2, team3));
@@ -254,7 +254,7 @@ public class ApprovalRequestServiceImplTest {
service.createApprovals(changeRequest);
verify(repo).findByRequestId(changeRequest.getId());
verify(repo).findByRequestIdAndType(changeRequest.getId(), RequestType.CHANGE_REQUEST.code);
verify(teamService).findByNames(argThat(
listMatches(List.of(team1.getName(), team2.getName(), team3.getName()))));
verify(manifestRepository).findById(changeRequest.getManifestId());