Skip to content

Commit

Permalink
MAN-156 - update test
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj committed Nov 15, 2024
1 parent b28658d commit e3584f9
Showing 1 changed file with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package uk.gov.justice.digital.hmpps

import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
Expand All @@ -21,6 +21,7 @@ import uk.gov.justice.digital.hmpps.data.generator.OffenderManagerGenerator.STAF
import uk.gov.justice.digital.hmpps.data.generator.OffenderManagerGenerator.TEAM
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.AppointmentRepository
import uk.gov.justice.digital.hmpps.test.CustomMatchers.isCloseTo
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withJson
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken
Expand Down Expand Up @@ -77,7 +78,14 @@ class AppointmentOutcomeIntegrationTest {
@Test
fun `outcome updated`() {
val response = createAppointment()
val request = Outcome(response.appointments[0].id, "ATTC", false, "my notes")
val createdAppointment = appointmentRepository.findById(response.appointments[0].id).get()

assertNull(createdAppointment.attended)
assertNull(createdAppointment.notes)
assertNull(createdAppointment.outcomeId)
assertNull(createdAppointment.sensitive)

val request = Outcome(response.appointments[0].id, "ATTC", notes = "my notes")

mockMvc
.perform(MockMvcRequestBuilders.patch("/appointment")
Expand All @@ -86,14 +94,24 @@ class AppointmentOutcomeIntegrationTest {
)
.andExpect(MockMvcResultMatchers.status().isOk)

val appointment = appointmentRepository.findById(response.appointments[0].id).get()
assertEquals("Y", appointment.attended)
assertEquals(request.notes, appointment.notes)
assertEquals(ATTENDED_COMPLIED.id, appointment.outcomeId)
assertFalse(appointment.sensitive!!)
val updatedAppointment = appointmentRepository.findById(response.appointments[0].id).get()
assertEquals("Y", updatedAppointment.attended)
assertEquals(request.notes, updatedAppointment.notes)
assertEquals(ATTENDED_COMPLIED.id, updatedAppointment.outcomeId)
assertFalse(updatedAppointment.sensitive!!)

assertThat(updatedAppointment.type.code, equalTo(createdAppointment.type.code))
assertThat(updatedAppointment.date, equalTo(createdAppointment.date))
assertThat(updatedAppointment.startTime, isCloseTo(createdAppointment.startTime))
assertThat(updatedAppointment.externalReference, equalTo(createdAppointment.externalReference))
assertThat(updatedAppointment.eventId, equalTo(createdAppointment.eventId))
assertThat(updatedAppointment.createdByUserId, equalTo(createdAppointment.createdByUserId))
assertThat(updatedAppointment.staffId, equalTo(createdAppointment.staffId))
assertThat(updatedAppointment.probationAreaId, equalTo(createdAppointment.probationAreaId))
assertThat(updatedAppointment.officeLocationId, equalTo(createdAppointment.officeLocationId))


appointmentRepository.delete(appointment)
appointmentRepository.delete(updatedAppointment)
}

private fun createAppointment() = mockMvc.perform(
Expand Down

0 comments on commit e3584f9

Please sign in to comment.