generated from ministryofjustice/template-repository
-
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
* PI-1991: Added schedule endpoints * PI-1991: Added schedule endpoints * PI-1991: Added schedule endpoints * PI-1991: Added schedule endpoints
- Loading branch information
Showing
21 changed files
with
905 additions
and
41 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
101 changes: 101 additions & 0 deletions
101
...delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ScheduleIntegrationTest.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,101 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import uk.gov.justice.digital.hmpps.api.model.schedule.PersonAppointment | ||
import uk.gov.justice.digital.hmpps.api.model.schedule.Schedule | ||
import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.OVERVIEW | ||
import uk.gov.justice.digital.hmpps.service.toAppointment | ||
import uk.gov.justice.digital.hmpps.service.toDocument | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
internal class ScheduleIntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Test | ||
fun `upcoming schedule is returned`() { | ||
|
||
val person = OVERVIEW | ||
val res = mockMvc | ||
.perform(get("/schedule/${person.crn}/upcoming").withToken()) | ||
.andExpect(status().isOk) | ||
.andReturn().response.contentAsJson<Schedule>() | ||
|
||
assertThat(res.personSummary.crn, equalTo(person.crn)) | ||
assertThat(res.appointments[0].id, equalTo(ContactGenerator.FIRST_APPT_CONTACT.toAppointment().id)) | ||
assertThat(res.appointments[0].type, equalTo(ContactGenerator.FIRST_APPT_CONTACT.toAppointment().type)) | ||
assertThat( | ||
res.appointments[0].location?.officeName, | ||
equalTo(ContactGenerator.FIRST_APPT_CONTACT.toAppointment().location?.officeName) | ||
) | ||
assertThat(res.appointments[0].location?.postcode, equalTo("H34 7TH")) | ||
} | ||
|
||
@Test | ||
fun `previous schedule is returned`() { | ||
|
||
val person = OVERVIEW | ||
val res = mockMvc | ||
.perform(get("/schedule/${person.crn}/previous").withToken()) | ||
.andExpect(status().isOk) | ||
.andReturn().response.contentAsJson<Schedule>() | ||
assertThat(res.personSummary.crn, equalTo(person.crn)) | ||
assertThat(res.appointments[0].id, equalTo(ContactGenerator.PREVIOUS_APPT_CONTACT_ABSENT.toAppointment().id)) | ||
assertThat( | ||
res.appointments[0].type, | ||
equalTo(ContactGenerator.PREVIOUS_APPT_CONTACT_ABSENT.toAppointment().type) | ||
) | ||
assertThat( | ||
res.appointments[0].location?.officeName, | ||
equalTo(ContactGenerator.PREVIOUS_APPT_CONTACT_ABSENT.toAppointment().location?.officeName) | ||
) | ||
assertThat(res.appointments[0].location?.postcode, equalTo("H34 7TH")) | ||
} | ||
|
||
@Test | ||
fun `previous schedule not found status returned`() { | ||
mockMvc | ||
.perform(get("/schedule/X123456/previous").withToken()) | ||
.andExpect(status().isNotFound) | ||
} | ||
|
||
@Test | ||
fun `Upcomimg schedule not found status returned`() { | ||
mockMvc | ||
.perform(get("/schedule/X123456/upcoming").withToken()) | ||
.andExpect(status().isNotFound) | ||
} | ||
|
||
@Test | ||
fun `individual appointment is returned`() { | ||
|
||
val person = OVERVIEW | ||
val id = ContactGenerator.NEXT_APPT_CONTACT.id | ||
val res = mockMvc | ||
.perform(get("/schedule/${person.crn}/appointment/${id}").withToken()) | ||
.andExpect(status().isOk) | ||
.andReturn().response.contentAsJson<PersonAppointment>() | ||
val expectedDocs = | ||
listOf(ContactGenerator.CONTACT_DOCUMENT_1.toDocument(), ContactGenerator.CONTACT_DOCUMENT_2.toDocument()) | ||
val expectedAppointment = ContactGenerator.NEXT_APPT_CONTACT.toAppointment().copy(documents = expectedDocs) | ||
assertThat(res.personSummary.crn, equalTo(person.crn)) | ||
assertThat(res.appointment.id, equalTo(expectedAppointment.id)) | ||
assertThat(res.appointment.type, equalTo(expectedAppointment.type)) | ||
assertThat(res.appointment.location?.officeName, equalTo(expectedAppointment.location?.officeName)) | ||
assertThat(res.appointment.documents.size, equalTo(expectedAppointment.documents.size)) | ||
assertThat(res.appointment.location?.postcode, equalTo("H34 7TH")) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/ScheduleController.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,30 @@ | ||
package uk.gov.justice.digital.hmpps.api.controller | ||
|
||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.security.access.prepost.PreAuthorize | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import uk.gov.justice.digital.hmpps.service.ScheduleService | ||
|
||
@RestController | ||
@Tag(name = "Sentence") | ||
@RequestMapping("/schedule/{crn}") | ||
@PreAuthorize("hasRole('PROBATION_API__MANAGE_A_SUPERVISION__CASE_DETAIL')") | ||
class ScheduleController(private val scheduleService: ScheduleService) { | ||
|
||
@GetMapping("/upcoming") | ||
@Operation(summary = "Gets upcoming schedule information’ ") | ||
fun getUpcomingSchedule(@PathVariable crn: String) = scheduleService.getPersonUpcomingSchedule(crn) | ||
|
||
@GetMapping("/previous") | ||
@Operation(summary = "Gets previous schedule information’ ") | ||
fun getPreviousSchedule(@PathVariable crn: String) = scheduleService.getPersonPreviousSchedule(crn) | ||
|
||
@GetMapping("/appointment/{contactId}") | ||
@Operation(summary = "Gets individual appointment information’ ") | ||
fun getContact(@PathVariable crn: String, @PathVariable contactId: Long) = | ||
scheduleService.getPersonAppointment(crn, contactId) | ||
} |
2 changes: 2 additions & 0 deletions
2
...on-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/overview/Overview.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
Oops, something went wrong.