Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

fix: delete non dcc tests after result update from qt table #249

Merged
merged 2 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,10 @@ public void updateQuickTest(Map<String, String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> 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<String, String> 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<String, String> ids = new HashMap<>();
Expand Down