Skip to content

Commit

Permalink
[Test] add backend unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Oct 20, 2023
1 parent 414fc52 commit 475015b
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ data class EnvActionModel(
if (other == null || Hibernate.getClass(this) != Hibernate.getClass(other)) return false
other as EnvActionModel

return id != null && id == other.id
return id == other.id
}

override fun hashCode(): Int = javaClass.hashCode()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import fr.gouv.cacem.monitorenv.domain.entities.VehicleTypeEnum
import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.ActionTypeEnum
import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.EnvActionNoteEntity
import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.EnvActionSurveillanceEntity
import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.envActionControl.ActionTargetTypeEnum
import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.envActionControl.EnvActionControlEntity
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.inputs.missions.MissionEnvActionDataInput
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.test.context.junit.jupiter.SpringExtension
import java.time.ZonedDateTime
import java.util.UUID

@ExtendWith(SpringExtension::class)
class MissionEnvActionDataInputUTest {

@MockBean private lateinit var missionEnvActionDataInput: MissionEnvActionDataInput

@Test
fun toEnvActionEntityControlType() {
val input =
MissionEnvActionDataInput(
id = UUID.randomUUID(),
actionType = ActionTypeEnum.CONTROL,
actionStartDateTimeUtc = ZonedDateTime.now(),
actionEndDateTimeUtc = ZonedDateTime.now().plusHours(1),
department = "TestDepartment",
facade = "TestFacade",
themes = listOf(),
actionNumberOfControls = 3,
actionTargetType = ActionTargetTypeEnum.VEHICLE,
vehicleType = VehicleTypeEnum.VESSEL,
infractions = listOf(),
observations = "Observations",
reportingIds = listOf(1, 2, 3),
)

val entity = input.toEnvActionEntity()

// Perform assertions to verify the correctness of the conversion
assertTrue(entity is EnvActionControlEntity)
}

@Test
fun toEnvActionEntitySurveillanceType() {
val input =
MissionEnvActionDataInput(
id = UUID.randomUUID(),
actionType = ActionTypeEnum.SURVEILLANCE,
actionStartDateTimeUtc = ZonedDateTime.now(),
actionEndDateTimeUtc = ZonedDateTime.now().plusHours(1),
department = "TestDepartment",
facade = "TestFacade",
themes = listOf(),
coverMissionZone = true,
observations = "Observations",
reportingIds = listOf(),
)

val entity = input.toEnvActionEntity()

// Perform assertions to verify the correctness of the conversion
assertTrue(entity is EnvActionSurveillanceEntity)
}

@Test
fun toEnvActionEntityNoteType() {
val input =
MissionEnvActionDataInput(
id = UUID.randomUUID(),
actionType = ActionTypeEnum.NOTE,
actionStartDateTimeUtc = ZonedDateTime.now(),
observations = "Observations",
reportingIds = listOf(),
)

val entity = input.toEnvActionEntity()

// Perform assertions to verify the correctness of the conversion
assertTrue(entity is EnvActionNoteEntity)
}
}

0 comments on commit 475015b

Please sign in to comment.