Skip to content

Commit

Permalink
Merge pull request #487 from Health-Education-England/fix/removeDupli…
Browse files Browse the repository at this point in the history
…cateDraft65c2415de6d8ff00033dd29b

fix: remove duplicate draft for 7409676
  • Loading branch information
JosephKelly authored Apr 16, 2024
2 parents f7a5c1d + 456ff23 commit 83114a7
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package uk.nhs.hee.tis.revalidation.changelog;

import com.github.cloudyrock.mongock.ChangeLog;
import com.github.cloudyrock.mongock.ChangeSet;
import java.util.Optional;
import uk.nhs.hee.tis.revalidation.entity.Recommendation;
import uk.nhs.hee.tis.revalidation.repository.RecommendationRepository;

@ChangeLog(order = "008")
public class RemoveDuplicateDraftFor7409676ChangeLog {

private static final String RECOMMENDATION_ID = "65c2415de6d8ff00033dd29b";

@ChangeSet(order="001", id = "removeInvalidRecommendationForDoctor7409676", author = "")
public void removeDuplicateDraftFor7409676(
RecommendationRepository recommendationRepository
) {
Optional<Recommendation> recommendation = recommendationRepository.findById(
RECOMMENDATION_ID
);
if(recommendation.isPresent()) {
recommendationRepository.delete(recommendation.get());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package uk.nhs.hee.tis.revalidation.changelog;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import uk.nhs.hee.tis.revalidation.entity.Recommendation;
import uk.nhs.hee.tis.revalidation.repository.RecommendationRepository;

@ExtendWith(MockitoExtension.class)
class RemoveDuplicateDraftFor7409676ChangeLogTest {

@InjectMocks
RemoveDuplicateDraftFor7409676ChangeLog changeLog;

@Mock
RecommendationRepository recommendationRepository;

private static final String RECOMMENDATION_ID = "65c2415de6d8ff00033dd29b";

@BeforeEach
void setup() {
changeLog = new RemoveDuplicateDraftFor7409676ChangeLog();
}

@Test
void shouldRemoveRecommendationWithGivenIdIfPresent() {
var testRecommendation = buildTestRecommendation();

when(recommendationRepository.findById(RECOMMENDATION_ID))
.thenReturn(Optional.of(testRecommendation));

changeLog.removeDuplicateDraftFor7409676(recommendationRepository);

verify(recommendationRepository).delete(testRecommendation);
}

@Test
void shouldNotRemoveRecommendationWithGivenIdIfNotPresent() {
when(recommendationRepository.findById(RECOMMENDATION_ID))
.thenReturn(Optional.empty());

changeLog.removeDuplicateDraftFor7409676(recommendationRepository);

verify(recommendationRepository, never()).delete(any());
}

private Recommendation buildTestRecommendation() {
return Recommendation.builder()
.id(RECOMMENDATION_ID)
.build();
}
}

0 comments on commit 83114a7

Please sign in to comment.