Invalid scenario scores are now explicitly blocked
This commit is contained in:
parent
c4a7f4cc58
commit
e1df1142ce
@ -132,6 +132,12 @@ class ObservationsController {
|
||||
logger.info("Attempted to add Observation without a tutor")
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Observation requires at least one Tutor")
|
||||
}
|
||||
for(scenario in newObservation.scenarios){
|
||||
if(!scenario.ratingsAllValid()){
|
||||
logger.info("Attempted to submit scenario with invalid score, $scenario")
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Scenario scores must be between 1 and 5")
|
||||
}
|
||||
}
|
||||
var observation = Observation(
|
||||
site = site.get(),
|
||||
date = LocalDate.now(),
|
||||
|
@ -125,6 +125,16 @@ class ObservationsControllerTest {
|
||||
assertEquals(1L, result)
|
||||
}
|
||||
|
||||
@Test(expected = ResponseStatusException::class)
|
||||
fun testAddObservationInvalidScenario() {
|
||||
val site = Site(1, "X")
|
||||
val tutor = Tutor(1, "Foo Bar", site)
|
||||
doReturn(Optional.of(site)).`when`(siteRepository).findById(1)
|
||||
doReturn(listOf(tutor)).`when`(tutorRepository).findAllById(listOf(1))
|
||||
val newData = NewObservation(1, TrainingType.INITIAL, "An Observation", listOf(Scenario(1, "Something", 5, "", "", 100, "", "", 0, "", "", -1, "", "", Byte.MAX_VALUE, "", "", Byte.MIN_VALUE, "", "", 1, "", "", 5, "", "")), listOf(1), "Mr X")
|
||||
controller.addObservation(newData)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetObservations_SiteAndTutorNull() {
|
||||
val request = ObservationsRequest(null, null, "", "", LocalDate.now(), LocalDate.now())
|
||||
|
Loading…
Reference in New Issue
Block a user