Skip to content

Commit

Permalink
Refactore as per comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Ewan Donovan committed Feb 27, 2025
1 parent 3a089ab commit de03d48
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package uk.gov.justice.digital.hmpps.learnerrecordsapi.service

import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.db.MatchEntity
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.ConfirmMatchRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.CheckMatchResponse
import uk.gov.justice.digital.hmpps.learnerrecordsapi.repository.MatchRepository
import uk.gov.justice.hmpps.kotlin.sar.HmppsSubjectAccessRequestContent
import java.time.LocalDate

@Service
Expand Down Expand Up @@ -34,9 +34,15 @@ class MatchService(
nomisId: String,
fromDate: LocalDate?,
toDate: LocalDate?,
): List<MatchEntity> = matchRepository.findForSubjectAccessRequest(
nomisId,
fromDate?.atStartOfDay(),
toDate?.plusDays(1)?.atStartOfDay()?.minusNanos(1L),
)
): HmppsSubjectAccessRequestContent? {
val foundData = matchRepository.findForSubjectAccessRequest(
nomisId,
fromDate?.atStartOfDay(),
toDate?.plusDays(1)?.atStartOfDay()?.minusNanos(1L),
)
return when (foundData.size) {
0 -> null
else -> HmppsSubjectAccessRequestContent(content = foundData)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,5 @@ class SubjectAccessRequestService(
prn: String,
fromDate: LocalDate?,
toDate: LocalDate?,
): HmppsSubjectAccessRequestContent? {
val foundData = matchService.getDataForSubjectAccessRequest(prn, fromDate, toDate)
return when (foundData.size) {
0 -> null
else -> HmppsSubjectAccessRequestContent(content = foundData)
}
}
): HmppsSubjectAccessRequestContent? = matchService.getDataForSubjectAccessRequest(prn, fromDate, toDate)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.mockito.Mockito.mock
import org.mockito.Mockito.reset
import org.mockito.Mockito.`when`
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.db.MatchEntity
import uk.gov.justice.hmpps.kotlin.sar.HmppsSubjectAccessRequestContent

class SubjectAccessRequestServiceTest {
private val mockMatchService = mock(MatchService::class.java)
Expand All @@ -19,7 +20,7 @@ class SubjectAccessRequestServiceTest {

@Test
fun `returns null for not found`() {
`when`(mockMatchService.getDataForSubjectAccessRequest("B12345", null, null)).thenReturn(listOf())
`when`(mockMatchService.getDataForSubjectAccessRequest("B12345", null, null)).thenReturn(null)
assertThat(service.getPrisonContentFor("B12345", null, null)).isNull()
}

Expand All @@ -30,7 +31,7 @@ class SubjectAccessRequestServiceTest {
MatchEntity(1, "A12345", "def"),
MatchEntity(1, "A12345", "ghi"),
)
`when`(mockMatchService.getDataForSubjectAccessRequest("A12345", null, null)).thenReturn(expectedData)
`when`(mockMatchService.getDataForSubjectAccessRequest("A12345", null, null)).thenReturn(HmppsSubjectAccessRequestContent(expectedData))
val actualData = service.getPrisonContentFor("A12345", null, null)?.content
assertThat(actualData).isEqualTo(expectedData)
}
Expand Down

0 comments on commit de03d48

Please sign in to comment.