Skip to content

Commit

Permalink
[Préavis] Ajout d'un filtre "statut de diffusion" sur la liste (#3414)
Browse files Browse the repository at this point in the history
## Linked issues

- #3410
- #3407

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
ivangabriele authored Jul 23, 2024
2 parents c40a79f + 820414a commit a56384e
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class CreateOrUpdateManualPriorNotification(
val message = getMessage(
hasPortEntranceAuthorization = hasPortEntranceAuthorization,
hasPortLandingAuthorization = hasPortLandingAuthorization,
existingPnoValue = existingPnoMessage,
expectedArrivalDate = expectedArrivalDate,
expectedLandingDate = expectedLandingDate,
// At the moment, manual prior notifications only have a single global FAO area field in Frontend,
Expand Down Expand Up @@ -148,7 +147,6 @@ class CreateOrUpdateManualPriorNotification(
}

private fun getMessage(
existingPnoValue: PNO?,
hasPortEntranceAuthorization: Boolean,
hasPortLandingAuthorization: Boolean,
purpose: LogbookMessagePurpose,
Expand All @@ -163,9 +161,11 @@ class CreateOrUpdateManualPriorNotification(
): PNO {
val allPorts = portRepository.findAll()

val isInVerificationScope = existingPnoValue?.isInVerificationScope
?: ManualPriorNotificationComputedValues
.computeIsInVerificationScope(computedVesselFlagCountryCode, computedVesselRiskFactor)
val isInVerificationScope = ManualPriorNotificationComputedValues
.computeIsInVerificationScope(computedVesselFlagCountryCode, computedVesselRiskFactor)
// If the prior notification is not in verification scope,
// we pass `isBeingSent` as `true` in order to ask the workflow to send it.
val isBeingSent = !isInVerificationScope
val portName = allPorts.find { it.locode == portLocode }?.name

return PNO().apply {
Expand All @@ -179,7 +179,9 @@ class CreateOrUpdateManualPriorNotification(
// so we transform that single FAO area into an FAO area per fishing catch.
// This means we don't need to set a global PNO message FAO area here.
this.faoZone = null
this.isBeingSent = false
// If the prior notification is not in verification scope,
// we pass `isBeingSent` as `true` in order to ask the workflow to send it.
this.isBeingSent = isBeingSent
this.isInVerificationScope = isInVerificationScope
this.isSent = false
this.isVerified = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification
import fr.gouv.cnsp.monitorfish.config.UseCase
import fr.gouv.cnsp.monitorfish.domain.entities.facade.SeafrontGroup
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotification
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotificationState
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotificationStats
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.filters.PriorNotificationsFilter
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.sorters.PriorNotificationsSortColumn
Expand All @@ -24,6 +25,7 @@ class GetPriorNotifications(
fun execute(
filter: PriorNotificationsFilter,
seafrontGroup: SeafrontGroup,
states: List<PriorNotificationState>?,
sortColumn: PriorNotificationsSortColumn,
sortDirection: Sort.Direction,
pageNumber: Int,
Expand Down Expand Up @@ -64,7 +66,7 @@ class GetPriorNotifications(
compareByDescending<PriorNotification> { getSortKey(it, sortColumn) }
.thenByDescending { it.logbookMessageTyped.logbookMessage.id }, // Tie-breaker
)
}.filter { seafrontGroup.hasSeafront(it.seafront) }
}.filter { seafrontGroup.hasSeafront(it.seafront) && (states.isNullOrEmpty() || states.contains(it.state)) }

val extraData = PriorNotificationStats(
perSeafrontGroupCount = SeafrontGroup.entries.associateWith { seafrontGroupEntry ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.gouv.cnsp.monitorfish.infrastructure.api.bff

import fr.gouv.cnsp.monitorfish.domain.entities.facade.SeafrontGroup
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotificationState
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.filters.PriorNotificationsFilter
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.sorters.PriorNotificationsSortColumn
import fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification.*
Expand Down Expand Up @@ -74,6 +75,9 @@ class PriorNotificationController(
@Parameter(description = "Seafront group.")
@RequestParam(name = "seafrontGroup")
seafrontGroup: SeafrontGroup,
@Parameter(description = "States.")
@RequestParam(name = "states")
states: List<PriorNotificationState>? = null,

@Parameter(description = "Sort column.")
@RequestParam(name = "sortColumn")
Expand Down Expand Up @@ -105,7 +109,7 @@ class PriorNotificationController(
)

val paginatedPriorNotifications = getPriorNotifications
.execute(priorNotificationsFilter, seafrontGroup, sortColumn, sortDirection, pageNumber, pageSize)
.execute(priorNotificationsFilter, seafrontGroup, states, sortColumn, sortDirection, pageNumber, pageSize)
val priorNotificationListItemDataOutputs = paginatedPriorNotifications.data
.mapNotNull { PriorNotificationListItemDataOutput.fromPriorNotification(it) }
val extraDataOutput = PriorNotificationsExtraDataOutput
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification

import fr.gouv.cnsp.monitorfish.config.MapperConfiguration
import fr.gouv.cnsp.monitorfish.domain.entities.facade.Seafront
import fr.gouv.cnsp.monitorfish.domain.entities.facade.SeafrontGroup
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotificationState
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.filters.PriorNotificationsFilter
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.sorters.PriorNotificationsSortColumn
import fr.gouv.cnsp.monitorfish.domain.repositories.*
Expand Down Expand Up @@ -50,6 +52,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
willArriveBefore = "2099-12-31T00:00:00Z",
)
private val defaultSeafrontGroup = SeafrontGroup.ALL
private val defaultStates = null
private val defaultSortColumn = PriorNotificationsSortColumn.EXPECTED_ARRIVAL_DATE
private val defaultSortDirection = Sort.Direction.ASC
private val defaultPageSize = 100
Expand All @@ -64,7 +67,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {

// When
val result = getPriorNotifications
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
.execute(
defaultFilter,
defaultSeafrontGroup,
defaultStates,
sortColumn,
sortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
val firstPriorNotificationWithNonNullArrivalDate = result.data
Expand All @@ -85,7 +96,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {

// When
val result = getPriorNotifications
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
.execute(
defaultFilter,
defaultSeafrontGroup,
defaultStates,
sortColumn,
sortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
val firstPriorNotificationWithNonNullArrivalDate = result.data
Expand All @@ -106,7 +125,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {

// When
val result = getPriorNotifications
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
.execute(
defaultFilter,
defaultSeafrontGroup,
defaultStates,
sortColumn,
sortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
val firstPriorNotificationWithNonNullLandingDate = result.data
Expand All @@ -127,7 +154,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {

// When
val result = getPriorNotifications
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
.execute(
defaultFilter,
defaultSeafrontGroup,
defaultStates,
sortColumn,
sortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
val firstPriorNotificationWithNonNullLandingDate = result.data
Expand All @@ -148,7 +183,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {

// When
val result = getPriorNotifications
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
.execute(
defaultFilter,
defaultSeafrontGroup,
defaultStates,
sortColumn,
sortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
val firstPriorNotificationWithNonNullPort = result.data.first { it.port != null }
Expand All @@ -166,7 +209,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {

// When
val result = getPriorNotifications
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
.execute(
defaultFilter,
defaultSeafrontGroup,
defaultStates,
sortColumn,
sortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
val firstPriorNotificationWithNonNullPort = result.data.first { it.port != null }
Expand All @@ -184,7 +235,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {

// When
val result = getPriorNotifications
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
.execute(
defaultFilter,
defaultSeafrontGroup,
defaultStates,
sortColumn,
sortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
val firstPriorNotificationWithKnownVessel = result.data.first { it.vessel!!.id != -1 }
Expand All @@ -207,7 +266,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {

// When
val result = getPriorNotifications
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
.execute(
defaultFilter,
defaultSeafrontGroup,
defaultStates,
sortColumn,
sortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
val firstPriorNotificationWithKnownVessel = result.data.first { it.vessel!!.id != -1 }
Expand All @@ -230,10 +297,19 @@ class GetPriorNotificationsITests : AbstractDBTests() {

// When
val result = getPriorNotifications
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
.execute(
defaultFilter,
defaultSeafrontGroup,
defaultStates,
sortColumn,
sortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
val firstPriorNotificationWithNonNullRiskFactor = result.data.first { it.logbookMessageTyped.typedMessage.riskFactor != null }
val firstPriorNotificationWithNonNullRiskFactor =
result.data.first { it.logbookMessageTyped.typedMessage.riskFactor != null }
assertThat(firstPriorNotificationWithNonNullRiskFactor.logbookMessageTyped.typedMessage.riskFactor!!).isEqualTo(
1.5,
)
Expand All @@ -249,13 +325,75 @@ class GetPriorNotificationsITests : AbstractDBTests() {

// When
val result = getPriorNotifications
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
.execute(
defaultFilter,
defaultSeafrontGroup,
defaultStates,
sortColumn,
sortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
val firstPriorNotificationWithNonNullRiskFactor = result.data.first { it.logbookMessageTyped.typedMessage.riskFactor != null }
val firstPriorNotificationWithNonNullRiskFactor =
result.data.first { it.logbookMessageTyped.typedMessage.riskFactor != null }
assertThat(firstPriorNotificationWithNonNullRiskFactor.logbookMessageTyped.typedMessage.riskFactor!!).isEqualTo(
3.9,
)
assertThat(result.data).hasSizeGreaterThan(0)
}

@Test
@Transactional
fun `execute should return a list of NAMO seafront group prior notifications`() {
// Given
val seafrontGroup = SeafrontGroup.NAMO

// When
val result = getPriorNotifications
.execute(
defaultFilter,
seafrontGroup,
defaultStates,
defaultSortColumn,
defaultSortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
assertThat(result.data).hasSizeGreaterThan(0)
assertThat(result.data.all { it.seafront === Seafront.NAMO }).isTrue()
}

@Test
@Transactional
fun `execute should return a list of pending sent and out of verification scope prior notifications`() {
// Given
val states = listOf(PriorNotificationState.PENDING_SEND, PriorNotificationState.OUT_OF_VERIFICATION_SCOPE)

// When
val result = getPriorNotifications
.execute(
defaultFilter,
defaultSeafrontGroup,
states,
defaultSortColumn,
defaultSortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
assertThat(result.data).hasSizeGreaterThan(0)
assertThat(
result.data.all {
listOf(
PriorNotificationState.PENDING_SEND,
PriorNotificationState.OUT_OF_VERIFICATION_SCOPE,
).contains(it.state)
},
).isTrue()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class GetPriorNotificationsUTests {
willArriveBefore = "2099-12-31T00:00:00Z",
)
private val defaultSeafrontGroup = SeafrontGroup.ALL
private val defaultStates = null
private val defaultSortColumn = PriorNotificationsSortColumn.EXPECTED_ARRIVAL_DATE
private val defaultSortDirection = Sort.Direction.ASC
private val defaultPageSize = 10
Expand Down Expand Up @@ -145,6 +146,7 @@ class GetPriorNotificationsUTests {
).execute(
defaultFilter,
defaultSeafrontGroup,
defaultStates,
defaultSortColumn,
defaultSortDirection,
defaultPageNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class PriorNotificationControllerITests {
val secondFakePriorNotification = PriorNotificationFaker.fakePriorNotification(2)

// Given
given(getPriorNotifications.execute(any(), any(), any(), any(), any(), any())).willReturn(
given(getPriorNotifications.execute(any(), any(), anyOrNull(), any(), any(), any(), any())).willReturn(
PaginatedList(
data = listOf(firstFakePriorNotification, secondFakePriorNotification),
extraData = PriorNotificationStats(perSeafrontGroupCount = emptyMap()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,9 @@ context('Side Window > Prior Notification Form > Form', () => {
}

assert.deepInclude(getInterception.response.body, {
state: PriorNotification.State.OUT_OF_VERIFICATION_SCOPE
// `PENDING_SEND` since this prior notification is out of verification scope
// so the backend will ask the workflow to send it right away.
state: PriorNotification.State.PENDING_SEND
})

cy.get('.Element-Tag').contains('Hors diffusion').should('exist')
Expand Down
1 change: 1 addition & 0 deletions frontend/src/features/Logbook/LogbookMessage.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export namespace LogbookMessage {
seafrontGroup: SeafrontGroup | AllSeafrontGroup | NoSeafrontGroup | undefined
searchQuery: string | undefined
specyCodes: string[] | undefined
states: PriorNotification.State[] | undefined
tripGearCodes: string[] | undefined
tripSegmentCodes: string[] | undefined
vesselLength: number | undefined
Expand Down
Loading

0 comments on commit a56384e

Please sign in to comment.