Skip to content

Commit

Permalink
tech: add case for envaction dates
Browse files Browse the repository at this point in the history
  • Loading branch information
maximeperrault committed Jan 16, 2025
1 parent c7d02db commit 1273fdc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MissionValidator : Validator<MissionEntity> {
private fun validateControl(
control: EnvActionControlEntity,
mission: MissionEntity,
isMissionEnded: Boolean
isMissionEnded: Boolean,
) {
validateEnvAction(control, mission)

Expand All @@ -95,7 +95,6 @@ class MissionValidator : Validator<MissionEntity> {
)
}


control.infractions?.forEach { infraction ->
if (infraction.infractionType !== InfractionTypeEnum.WAITING && infraction.natinf?.isEmpty() == true) {
throw BackendUsageException(
Expand Down Expand Up @@ -131,8 +130,8 @@ class MissionValidator : Validator<MissionEntity> {
mission: MissionEntity,
) {
val actionType = if (envAction.actionType === ActionTypeEnum.CONTROL) "du contrôle" else "de la surveillance"
if (envAction.actionStartDateTimeUtc?.isAfter(mission.startDateTimeUtc) == false
&& envAction.actionStartDateTimeUtc?.isEqual(mission.startDateTimeUtc) == false
if (envAction.actionStartDateTimeUtc?.isAfter(mission.startDateTimeUtc) == false &&
envAction.actionStartDateTimeUtc?.isEqual(mission.startDateTimeUtc) == false
) {
throw BackendUsageException(
BackendUsageErrorCode.UNVALID_PROPERTY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class EnvActionFixture {
infractions = infractions,
actionNumberOfControls = actionNumberOfControls,
actionTargetType = actionTargetTypeEnum,
vehicleType = vehicleTypeEnum
vehicleType = vehicleTypeEnum,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class MissionValidatorUTest {
assertThat(assertThrows.message).isEqualTo("Le type de mission est requis")
}


@ParameterizedTest
@ValueSource(strings = ["A", "AA", "AAAA"])
fun `validate should throw an exception if openBy is not a trigram`(openBy: String) {
Expand Down Expand Up @@ -120,11 +119,12 @@ class MissionValidatorUTest {
val endDateTimeUtc = ZonedDateTime.parse("2021-03-04T00:00:00.000Z")

val anEnvActionControl = anEnvActionControl(endTime = startDateTimeUtc.minusSeconds(1))
val mission = aMissionEntity(
startDateTimeUtc = startDateTimeUtc,
endDateTimeUtc = endDateTimeUtc,
envAction = listOf(anEnvActionControl)
)
val mission =
aMissionEntity(
startDateTimeUtc = startDateTimeUtc,
endDateTimeUtc = endDateTimeUtc,
envAction = listOf(anEnvActionControl),
)

val assertThrows = assertThrows(BackendUsageException::class.java) { missionValidator.validate(mission) }
assertThat(
Expand All @@ -137,11 +137,12 @@ class MissionValidatorUTest {
val startDateTimeUtc = ZonedDateTime.parse("2020-03-04T00:00:00.000Z")
val endDateTimeUtc = ZonedDateTime.parse("2021-03-04T00:00:00.000Z")
val anEnvActionControl = anEnvActionControl(startTime = startDateTimeUtc, endTime = endDateTimeUtc)
val mission = aMissionEntity(
startDateTimeUtc = startDateTimeUtc,
endDateTimeUtc = endDateTimeUtc,
envAction = listOf(anEnvActionControl)
)
val mission =
aMissionEntity(
startDateTimeUtc = startDateTimeUtc,
endDateTimeUtc = endDateTimeUtc,
envAction = listOf(anEnvActionControl),
)

missionValidator.validate(mission)
}
Expand Down Expand Up @@ -214,8 +215,7 @@ class MissionValidatorUTest {
}

@Test
fun `validate should throw an exception if there is a control actionTargetType as VEHICULE without vehiculeType when mission has ended`(
) {
fun `validate should throw an exception if there is a control actionTargetType as VEHICULE without vehiculeType when mission has ended`() {
val endDateTimeUtc = ZonedDateTime.now().plusSeconds(1)
val anEnvActionControl = anEnvActionControl(actionTargetTypeEnum = ActionTargetTypeEnum.VEHICLE)
val mission = aMissionEntity(endDateTimeUtc = endDateTimeUtc, envAction = listOf(anEnvActionControl))
Expand All @@ -224,7 +224,6 @@ class MissionValidatorUTest {
assertThat(assertThrows.message).isEqualTo("Le type de véhicule est obligatoire")
}


@ParameterizedTest
@EnumSource(value = ActionTargetTypeEnum::class, names = ["VEHICLE"], mode = EnumSource.Mode.EXCLUDE)
fun `validate should pass if there is a control actionTargetType as targetType other than VEHICLE without vehiculeType when mission has ended`(
Expand Down Expand Up @@ -291,11 +290,12 @@ class MissionValidatorUTest {
val endDateTimeUtc = ZonedDateTime.parse("2021-03-04T00:00:00.000Z")

val anEnvActionSurveillance = anEnvActionSurveillance(endTime = startDateTimeUtc.minusSeconds(1))
val mission = aMissionEntity(
startDateTimeUtc = startDateTimeUtc,
endDateTimeUtc = endDateTimeUtc,
envAction = listOf(anEnvActionSurveillance)
)
val mission =
aMissionEntity(
startDateTimeUtc = startDateTimeUtc,
endDateTimeUtc = endDateTimeUtc,
envAction = listOf(anEnvActionSurveillance),
)

val assertThrows = assertThrows(BackendUsageException::class.java) { missionValidator.validate(mission) }
assertThat(
Expand All @@ -308,11 +308,12 @@ class MissionValidatorUTest {
val startDateTimeUtc = ZonedDateTime.parse("2020-03-04T00:00:00.000Z")
val endDateTimeUtc = ZonedDateTime.parse("2020-03-04T00:00:00.000Z")
val anEnvActionSurveillance = anEnvActionSurveillance(startTime = startDateTimeUtc, endTime = endDateTimeUtc)
val mission = aMissionEntity(
startDateTimeUtc = startDateTimeUtc,
endDateTimeUtc = endDateTimeUtc,
envAction = listOf(anEnvActionSurveillance)
)
val mission =
aMissionEntity(
startDateTimeUtc = startDateTimeUtc,
endDateTimeUtc = endDateTimeUtc,
envAction = listOf(anEnvActionSurveillance),
)

missionValidator.validate(mission)
}
Expand Down

0 comments on commit 1273fdc

Please sign in to comment.