Skip to content

Commit

Permalink
amend sql to fix failing test against h2 db
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj committed Dec 11, 2024
1 parent 1d9a0a9 commit 177fb1f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ class SentenceIntegrationTest {
),
"3 minutes completed (of 12 hours)",
listOf(
LicenceCondition(
LC_WITHOUT_NOTES.id,
LIC_COND_MAIN_CAT.description,
imposedReleasedDate = LocalDate.now().minusDays(14),
licenceConditionNotes = listOf()
),
LicenceCondition(
LC_WITH_NOTES.id,
LIC_COND_MAIN_CAT.description,
Expand Down Expand Up @@ -181,12 +187,6 @@ class SentenceIntegrationTest {
)
)
),
LicenceCondition(
LC_WITHOUT_NOTES.id,
LIC_COND_MAIN_CAT.description,
imposedReleasedDate = LocalDate.now().minusDays(14),
licenceConditionNotes = listOf()
),
LicenceCondition(
LC_WITH_NOTES_WITHOUT_ADDED_BY.id,
LIC_COND_MAIN_CAT.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface LicenceConditionRepository : JpaRepository<LicenceCondition, Long> {
JOIN FETCH lc.mainCategory mc
LEFT JOIN FETCH lc.subCategory
WHERE lc.disposalId = :disposalId
ORDER BY mc.description ASC
ORDER BY mc.description, lc.id ASC
"""
)
fun findAllByDisposalId(disposalId: Long): List<LicenceCondition>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ interface OffenderManagerRepository : JpaRepository<OffenderManager, Long> {

fun countOffenderManagersByPerson(person: Person): Long

fun findOffenderManagersByPersonOrderByEndDateDesc(person: Person): List<OffenderManager>
@Query("""
SELECT om
FROM OffenderManager om
WHERE om.person.id = :id
ORDER BY om.endDate NULLS FIRST
""")
fun findOffenderManagersByPersonOrderByEndDateDesc(id: Long): List<OffenderManager>
}

fun OffenderManagerRepository.getByCrn(crn: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ContactService(

fun getContacts(crn: String): ProfessionalContact {
val person = personRepository.getPerson(crn)
val contacts = offenderManagerRepository.findOffenderManagersByPersonOrderByEndDateDesc(person)
val contacts = offenderManagerRepository.findOffenderManagersByPersonOrderByEndDateDesc(person.id)

if (contacts.isEmpty()) {
throw NotFoundException("Offender Manager records", "crn", crn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ContactServiceTest {
fun `no offender manager records`() {
whenever(personRepository.findByCrn(PersonGenerator.OVERVIEW.crn)).thenReturn(PersonGenerator.OVERVIEW)
whenever(
offenderManagerRepository.findOffenderManagersByPersonOrderByEndDateDesc(PersonGenerator.OVERVIEW)
offenderManagerRepository.findOffenderManagersByPersonOrderByEndDateDesc(PersonGenerator.OVERVIEW.id)
).thenReturn(listOf())

val exception = assertThrows<NotFoundException> {
Expand All @@ -81,7 +81,7 @@ class ContactServiceTest {

verify(personRepository, times(1)).findByCrn(PersonGenerator.OVERVIEW.crn)
verify(offenderManagerRepository, times(1)).findOffenderManagersByPersonOrderByEndDateDesc(
PersonGenerator.OVERVIEW
PersonGenerator.OVERVIEW.id
)

verifyNoMoreInteractions(personRepository)
Expand All @@ -108,7 +108,7 @@ class ContactServiceTest {

whenever(personRepository.findByCrn(PersonGenerator.OVERVIEW.crn)).thenReturn(PersonGenerator.OVERVIEW)
whenever(
offenderManagerRepository.findOffenderManagersByPersonOrderByEndDateDesc(PersonGenerator.OVERVIEW)
offenderManagerRepository.findOffenderManagersByPersonOrderByEndDateDesc(PersonGenerator.OVERVIEW.id)
).thenReturn(
listOf(OFFENDER_MANAGER_ACTIVE, OFFENDER_MANAGER_INACTIVE)
)
Expand All @@ -119,7 +119,7 @@ class ContactServiceTest {

verify(personRepository, times(1)).findByCrn(PersonGenerator.OVERVIEW.crn)
verify(offenderManagerRepository, times(1)).findOffenderManagersByPersonOrderByEndDateDesc(
PersonGenerator.OVERVIEW
PersonGenerator.OVERVIEW.id
)

verifyNoMoreInteractions(personRepository)
Expand Down

0 comments on commit 177fb1f

Please sign in to comment.