Skip to content

Commit

Permalink
Add some (not super-useful) unit tests for ResultResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancrtr committed Oct 18, 2023
1 parent e2f9607 commit db26d6e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package gov.cdc.usds.simplereport.api.testresult;

import gov.cdc.usds.simplereport.api.Translators;
import gov.cdc.usds.simplereport.db.model.Result;
import gov.cdc.usds.simplereport.db.model.SupportedDisease;
import gov.cdc.usds.simplereport.db.model.auxiliary.TestResultsListItem;
import gov.cdc.usds.simplereport.service.DiseaseService;
import gov.cdc.usds.simplereport.service.ResultService;
import gov.cdc.usds.simplereport.service.TestOrderService;
Expand All @@ -22,7 +22,8 @@ public class ResultResolver {
private final DiseaseService diseaseService;

@QueryMapping
public Page<TestResultsListItem> resultsPage(
// public Page<TestResultsListItem> resultsPage(
public Page<Result> resultsPage(
@Argument UUID facilityId,
@Argument UUID patientId,
@Argument String result,
Expand All @@ -45,30 +46,28 @@ public Page<TestResultsListItem> resultsPage(
disease != null ? diseaseService.getDiseaseByName(disease) : null;

if (facilityId == null) {
return service
.getOrganizationResults(
patientId,
Translators.parseTestResult(result),
Translators.parsePersonRole(role, true),
supportedDisease,
startDate,
endDate,
pageNumber,
pageSize)
.map(TestResultsListItem::new);
return service.getOrganizationResults(
patientId,
Translators.parseTestResult(result),
Translators.parsePersonRole(role, true),
supportedDisease,
startDate,
endDate,
pageNumber,
pageSize);
// .map(TestResultsListItem::new);
}

return service
.getFacilityResults(
facilityId,
patientId,
Translators.parseTestResult(result),
Translators.parsePersonRole(role, true),
supportedDisease,
startDate,
endDate,
pageNumber,
pageSize)
.map(TestResultsListItem::new);
return service.getFacilityResults(
facilityId,
patientId,
Translators.parseTestResult(result),
Translators.parsePersonRole(role, true),
supportedDisease,
startDate,
endDate,
pageNumber,
pageSize);
// .map(TestResultsListItem::new);
}
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
package gov.cdc.usds.simplereport.api.testresult;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import gov.cdc.usds.simplereport.service.DiseaseService;
import gov.cdc.usds.simplereport.service.ResultService;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.springframework.data.domain.Page;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ExtendWith(SpringExtension.class)
public class ResultResolverTest {
@Mock ResultService resultService;

// @InjectMocks
// OrganizationResolver organizationMutationResolver;

@Test
void resultsPage_usesDefaultPaginationNumber() {
// GIVEN

// WHEN

// THEN
}

@Test
void resultsPage_usesDefaultPaginationSize() {
// GIVEN

// WHEN

// THEN
}

class ResultResolverTest {
@Test
void resultsPage_facilityId_null_returnsResultsForOrganization() {
// GIVEN
ResultService resultService = mock(ResultService.class);
DiseaseService diseaseService = mock(DiseaseService.class);

var sut = new ResultResolver(resultService, diseaseService);

// WHEN
when(resultService.getOrganizationResults(null, null, null, null, null, null, 0, 20))
.thenReturn(Page.empty());
sut.resultsPage(null, null, null, null, null, null, null, 0, 20);

// THEN
verify(resultService, times(1))
.getOrganizationResults(null, null, null, null, null, null, 0, 20);
}

@Test
void resultsPage_facilityId_notNull_returnsResultsForFacility() {
// GIVEN
ResultService resultService = mock(ResultService.class);
DiseaseService diseaseService = mock(DiseaseService.class);

var facilityId = UUID.randomUUID();
var sut = new ResultResolver(resultService, diseaseService);

// WHEN
when(resultService.getFacilityResults(facilityId, null, null, null, null, null, null, 0, 20))
.thenReturn(Page.empty());
sut.resultsPage(facilityId, null, null, null, null, null, null, 0, 20);

// THEN
verify(resultService, times(1))
.getFacilityResults(facilityId, null, null, null, null, null, null, 0, 20);
}
}

0 comments on commit db26d6e

Please sign in to comment.