diff --git a/src/main/java/app/coronawarn/quicktest/service/QuickTestService.java b/src/main/java/app/coronawarn/quicktest/service/QuickTestService.java index 9b531fae..4ab53485 100644 --- a/src/main/java/app/coronawarn/quicktest/service/QuickTestService.java +++ b/src/main/java/app/coronawarn/quicktest/service/QuickTestService.java @@ -148,13 +148,10 @@ public void updateQuickTest(Map ids, String shortHash, quicktest.setUpdatedAt(LocalDateTime.now()); - if ((quicktest.getTestResult() == QuickTest.TEST_RESULT_PCR_NEGATIVE - || quicktest.getTestResult() == QuickTest.TEST_RESULT_PCR_POSITIVE - || quicktest.getTestResult() == QuickTest.TEST_RESULT_NEGATIVE - || quicktest.getTestResult() == QuickTest.TEST_RESULT_POSITIVE) - && quicktest.getDccStatus() == null) { - if (quicktest.getConfirmationCwa() != null && quicktest.getConfirmationCwa() - && quicktest.getDccConsent() != null && quicktest.getDccConsent()) { + if (quicktest.getDccConsent() != null && quicktest.getDccConsent() && quicktest.getDccStatus() == null + && (quicktest.getTestResult() == QuickTest.TEST_RESULT_PCR_NEGATIVE + || quicktest.getTestResult() == QuickTest.TEST_RESULT_NEGATIVE)) { + if (quicktest.getConfirmationCwa() != null && quicktest.getConfirmationCwa()) { quicktest.setDccStatus(DccStatus.pendingPublicKey); } else { quicktest.setDccStatus(DccStatus.pendingSignatureNoCWA); diff --git a/src/test/java/app/coronawarn/quicktest/service/QuickTestServiceTest.java b/src/test/java/app/coronawarn/quicktest/service/QuickTestServiceTest.java index b050b1be..d90c0290 100644 --- a/src/test/java/app/coronawarn/quicktest/service/QuickTestServiceTest.java +++ b/src/test/java/app/coronawarn/quicktest/service/QuickTestServiceTest.java @@ -27,11 +27,7 @@ import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import app.coronawarn.quicktest.config.QuickTestConfig; import app.coronawarn.quicktest.domain.QuickTest; @@ -155,6 +151,54 @@ void addStatisticsInUpdateQuickTestIsCalledTest() throws ResponseStatusException assertNotEquals(captor.getValue().getCreatedAt(), pendingTest.getCreatedAt()); } + @Test + void deleteNonDccTests() throws ResponseStatusException, IOException { + QuickTestService qs = spy(quickTestService); + Map ids = new HashMap<>(); + QuickTest pendingTest = createPendingTest(); + pendingTest.setDccConsent(false); + pendingTest.setCreatedAt(Utilities.getCurrentLocalDateTimeUtc().minusMinutes(5)); + when(quickTestRepository.findByTenantIdAndPocIdAndShortHashedGuid(any(), any(), any())) + .thenReturn(pendingTest); + when(pdf.generatePdf(any(), any(), any())) + .thenReturn(new ByteArrayOutputStream()); + + QuickTestUpdateRequest quickTestUpdateRequest = new QuickTestUpdateRequest(); + quickTestUpdateRequest.setTestBrandId("testBrandId"); + quickTestUpdateRequest.setResult((short) 6); + quickTestUpdateRequest.setTestBrandName("TestBrandName"); + qs.updateQuickTest(ids, + "6fa4dcecf716d8dd96c9e927dda5484f1a8a9da03155aa760e0c38f9bed645c4", + quickTestUpdateRequest, + new ArrayList<>(), + "User"); + verify(quickTestRepository, times(1)).deleteById(pendingTest.getHashedGuid()); + } + + @Test + void keepDccTestsInQtTable() throws ResponseStatusException, IOException { + QuickTestService qs = spy(quickTestService); + Map ids = new HashMap<>(); + QuickTest pendingTest = createPendingTest(); + pendingTest.setDccConsent(true); + pendingTest.setCreatedAt(Utilities.getCurrentLocalDateTimeUtc().minusMinutes(5)); + when(quickTestRepository.findByTenantIdAndPocIdAndShortHashedGuid(any(), any(), any())) + .thenReturn(pendingTest); + when(pdf.generatePdf(any(), any(), any())) + .thenReturn(new ByteArrayOutputStream()); + + QuickTestUpdateRequest quickTestUpdateRequest = new QuickTestUpdateRequest(); + quickTestUpdateRequest.setDccTestManufacturerId("testBrandId"); + quickTestUpdateRequest.setResult((short) 6); + quickTestUpdateRequest.setDccTestManufacturerDescription("TestBrandName"); + qs.updateQuickTest(ids, + "6fa4dcecf716d8dd96c9e927dda5484f1a8a9da03155aa760e0c38f9bed645c4", + quickTestUpdateRequest, + new ArrayList<>(), + "User"); + verify(quickTestRepository, never()).deleteById(pendingTest.getHashedGuid()); + } + @Test void createPdfInUpdateQuickTestIoExceptionTest() throws IOException { Map ids = new HashMap<>();