Skip to content

Commit

Permalink
[AECP & Mission] Retirer des act-rep les contrôles faits par les unit…
Browse files Browse the repository at this point in the history
…és AECP & Correction de la MAJ de la zone de mission (#3200)

## Linked issues

- Resolve #3149
- Resolve #3194

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
louptheron authored May 21, 2024
2 parents 48e4187 + 83d2604 commit 15d467b
Show file tree
Hide file tree
Showing 16 changed files with 504 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class GetActivityReports(

else -> throw IllegalArgumentException("Bad control type: ${control.actionType}")
}
}.filter { control ->
// All AECP reports are excluded from the response
// see: https://github.com/MTES-MCT/monitorfish/issues/3194
return@filter !control.controlUnits.any { controlUnit -> controlUnit.administration == "AECP" }
}
logger.info("Found ${filteredControls.size} controls to report.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.neovisionaries.i18n.CountryCode
import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.eq
import com.nhaarman.mockitokotlin2.given
import fr.gouv.cnsp.monitorfish.domain.entities.mission.ControlUnit
import fr.gouv.cnsp.monitorfish.domain.entities.mission.Mission
import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionSource
import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionType
Expand Down Expand Up @@ -382,4 +383,74 @@ class GetActivityReportsUTests {
// Then
assertThat(activityReports.activityReports).hasSize(0)
}

@Test
fun `execute Should filter a control done by an AECP unit`() {
// Given
val controls = listOf(
MissionAction(
id = 1,
vesselId = 1,
missionId = 1,
actionDatetimeUtc = ZonedDateTime.now(),
portLocode = "AEFAT",
faoAreas = listOf("27.4.b", "27.4.c"),
actionType = MissionActionType.LAND_CONTROL,
gearOnboard = listOf(),
controlUnits = listOf(ControlUnit(123, "AECP", false, "Unit AECP", listOf())),
speciesOnboard = listOf(),
seizureAndDiversion = true,
isDeleted = false,
hasSomeGearsSeized = false,
hasSomeSpeciesSeized = false,
isFromPoseidon = false,
completion = Completion.TO_COMPLETE,
),
)
given(missionActionsRepository.findControlsInDates(any(), any())).willReturn(controls)

val vessels = listOf(
Vessel(
id = 1,
internalReferenceNumber = "FR00022680",
vesselName = "MY AWESOME VESSEL",
flagState = CountryCode.FR,
declaredFishingGears = listOf("Trémails"),
vesselType = "Fishing",
districtCode = "AY",
),
)
given(vesselRepository.findVesselsByIds(eq(listOf(1)))).willReturn(vessels)

val missions = listOf(
Mission(
1,
missionTypes = listOf(MissionType.LAND),
missionSource = MissionSource.MONITORFISH,
isUnderJdp = false,
isGeometryComputedFromControls = false,
startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC),
),

)
// The mission id 2 is not returned
given(missionRepository.findByIds(listOf(1))).willReturn(missions)
given(portRepository.findByLocode(eq("AEFAT"))).willReturn(Port("AEFAT", "Al Jazeera Port"))

// When
val activityReports = GetActivityReports(
missionActionsRepository,
portRepository,
vesselRepository,
missionRepository,
).execute(
ZonedDateTime.now(),
ZonedDateTime.now().minusDays(1),
JointDeploymentPlan.NORTH_SEA,
)

// Then
assertThat(activityReports.jdpSpecies).hasSize(38)
assertThat(activityReports.activityReports).hasSize(0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function EnvActionCard({ missionAction }: EnvActionCardProps) {
]

case EnvMissionAction.MissionActionType.NOTE:
return [<NoteContent>{missionAction.observations}</NoteContent>, Icon.Note]
return [<NoteContent title={missionAction.observations}>{missionAction.observations}</NoteContent>, Icon.Note]

case EnvMissionAction.MissionActionType.SURVEILLANCE:
return [
Expand Down
213 changes: 0 additions & 213 deletions frontend/src/features/Mission/components/MissionForm/formikUsecases.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useGetPortsQuery } from '@api/port'
import { updateMissionGeometry } from '@features/Mission/components/MissionForm/useCases/updateMissionGeometry'
import { updateOtherControlsCheckboxes } from '@features/Mission/components/MissionForm/useCases/updateOtherControlsCheckboxes'
import { useGetMissionQuery } from '@features/Mission/monitorfishMissionApi'
import { isAirOrSeaControl, isLandControl } from '@features/Mission/useCases/getLastControlCircleGeometry'
import { useMainAppDispatch } from '@hooks/useMainAppDispatch'
import { useMainAppSelector } from '@hooks/useMainAppSelector'
import { skipToken } from '@reduxjs/toolkit/query'
import { sortBy } from 'lodash'

import { formikUsecase } from '../formikUsecases'

import type { MissionMainFormValues } from '../types'

export function useGetMainFormFormikUsecases() {
Expand All @@ -22,7 +22,7 @@ export function useGetMainFormFormikUsecases() {
* When updating a control unit, we must reset the "Other controls" field checkboxes
*/
updateMissionActionOtherControlsCheckboxes: (mission: MissionMainFormValues, previousIsControlUnitPAM: boolean) =>
formikUsecase.updateOtherControlsCheckboxes(dispatch)(mission, previousIsControlUnitPAM),
updateOtherControlsCheckboxes(dispatch)(mission, previousIsControlUnitPAM),

/**
* When updating the mission location from the mission, we use the `RTK-Query` cache object to access the `missionAction` form.
Expand Down Expand Up @@ -53,10 +53,11 @@ export function useGetMainFormFormikUsecases() {
return false
}

await formikUsecase.updateMissionLocation(
await updateMissionGeometry(
dispatch,
getPortsApiQuery.data,
getMissionApiQuery.data?.envActions ?? []
getMissionApiQuery.data?.envActions ?? [],
getMissionApiQuery.data?.actions ?? []
)(isGeometryComputedFromControls, lastControl)

return true
Expand Down
Loading

0 comments on commit 15d467b

Please sign in to comment.