-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(PublicMissionApi): add filter by controlUnits (#1044)
## Description Ajout d'un filtre par controlUnits sur l'endpoint Missions de l'API publique. J'ai choisi de faire le filtre au niveau du UseCase plutot que dans la query car elle est native, que je ne maitrise pas du tout ce format et que le temps presse avant que les premiers tests de RapportNav ne commencent. Dîtes moi si c'est ok. ---- - [ ] Tests E2E (Cypress)
- Loading branch information
Showing
3 changed files
with
226 additions
and
1 deletion.
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
210 changes: 210 additions & 0 deletions
210
...d/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsUTests.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,210 @@ | ||
package fr.gouv.cacem.monitorenv.domain.use_cases.missions | ||
|
||
import com.nhaarman.mockitokotlin2.given | ||
import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity | ||
import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository | ||
import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitEntity | ||
import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionTypeEnum | ||
import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum | ||
import java.time.ZonedDateTime | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.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 com.nhaarman.mockitokotlin2.any | ||
|
||
@ExtendWith(SpringExtension::class) | ||
class GetMissionsUTests { | ||
@MockBean | ||
private lateinit var missionRepository: IMissionRepository | ||
|
||
private val controlUnit1: LegacyControlUnitEntity = LegacyControlUnitEntity( | ||
id = 1, | ||
administration = "whatever", | ||
isArchived = false, | ||
name = "whatever", | ||
resources = listOf(), | ||
) | ||
|
||
private val controlUnit2: LegacyControlUnitEntity = LegacyControlUnitEntity( | ||
id = 2, | ||
administration = "whatever", | ||
isArchived = false, | ||
name = "whatever", | ||
resources = listOf(), | ||
) | ||
|
||
private val controlUnit3: LegacyControlUnitEntity = LegacyControlUnitEntity( | ||
id = 3, | ||
administration = "whatever", | ||
isArchived = false, | ||
name = "whatever", | ||
resources = listOf(), | ||
) | ||
|
||
private val mission1 = | ||
MissionEntity( | ||
id = 10, | ||
missionTypes = listOf(MissionTypeEnum.SEA), | ||
startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), | ||
isDeleted = false, | ||
missionSource = MissionSourceEnum.MONITORFISH, | ||
isClosed = false, | ||
hasMissionOrder = false, | ||
isUnderJdp = false, | ||
isGeometryComputedFromControls = false, | ||
controlUnits = listOf(controlUnit1, controlUnit2) | ||
) | ||
|
||
private val mission2 = | ||
MissionEntity( | ||
id = 11, | ||
missionTypes = listOf(MissionTypeEnum.SEA), | ||
startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), | ||
isDeleted = false, | ||
missionSource = MissionSourceEnum.MONITORFISH, | ||
isClosed = false, | ||
hasMissionOrder = false, | ||
isUnderJdp = false, | ||
isGeometryComputedFromControls = false, | ||
controlUnits = listOf(controlUnit1, controlUnit3) | ||
) | ||
|
||
@Test | ||
fun `execute should return all missions when filter for controlUnits is null`() { | ||
given(missionRepository.findAll( | ||
startedAfter = any(), | ||
startedBefore = any(), | ||
missionSources = any(), | ||
missionTypes = any(), | ||
missionStatuses = any(), | ||
seaFronts = any(), | ||
pageable = any(), | ||
)).willReturn(listOf(mission1, mission2)) | ||
|
||
val result = GetMissions(missionRepository).execute( | ||
startedAfterDateTime = any(), | ||
startedBeforeDateTime = any(), | ||
missionSources = any(), | ||
missionTypes = any(), | ||
missionStatuses = any(), | ||
pageNumber = any(), | ||
pageSize = any(), | ||
seaFronts = any(), | ||
controlUnits = null | ||
) | ||
|
||
assertThat(result.size).isEqualTo(2) | ||
} | ||
|
||
@Test | ||
fun `execute should return all missions when filter for controlUnits is an empty list`() { | ||
given(missionRepository.findAll( | ||
startedAfter = any(), | ||
startedBefore = any(), | ||
missionSources = any(), | ||
missionTypes = any(), | ||
missionStatuses = any(), | ||
seaFronts = any(), | ||
pageable = any(), | ||
)).willReturn(listOf(mission1, mission2)) | ||
|
||
val result = GetMissions(missionRepository).execute( | ||
startedAfterDateTime = any(), | ||
startedBeforeDateTime = any(), | ||
missionSources = any(), | ||
missionTypes = any(), | ||
missionStatuses = any(), | ||
pageNumber = any(), | ||
pageSize = any(), | ||
seaFronts = any(), | ||
controlUnits = listOf() | ||
) | ||
|
||
assertThat(result.size).isEqualTo(2) | ||
} | ||
|
||
@Test | ||
fun `execute should only one missions when the controlUnits input matches 1 mission`() { | ||
given(missionRepository.findAll( | ||
startedAfter = any(), | ||
startedBefore = any(), | ||
missionSources = any(), | ||
missionTypes = any(), | ||
missionStatuses = any(), | ||
seaFronts = any(), | ||
pageable = any(), | ||
)).willReturn(listOf(mission1, mission2)) | ||
|
||
val result = GetMissions(missionRepository).execute( | ||
startedAfterDateTime = any(), | ||
startedBeforeDateTime = any(), | ||
missionSources = any(), | ||
missionTypes = any(), | ||
missionStatuses = any(), | ||
pageNumber = any(), | ||
pageSize = any(), | ||
seaFronts = any(), | ||
controlUnits = listOf(controlUnit2.id) | ||
) | ||
|
||
assertThat(result.size).isEqualTo(1) | ||
assertThat(result.first()).isEqualTo(controlUnit2) | ||
} | ||
|
||
@Test | ||
fun `execute should only two missions when the same controlUnits input matches 2 missions`() { | ||
given(missionRepository.findAll( | ||
startedAfter = any(), | ||
startedBefore = any(), | ||
missionSources = any(), | ||
missionTypes = any(), | ||
missionStatuses = any(), | ||
seaFronts = any(), | ||
pageable = any(), | ||
)).willReturn(listOf(mission1, mission2)) | ||
|
||
val result = GetMissions(missionRepository).execute( | ||
startedAfterDateTime = any(), | ||
startedBeforeDateTime = any(), | ||
missionSources = any(), | ||
missionTypes = any(), | ||
missionStatuses = any(), | ||
pageNumber = any(), | ||
pageSize = any(), | ||
seaFronts = any(), | ||
controlUnits = listOf(controlUnit1.id) | ||
) | ||
|
||
assertThat(result.size).isEqualTo(2) | ||
} | ||
|
||
@Test | ||
fun `execute should return filtered missions matching nultiple controlUnits input`() { | ||
given(missionRepository.findAll( | ||
startedAfter = any(), | ||
startedBefore = any(), | ||
missionSources = any(), | ||
missionTypes = any(), | ||
missionStatuses = any(), | ||
seaFronts = any(), | ||
pageable = any(), | ||
)).willReturn(listOf(mission1, mission2)) | ||
|
||
val result = GetMissions(missionRepository).execute( | ||
startedAfterDateTime = any(), | ||
startedBeforeDateTime = any(), | ||
missionSources = any(), | ||
missionTypes = any(), | ||
missionStatuses = any(), | ||
pageNumber = any(), | ||
pageSize = any(), | ||
seaFronts = any(), | ||
controlUnits = listOf(controlUnit2.id, controlUnit3.id) | ||
) | ||
|
||
assertThat(result.size).isEqualTo(2) | ||
} | ||
|
||
} |