Skip to content

Commit

Permalink
Préavis – Consulter la liste des signalements et en créer depuis le f…
Browse files Browse the repository at this point in the history
…ormulaire d'un préavis (#3751)

## Linked issues

- Resolve #2868
- Resolve #3460

----

- [x] Tests E2E (Cypress)
  • Loading branch information
ivangabriele authored Oct 15, 2024
2 parents 6f37690 + d6c9d35 commit 93b9f15
Show file tree
Hide file tree
Showing 126 changed files with 2,466 additions and 1,971 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ class GetVesselReportings(

val (reportings, reportingsTimeTaken) =
measureTimedValue {
findReportings(
vesselId,
if (vesselId != null) {
return@measureTimedValue findReportingsByVesselId(vesselId, fromDate)
}

findReportingsByVesselIdentity(
vesselIdentifier,
internalReferenceNumber,
fromDate,
Expand Down Expand Up @@ -231,18 +234,20 @@ class GetVesselReportings(
return (reportingsWithoutAlerts + alertTypeToLastAlertAndOccurrences)
}

private fun findReportings(
vesselId: Int?,
private fun findReportingsByVesselId(
vesselId: Int,
fromDate: ZonedDateTime,
): List<Reporting> {
return reportingRepository.findCurrentAndArchivedByVesselIdEquals(vesselId, fromDate)
}

private fun findReportingsByVesselIdentity(
vesselIdentifier: VesselIdentifier?,
internalReferenceNumber: String,
fromDate: ZonedDateTime,
ircs: String,
externalReferenceNumber: String,
): List<Reporting> {
if (vesselId != null) {
return reportingRepository.findCurrentAndArchivedByVesselIdEquals(vesselId, fromDate)
}

return when (vesselIdentifier) {
VesselIdentifier.INTERNAL_REFERENCE_NUMBER ->
reportingRepository.findCurrentAndArchivedByVesselIdentifierEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ReportingController(
archiveReporting.execute(reportingId)
}

@PutMapping(value = ["/{reportingId}/update"], consumes = ["application/json"])
@PutMapping(value = ["/{reportingId}"], consumes = ["application/json"])
@Operation(summary = "Update a reporting")
fun updateReporting(
@PathParam("Reporting id")
Expand All @@ -78,7 +78,7 @@ class ReportingController(
archiveReportings.execute(ids)
}

@PutMapping(value = ["/{reportingId}/delete"])
@DeleteMapping(value = ["/{reportingId}"])
@Operation(summary = "Delete a reporting")
fun deleteReporting(
@PathParam("Reporting id")
Expand All @@ -88,7 +88,7 @@ class ReportingController(
deleteReporting.execute(reportingId)
}

@PutMapping(value = ["/delete"])
@DeleteMapping(value = [""])
@Operation(summary = "Delete multiple reportings")
fun deleteReporting(
@RequestBody ids: List<Int>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ class VesselController(
const val zoneDateTimePattern = "yyyy-MM-dd'T'HH:mm:ss.000X"
}

@GetMapping("/reporting")
@GetMapping("/reportings")
@Operation(summary = "Get vessel's reporting")
fun getVesselReporting(
fun getReportingsByVesselIdentity(
@Parameter(description = "Vessel id")
@RequestParam(name = "vesselId")
vesselId: Int?,
Expand All @@ -192,8 +192,8 @@ class VesselController(
@RequestParam(name = "externalReferenceNumber")
externalReferenceNumber: String,
@Parameter(description = "Vessel IRCS")
@RequestParam(name = "IRCS")
IRCS: String,
@RequestParam(name = "ircs")
ircs: String,
@Parameter(description = "Vessel positions identifier")
@RequestParam(name = "vesselIdentifier")
vesselIdentifier: VesselIdentifier?,
Expand All @@ -207,7 +207,7 @@ class VesselController(
vesselId,
internalReferenceNumber,
externalReferenceNumber,
IRCS,
ircs,
vesselIdentifier,
fromDate,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PriorNotificationDataOutput(
val state: PriorNotificationState?,
val riskFactor: Double?,
val vesselId: Int,
val vesselIdentity: VesselIdentityDataOutput,
) {
companion object {
fun fromPriorNotification(priorNotification: PriorNotification): PriorNotificationDataOutput {
Expand Down Expand Up @@ -54,6 +55,7 @@ class PriorNotificationDataOutput(
val isLessThanTwelveMetersVessel = vessel.isLessThanTwelveMetersVessel()
val isVesselUnderCharter = vessel.underCharter
val logbookMessage = priorNotification.logbookMessageAndValue.logbookMessage
val vesselIdentity = VesselIdentityDataOutput.fromVessel(vessel)
val vesselId = vessel.id

val logbookMessageDataOutput = LogbookMessageDataOutput.fromLogbookMessage(logbookMessage)
Expand All @@ -72,6 +74,7 @@ class PriorNotificationDataOutput(
state = priorNotification.state,
riskFactor = priorNotification.logbookMessageAndValue.value.riskFactor,
vesselId = vesselId,
vesselIdentity = vesselIdentity,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs

import com.neovisionaries.i18n.CountryCode
import fr.gouv.cnsp.monitorfish.domain.entities.vessel.Vessel
import fr.gouv.cnsp.monitorfish.domain.entities.vessel.VesselAndBeacon

data class VesselIdentityDataOutput(
Expand All @@ -16,6 +17,20 @@ data class VesselIdentityDataOutput(
val beaconNumber: String? = null,
) {
companion object {
fun fromVessel(vessel: Vessel): VesselIdentityDataOutput {
return VesselIdentityDataOutput(
internalReferenceNumber = vessel.internalReferenceNumber,
districtCode = vessel.districtCode,
vesselId = vessel.id,
imo = vessel.imo,
ircs = vessel.ircs,
mmsi = vessel.mmsi,
externalReferenceNumber = vessel.externalReferenceNumber,
vesselName = vessel.vesselName,
flagState = vessel.flagState,
)
}

fun fromVesselAndBeacon(vesselAndBeacon: VesselAndBeacon): VesselIdentityDataOutput {
return VesselIdentityDataOutput(
internalReferenceNumber = vesselAndBeacon.vessel.internalReferenceNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ReportingControllerITests {
@Test
fun `Should delete a reporting`() {
// When
api.perform(put("/bff/v1/reportings/123/delete"))
api.perform(delete("/bff/v1/reportings/123"))
// Then
.andExpect(status().isOk)

Expand All @@ -100,7 +100,7 @@ class ReportingControllerITests {
fun `Should delete multiple reportings`() {
// When
api.perform(
put("/bff/v1/reportings/delete")
delete("/bff/v1/reportings")
.content(objectMapper.writeValueAsString(listOf(1, 2, 3)))
.contentType(MediaType.APPLICATION_JSON),
)
Expand Down Expand Up @@ -299,7 +299,7 @@ class ReportingControllerITests {

// When
api.perform(
put("/bff/v1/reportings/123/update")
put("/bff/v1/reportings/123")
.content(
objectMapper.writeValueAsString(
UpdateReportingDataInput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,11 @@ class VesselControllerITests {
stage = Stage.ARCHIVED,
malfunctionStartDateTime = ZonedDateTime.now(),
malfunctionEndDateTime = null,
vesselStatusLastModificationDateTime = ZonedDateTime.now(), endOfBeaconMalfunctionReason = EndOfBeaconMalfunctionReason.RESUMED_TRANSMISSION,
beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123,
vesselStatusLastModificationDateTime = ZonedDateTime.now(),
endOfBeaconMalfunctionReason = EndOfBeaconMalfunctionReason.RESUMED_TRANSMISSION,
beaconNumber = "123465",
beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED,
vesselId = 123,
),
comments =
listOf(
Expand Down Expand Up @@ -624,7 +627,9 @@ class VesselControllerITests {
malfunctionStartDateTime = ZonedDateTime.now(),
malfunctionEndDateTime = null,
vesselStatusLastModificationDateTime = ZonedDateTime.now(),
beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123,
beaconNumber = "123465",
beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED,
vesselId = 123,
),
comments =
listOf(
Expand Down Expand Up @@ -680,7 +685,7 @@ class VesselControllerITests {
}

@Test
fun `Should get vessel's reporting`() {
fun `Should get vessel's reportings by vessel identity with vessel ID`() {
// Given
val currentReporting =
Reporting(
Expand Down Expand Up @@ -782,8 +787,8 @@ class VesselControllerITests {
// When
api.perform(
get(
"/bff/v1/vessels/reporting?vesselId=123456&internalReferenceNumber=FR224226850" +
"&externalReferenceNumber=123&IRCS=IEF4&vesselIdentifier=INTERNAL_REFERENCE_NUMBER&fromDate=2021-03-24T22:07:00.000Z",
"/bff/v1/vessels/reportings?vesselId=123456&internalReferenceNumber=FR224226850" +
"&externalReferenceNumber=123&ircs=IEF4&vesselIdentifier=INTERNAL_REFERENCE_NUMBER&fromDate=2021-03-24T22:07:00.000Z",
),
)
// Then
Expand Down Expand Up @@ -811,7 +816,7 @@ class VesselControllerITests {
}

@Test
fun `Should get vessel's reporting with an empty vessel id`() {
fun `Should get vessel's reporting by vessel identity without vessel ID`() {
given(
this.getVesselReportings.execute(
eq(null),
Expand All @@ -838,8 +843,8 @@ class VesselControllerITests {
// When
api.perform(
get(
"/bff/v1/vessels/reporting?vesselId=&internalReferenceNumber=FR224226850" +
"&externalReferenceNumber=123&IRCS=IEF4&vesselIdentifier=INTERNAL_REFERENCE_NUMBER&fromDate=2021-03-24T22:07:00.000Z",
"/bff/v1/vessels/reportings?vesselId=&internalReferenceNumber=FR224226850" +
"&externalReferenceNumber=123&ircs=IEF4&vesselIdentifier=INTERNAL_REFERENCE_NUMBER&fromDate=2021-03-24T22:07:00.000Z",
),
)
// Then
Expand Down
2 changes: 1 addition & 1 deletion frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ module.exports = {
overrides: [
// Redux
{
files: ['src/domain/shared_slices/**/*.ts', 'src/**/slice.ts'],
files: ['src/domain/shared_slices/**/*.ts', 'src/**/slice.ts', 'src/**/*.slice.ts'],
rules: {
'no-param-reassign': 'off'
}
Expand Down
7 changes: 5 additions & 2 deletions frontend/config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ export default {
collectCoverageFrom: ['**/{hooks,libs,utils}/**/*.t{s,sx}', '**/utils.ts'],
globalSetup: '<rootDir>/config/jest.global.js',
maxWorkers: '50%',
moduleNameMapper: {
'\\.svg\\?react$': '<rootDir>/config/jest.svgImportTransformer.js'
},
rootDir: '..',
setupFiles: ['dotenv/config'],
setupFiles: ['dotenv/config', '<rootDir>/config/jest.setup.js'],
testEnvironment: 'jsdom',
testMatch: ['<rootDir>/**/*.test.t{s,sx}'],
transform: {
Expand Down Expand Up @@ -41,7 +44,7 @@ export default {
}
],
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/config/fileTransformer.js'
'<rootDir>/config/jest.fileTransformer.js'
},
transformIgnorePatterns: ['node_modules/(?!ol)/']
}
File renamed without changes.
2 changes: 2 additions & 0 deletions frontend/config/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// To fix `Warning: `fetch` is not available. Please supply a custom `fetchFn` property to use `fetchBaseQuery` on SSR environments.`.
import 'whatwg-fetch'
11 changes: 11 additions & 0 deletions frontend/config/jest.svgImportTransformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createElement } from 'react'

function SvgComponent(props) {
return createElement('svg', {
...props,
'data-testid': 'svg-mock'
})
}

module.exports = SvgComponent
module.exports.ReactComponent = SvgComponent
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ context('Offline management', () => {
cy.get('*[data-cy="vessel-sidebar-error"]').contains("Nous n'avons pas pu récupérer les messages JPE de ce navire")

// When clicking on Reporting tab
cy.intercept(
'GET',
'/bff/v1/vessels/reporting?vesselId=1&internalReferenceNumber=FAK000999999&externalReferenceNumber=DONTSINK&IRCS=CALLME&vesselIdentifier=INTERNAL_REFERENCE_NUMBER*',
{ statusCode: 400 }
).as('getReportings')
cy.intercept('GET', '/bff/v1/vessels/reportings?*', { statusCode: 400 }).as('getReportings')
cy.get('*[data-cy="vessel-menu-reporting"').click()
cy.wait('@getReportings')
cy.get('*[data-cy="vessel-sidebar-error"]').contains("Nous n'avons pas pu récupérer les signalements de ce navire")
Expand Down Expand Up @@ -139,17 +135,15 @@ context('Offline management', () => {
cy.intercept(
{
method: 'GET',
pathname: '/bff/v1/vessels/reporting',
times: 1
pathname: '/bff/v1/vessels/reportings',
times: 3
},
{ statusCode: 400 }
).as('getReportingsStubbed')
cy.get('*[data-cy="vessel-menu-reporting"').click()
cy.wait('@getReportingsStubbed')
cy.get('*[data-cy="vessel-sidebar-error"]').contains("Nous n'avons pas pu récupérer les signalements de ce navire")
cy.intercept(
'/bff/v1/vessels/reporting?vesselId=1&internalReferenceNumber=FAK000999999&externalReferenceNumber=DONTSINK&IRCS=CALLME&vesselIdentifier=INTERNAL_REFERENCE_NUMBER*'
).as('getReportings')
cy.intercept('/bff/v1/vessels/reportings?*').as('getReportings')
cy.clickButton('Réessayer')
cy.wait('@getReportings')
cy.get('*[data-cy="vessel-sidebar-error"]').should('not.exist')
Expand Down
Loading

0 comments on commit 93b9f15

Please sign in to comment.