Skip to content

Commit

Permalink
Add non-reg unit test for null weight in logbook pno case
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Oct 30, 2024
1 parent d2ab463 commit 0efc167
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,7 @@
// - Vessel: BON VENT
// - Flag state: FR
// - French vessel landing in a foreign port
// - `null` weight in fishing catches
{
"id": 120,
"report_id": "FAKE_OPERATION_120",
Expand Down Expand Up @@ -1627,7 +1628,6 @@

// - Vessel: L'HIPPO CAMPE
// - Flag state: FR
// - `null` weight in fishing catches
// - DAT with a predicted arrival date 30h after the COR predicted arrival
{
"id": 122,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package fr.gouv.cnsp.monitorfish.fakers

import fr.gouv.cnsp.monitorfish.domain.entities.logbook.*
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.messages.Acknowledgment
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.messages.PNO
import java.time.ZonedDateTime

class LogbookMessageFaker {
companion object {
fun fakePnoLogbookMessage(index: Int = 1): LogbookMessage {
fun fakePnoLogbookMessage(index: Int): LogbookMessage {
return LogbookMessage(
id = index.toLong(),
reportId = "FAKE_REPORT_ID_$index",
referencedReportId = null,
isDeleted = false,
integrationDateTime = ZonedDateTime.now(),
isCorrectedByNewerMessage = false,
isDeleted = false,
isEnriched = true,
message = fakePnoMessage(),
messageType = "PNO",
Expand All @@ -25,21 +26,97 @@ class LogbookMessageFaker {
)
}

private fun fakeLogbookFishingCatch(specyCode: String = "HKE"): LogbookFishingCatch {
fun fakePnoLogbookMessage(
id: Long? = null,
reportId: String? = null,
referencedReportId: String? = null,
acknowledgment: Acknowledgment? = null,
externalReferenceNumber: String? = null,
flagState: String? = null,
imo: String? = null,
integrationDateTime: ZonedDateTime = ZonedDateTime.now(),
internalReferenceNumber: String? = null,
ircs: String? = null,
isCorrectedByNewerMessage: Boolean = false,
isDeleted: Boolean = false,
isEnriched: Boolean = false,
isSentByFailoverSoftware: Boolean = false,
message: PNO = fakePnoMessage(),
messageType: String? = null,
operationDateTime: ZonedDateTime = ZonedDateTime.now(),
operationNumber: String? = null,
operationType: LogbookOperationType = LogbookOperationType.DAT,
rawMessage: String? = null,
reportDateTime: ZonedDateTime? = null,
software: String? = null,
transmissionFormat: LogbookTransmissionFormat? = null,
tripGears: List<LogbookTripGear>? = emptyList(),
tripNumber: String? = null,
tripSegments: List<LogbookTripSegment>? = emptyList(),
vesselId: Int? = null,
vesselName: String? = null,
): LogbookMessage {
return LogbookMessage(
id = id,
reportId = reportId,
referencedReportId = referencedReportId,
acknowledgment = acknowledgment,
externalReferenceNumber = externalReferenceNumber,
flagState = flagState,
imo = imo,
integrationDateTime = integrationDateTime,
internalReferenceNumber = internalReferenceNumber,
ircs = ircs,
isCorrectedByNewerMessage = isCorrectedByNewerMessage,
isDeleted = isDeleted,
isEnriched = isEnriched,
isSentByFailoverSoftware = isSentByFailoverSoftware,
message = message,
messageType = messageType,
operationDateTime = operationDateTime,
operationNumber = operationNumber,
operationType = operationType,
rawMessage = rawMessage,
reportDateTime = reportDateTime,
software = software,
transmissionFormat = transmissionFormat,
tripGears = tripGears,
tripNumber = tripNumber,
tripSegments = tripSegments,
vesselId = vesselId,
vesselName = vesselName,
)
}

fun fakeLogbookFishingCatch(
conversionFactor: Double? = null,
economicZone: String? = null,
effortZone: String? = null,
faoZone: String? = "FAO AREA 51",
freshness: String? = null,
nbFish: Double? = null,
packaging: String? = null,
presentation: String? = null,
preservationState: String? = null,
species: String? = "HKE",
speciesName: String? = "Fake Species HKE",
statisticalRectangle: String? = null,
weight: Double? = 42.0,
): LogbookFishingCatch {
return LogbookFishingCatch(
conversionFactor = null,
economicZone = null,
effortZone = null,
faoZone = "FAO AREA 51",
freshness = null,
nbFish = null,
packaging = null,
presentation = null,
preservationState = null,
species = specyCode,
speciesName = "Fake Species $specyCode",
statisticalRectangle = null,
weight = 42.0,
conversionFactor = conversionFactor,
economicZone = economicZone,
effortZone = effortZone,
faoZone = faoZone,
freshness = freshness,
nbFish = nbFish,
packaging = packaging,
presentation = presentation,
preservationState = preservationState,
species = species,
speciesName = speciesName,
statisticalRectangle = statisticalRectangle,
weight = weight,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.anyOrNull
import fr.gouv.cnsp.monitorfish.config.SentryConfig
import fr.gouv.cnsp.monitorfish.domain.entities.facade.SeafrontGroup
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookMessageAndValue
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookMessagePurpose
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.messages.PNO
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.*
import fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification.*
import fr.gouv.cnsp.monitorfish.domain.utils.PaginatedList
import fr.gouv.cnsp.monitorfish.fakers.LogbookMessageFaker
import fr.gouv.cnsp.monitorfish.fakers.PriorNotificationFaker
import fr.gouv.cnsp.monitorfish.infrastructure.api.input.LogbookPriorNotificationFormDataInput
import fr.gouv.cnsp.monitorfish.infrastructure.api.input.ManualPriorNotificationComputeDataInput
Expand Down Expand Up @@ -366,6 +369,59 @@ class PriorNotificationControllerUTests {
.andExpect(jsonPath("$.reportId", equalTo(fakePriorNotification.reportId)))
}

// Non-regression test
@Test
fun `getOne Should get a logbook prior notification including a null weight in its fishing catches`() {
val fakePriorNotification =
PriorNotificationFaker.fakePriorNotification().copy(
logbookMessageAndValue =
LogbookMessageAndValue(
logbookMessage =
LogbookMessageFaker.fakePnoLogbookMessage(
reportId = "FAKE_OPERATION_001",
message =
LogbookMessageFaker.fakePnoMessage().apply {
catchOnboard =
listOf(
LogbookMessageFaker.fakeLogbookFishingCatch(species = "COD", weight = 12.0),
LogbookMessageFaker.fakeLogbookFishingCatch(species = "HKE", weight = null),
)
catchToLand =
listOf(
LogbookMessageFaker.fakeLogbookFishingCatch(species = "COD", weight = 12.0),
LogbookMessageFaker.fakeLogbookFishingCatch(species = "HKE", weight = null),
)
},
),
clazz = PNO::class.java,
),
)

// Given
given(
getPriorNotification.execute(
fakePriorNotification.reportId!!,
fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime,
false,
),
)
.willReturn(fakePriorNotification)

// When
api.perform(
get(
"/bff/v1/prior_notifications/${fakePriorNotification.reportId!!}?operationDate=${fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime}&isManuallyCreated=false",
),
)
// Then
.andExpect(status().isOk)
.andExpect(jsonPath("$.reportId", equalTo(fakePriorNotification.reportId!!)))
.andExpect(jsonPath("$.asManualDraft.fishingCatches[0].weight", equalTo(12.0)))
.andExpect(jsonPath("$.asManualDraft.fishingCatches[1].weight", equalTo(0.0)))
.andExpect(jsonPath("$.logbookMessage.message.catchOnboard[0].weight", equalTo(12.0)))
.andExpect(jsonPath("$.logbookMessage.message.catchToLand[1].weight", equalTo(null)))
}

@Test
fun `getPdf Should get the PDF of a prior notification`() {
val dummyPdfContent =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,4 @@ context('Side Window > Logbook Prior Notification Card > Card', () => {
cy.contains(`L'ANCRE SÈCHE (CFR106)`).should('not.exist')
})
})

// Non-regression test
it('Should display a logbook prior notification with null fishing catch weight as expected', () => {
openSideWindowPriorNotificationCardAsUser(`VENT`, 'FAKE_OPERATION_120')

cy.contains('BAUDROIE (ANF)').parent().find('[data-cy="SpecyCatch-weight"]').should('have.text', '-')
})
})

0 comments on commit 0efc167

Please sign in to comment.