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.
Browse files
Browse the repository at this point in the history
* implement `registerCreation(employer)` * check ID mapping before creation
- Loading branch information
1 parent
5168863
commit 80d2ffa
Showing
10 changed files
with
423 additions
and
28 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
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
6 changes: 6 additions & 0 deletions
6
...ain/kotlin/uk/gov/justice/digital/hmpps/jobsboardintegrationapi/refdata/domain/RefData.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package uk.gov.justice.digital.hmpps.jobsboardintegrationapi.refdata.domain | ||
|
||
enum class RefData(val type: String) { | ||
EmployerStatus("employer_status"), | ||
EmployerSector("employer_sector"), | ||
} |
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
94 changes: 94 additions & 0 deletions
94
...ce/digital/hmpps/jobsboardintegrationapi/employers/application/EmployerRegistrarShould.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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package uk.gov.justice.digital.hmpps.jobsboardintegrationapi.employers.application | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Nested | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.kotlin.never | ||
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.whenever | ||
import uk.gov.justice.digital.hmpps.jobsboardintegrationapi.employers.domain.Employer | ||
import uk.gov.justice.digital.hmpps.jobsboardintegrationapi.employers.domain.EmployerObjects.mnEmployer | ||
import uk.gov.justice.digital.hmpps.jobsboardintegrationapi.employers.domain.EmployerObjects.sainsburys | ||
import uk.gov.justice.digital.hmpps.jobsboardintegrationapi.shared.application.UnitTestBase | ||
import uk.gov.justice.digital.hmpps.jobsboardintegrationapi.shared.infrastructure.MNEmployer | ||
import kotlin.test.assertFailsWith | ||
|
||
class EmployerRegistrarShould : UnitTestBase() { | ||
@Mock | ||
private lateinit var employerService: EmployerService | ||
|
||
@InjectMocks | ||
private lateinit var employerRegistrar: EmployerRegistrar | ||
|
||
@Nested | ||
@DisplayName("Given a valid employer to be registered") | ||
inner class GivenAnEmployerToRegister { | ||
private val employer = sainsburys | ||
private val externalId = 1L | ||
private val mnEmployer = employer.mnEmployer(externalId) | ||
private val mnEmployerNoId = mnEmployer.copy(id = null) | ||
|
||
@Test | ||
fun `register a valid employer`() { | ||
givenMNEmployerCreated(employer, mnEmployerNoId, mnEmployer) | ||
|
||
employerRegistrar.registerCreation(employer) | ||
|
||
verify(employerService).createIdMapping(externalId, employer.id) | ||
} | ||
|
||
@Test | ||
fun `skip registering existing employer`() { | ||
val id = employer.id | ||
whenever(employerService.existsIdMappingById(id)).thenReturn(true) | ||
|
||
employerRegistrar.registerCreation(employer) | ||
|
||
verify(employerService, never()).convert(employer) | ||
verify(employerService, never()).create(mnEmployerNoId) | ||
verify(employerService, never()).createIdMapping(externalId, id) | ||
} | ||
|
||
@Test | ||
fun `NOT finish registering employer without external ID received`() { | ||
givenMNEmployerCreated(employer, mnEmployerNoId, mnEmployerNoId) | ||
|
||
val exception = assertFailsWith<Exception> { | ||
employerRegistrar.registerCreation(employer) | ||
} | ||
|
||
assertThat(exception.message) | ||
.startsWith("Fail to register employer-creation").contains("employerId=${employer.id}") | ||
with(exception.cause) { | ||
assertThat(this).isNotNull.isInstanceOfAny(AssertionError::class.java) | ||
assertThat(this!!.message) | ||
.startsWith("MN Employer ID is missing!").contains("employerId=${employer.id}") | ||
} | ||
verify(employerService, never()).createIdMapping(externalId, employer.id) | ||
} | ||
|
||
@Test | ||
fun `NOT finish registering employer, with ID mapping clash while saving it`() { | ||
whenever(employerService.existsIdMappingById(employer.id)).thenReturn(false, true) | ||
whenever(employerService.convert(employer)).thenReturn(mnEmployerNoId) | ||
whenever(employerService.create(mnEmployerNoId)).thenReturn(mnEmployer) | ||
whenever(employerService.createIdMapping(externalId, employer.id)).thenCallRealMethod() | ||
|
||
val exception = assertFailsWith<Exception> { | ||
employerRegistrar.registerCreation(employer) | ||
} | ||
|
||
assertThat(exception.message) | ||
.startsWith("Fail to register employer-creation").contains("employerId=${employer.id}") | ||
} | ||
} | ||
|
||
private fun givenMNEmployerCreated(employer: Employer, convertedEmployer: MNEmployer, mnEmployer: MNEmployer) { | ||
whenever(employerService.existsIdMappingById(employer.id)).thenReturn(false) | ||
whenever(employerService.convert(employer)).thenReturn(convertedEmployer) | ||
whenever(employerService.create(convertedEmployer)).thenReturn(mnEmployer) | ||
} | ||
} |
Oops, something went wrong.