Skip to content

Commit

Permalink
[Act-Rep] Afficher l'identifiant navire pour tous les pavillons (#2930)
Browse files Browse the repository at this point in the history
## Linked issues

- Resolve #2928

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
louptheron authored Feb 14, 2024
2 parents 810c413 + 8849135 commit 531a743
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,58 @@ data class Vessel(
val underCharter: Boolean? = null,
) {
fun getNationalIdentifier(): String {
val identifier = internalReferenceNumber?.replace("FRA000", "") ?: ""
val internalReferenceNumberCountryCode = LIKELY_CONTROLLED_COUNTRY_CODES.find { countryAlpha3 -> internalReferenceNumber?.contains(countryAlpha3) ?: false }
val identifier = internalReferenceNumber?.replace("${internalReferenceNumberCountryCode}000", "") ?: ""

if (districtCode.isNullOrEmpty()) {
return identifier
}

return "$districtCode$identifier"
}
}

val LIKELY_CONTROLLED_COUNTRY_CODES = listOf(
CountryCode.FR.alpha3,
CountryCode.RU.alpha3,
CountryCode.KR.alpha3,
CountryCode.JP.alpha3,
CountryCode.LY.alpha3,
CountryCode.VE.alpha3,
CountryCode.SC.alpha3,
CountryCode.AU.alpha3,
CountryCode.CN.alpha3,
CountryCode.MG.alpha3,
CountryCode.BR.alpha3,
CountryCode.PL.alpha3,
CountryCode.VU.alpha3,
CountryCode.KM.alpha3,
CountryCode.MC.alpha3,
CountryCode.BW.alpha3,
CountryCode.AI.alpha3,
CountryCode.LK.alpha3,
CountryCode.TW.alpha3,
CountryCode.TT.alpha3,
CountryCode.FO.alpha3,
CountryCode.GY.alpha3,
CountryCode.PA.alpha3,
CountryCode.SX.alpha3,
CountryCode.TN.alpha3,
CountryCode.TR.alpha3,
CountryCode.AL.alpha3,
CountryCode.GD.alpha3,
CountryCode.DZ.alpha3,
CountryCode.SX.alpha3,
CountryCode.BE.alpha3,
CountryCode.DK.alpha3,
CountryCode.DE.alpha3,
CountryCode.EE.alpha3,
CountryCode.IE.alpha3,
CountryCode.ES.alpha3,
CountryCode.IT.alpha3,
CountryCode.NL.alpha3,
CountryCode.NO.alpha3,
CountryCode.PT.alpha3,
CountryCode.SE.alpha3,
CountryCode.GB.alpha3,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package fr.gouv.cnsp.monitorfish.domain.entities.vessel

import com.neovisionaries.i18n.CountryCode
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.test.context.junit.jupiter.SpringExtension

@ExtendWith(SpringExtension::class)
class VesselUTests {
@Test
fun `getNationalIdentifier should return the identifier for a FR vessel`() {
// Given
val vessel = Vessel(
id = 1,
internalReferenceNumber = "FRA00022680",
vesselName = "MY AWESOME VESSEL",
flagState = CountryCode.FR,
declaredFishingGears = listOf("Trémails"),
vesselType = "Fishing",
districtCode = "AY",
)

// When
val nationalIdentifier = vessel.getNationalIdentifier()

// Then
assertThat(nationalIdentifier).isEqualTo("AY22680")
}

@Test
fun `getNationalIdentifier should return the identifier for a FR vessel When district code is null`() {
// Given
val vessel = Vessel(
id = 1,
internalReferenceNumber = "FRA00022680",
vesselName = "MY AWESOME VESSEL",
flagState = CountryCode.FR,
declaredFishingGears = listOf("Trémails"),
vesselType = "Fishing",
districtCode = "",
)

// When
val nationalIdentifier = vessel.getNationalIdentifier()

// Then
assertThat(nationalIdentifier).isEqualTo("22680")
}

@Test
fun `getNationalIdentifier should return the identifier for a GB vessel`() {
// Given
val vessel = Vessel(
id = 1,
internalReferenceNumber = "GBR00022680",
vesselName = "MY AWESOME VESSEL",
flagState = CountryCode.GB,
declaredFishingGears = listOf("Trémails"),
vesselType = "Fishing",
districtCode = "AY",
)

// When
val nationalIdentifier = vessel.getNationalIdentifier()

// Then
assertThat(nationalIdentifier).isEqualTo("AY22680")
}
}

0 comments on commit 531a743

Please sign in to comment.