generated from ministryofjustice/hmpps-template-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDPS-1054: Updated resource and service tests for core person record.
- Loading branch information
Showing
3 changed files
with
58 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 51 additions & 2 deletions
53
...igital/hmpps/personintegrationapi/corepersonrecord/service/CorePersonRecordServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,59 @@ | ||
package uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.service | ||
|
||
import org.junit.jupiter.api.AfterEach | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Nested | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.reset | ||
import org.mockito.kotlin.whenever | ||
import org.springframework.http.ResponseEntity | ||
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.PrisonApiClient | ||
import uk.gov.justice.digital.hmpps.personintegrationapi.common.client.dto.UpdateBirthPlace | ||
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.enumeration.CorePersonRecordField | ||
import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.exception.UnknownCorePersonFieldException | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
class CorePersonRecordServiceTest { | ||
|
||
@Test | ||
fun updateCorePersonRecordField() { | ||
@Mock | ||
lateinit var prisonApiClient: PrisonApiClient | ||
|
||
@InjectMocks | ||
lateinit var underTest: CorePersonRecordService | ||
|
||
@AfterEach | ||
fun afterEach() { | ||
reset(prisonApiClient) | ||
} | ||
|
||
@BeforeEach | ||
fun beforeEach() { | ||
whenever(prisonApiClient.updateBirthPlaceForWorkingName(PRISONER_NUMBER, TEST_BIRTHPLACE_BODY)).thenReturn(ResponseEntity.noContent().build()) | ||
} | ||
|
||
@Nested | ||
inner class UpdateCorePersonRecordField { | ||
@Test | ||
fun `can update the birthplace field`() { | ||
underTest.updateCorePersonRecordField(PRISONER_NUMBER, CorePersonRecordField.BIRTHPLACE, TEST_BIRTHPLACE_VALUE) | ||
} | ||
|
||
@Test | ||
fun `throws an exception if the field type is not supported`() { | ||
assertThrows<UnknownCorePersonFieldException> { | ||
underTest.updateCorePersonRecordField(PRISONER_NUMBER, CorePersonRecordField.COUNTRY_OF_BIRTH, "") | ||
} | ||
} | ||
} | ||
|
||
private companion object { | ||
const val PRISONER_NUMBER = "A1234AA" | ||
const val TEST_BIRTHPLACE_VALUE = "London" | ||
val TEST_BIRTHPLACE_BODY = UpdateBirthPlace("London") | ||
} | ||
} |