-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #487 from Health-Education-England/fix/removeDupli…
…cateDraft65c2415de6d8ff00033dd29b fix: remove duplicate draft for 7409676
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...n/java/uk/nhs/hee/tis/revalidation/changelog/RemoveDuplicateDraftFor7409676ChangeLog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...va/uk/nhs/hee/tis/revalidation/changelog/RemoveDuplicateDraftFor7409676ChangeLogTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |