Skip to content

Commit

Permalink
Merge branch 'main' into jpa-init-infraction-natinf
Browse files Browse the repository at this point in the history
  • Loading branch information
lwih authored Oct 18, 2024
2 parents 7c0c80b + df6b836 commit 961277e
Show file tree
Hide file tree
Showing 16 changed files with 308 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ variables:
value: "postgres:15.8-alpine"
description: "Image de la base de données"
PROJECT_VERSION:
value: "2.2.5"
value: "2.2.6"
description: "Version du projet à déployer"
SERVER_ENV_INT:
value: "int-rapportnav-appli01"
Expand Down
2 changes: 1 addition & 1 deletion backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.lang.System.getenv

group = "fr.gouv.dgampa"
version = "2.2.5"
version = "2.2.6"
description = "RapportNav"

val kotlinVersion by extra("1.9.24")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ data class AEMIllegalFish(

fun getNbrOfInfractionWithPV(fishActions: List<ExtendedFishActionEntity?>): Double {
return fishActions.map { it?.controlAction?.action }.fold(0.0) { acc, c ->
acc.plus(c!!.gearInfractions.filter { g -> g.infractionType == InfractionType.WITH_RECORD }.size)
.plus(c.otherInfractions.filter { o -> o.infractionType == InfractionType.WITH_RECORD }.size)
.plus(c.speciesInfractions.filter { s -> s.infractionType == InfractionType.WITH_RECORD }.size)
.plus(c.logbookInfractions.filter { l -> l.infractionType == InfractionType.WITH_RECORD }.size)
acc.plus(c?.gearInfractions?.filter { g -> g.infractionType == InfractionType.WITH_RECORD }?.size ?: 0)
.plus(
c?.otherInfractions?.filter { o -> o.infractionType == InfractionType.WITH_RECORD }?.size ?: 0
)
.plus(
c?.speciesInfractions?.filter { s -> s.infractionType == InfractionType.WITH_RECORD }?.size ?: 0
)
.plus(
c?.logbookInfractions?.filter { l -> l.infractionType == InfractionType.WITH_RECORD }?.size ?: 0
)
};
}

Expand All @@ -61,7 +67,7 @@ data class AEMIllegalFish(
}

fun getQuantityOfFish(fishActions: List<ExtendedFishActionEntity?>): Double {
return 0.0;
return 0.0; //TODO: hasSomeSpeciesSeized
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@ data class AEMMigrationRescue(

companion object {
fun getNbrPersonsRescued(actionRescues: List<ActionRescueEntity?>): Double {
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.numberPersonsRescued!!) }
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.numberPersonsRescued ?: 0) }
}

fun getNbrOfVesselsTrackedWithoutIntervention(actionRescues: List<ActionRescueEntity?>): Double {
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.nbOfVesselsTrackedWithoutIntervention!!) }
return actionRescues.fold(0.0) { acc, actionRescue ->
acc.plus(
actionRescue?.nbOfVesselsTrackedWithoutIntervention ?: 0
)
}
}

fun getAssistedVesselsReturningToShore(actionRescues: List<ActionRescueEntity?>): Double {
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.nbAssistedVesselsReturningToShore!!) }
return actionRescues.fold(0.0) { acc, actionRescue ->
acc.plus(
actionRescue?.nbAssistedVesselsReturningToShore ?: 0
)
}
}

private fun actionRescueEntities(navActions: List<NavActionEntity>): List<ActionRescueEntity?> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data class AEMOutOfMigrationRescue(

companion object {
fun getNbrPersonsRescued(actionRescues: List<ActionRescueEntity?>): Double {
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.numberPersonsRescued!!) }
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.numberPersonsRescued ?: 0) }
}

private fun actionRescueEntities(navActions: List<NavActionEntity>): List<ActionRescueEntity?> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,25 @@ import fr.gouv.dgampa.rapportnav.domain.repositories.mission.crew.IMissionCrewRe
class GetAgentsCrewByMissionId(private val agentCrewRepository: IMissionCrewRepository) {

fun execute(missionId: Int, commentDefaultsToString: Boolean? = false): List<MissionCrewEntity> {
val rolePriority = listOf(
"Commandant",
"Second capitaine",
"Second",
"Chef mécanicien",
"Second mécanicien",
"Mécanicien électricien",
"Mécanicien",
"Chef de quart",
"Maître d’équipage",
"Agent pont",
"Agent machine",
"Agent mécanicien",
"Électricien",
"Cuisinier",
)

return agentCrewRepository.findByMissionId(missionId = missionId)
.map { it.toMissionCrewEntity(commentDefaultsToString) }
.sortedBy { it.id }
.sortedBy { rolePriority.indexOf(it.role.title) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MissionCrewModel(
var missionId: Int,

@Column(name = "comment", nullable = true)
var comment: String?,
var comment: String? = null,

@ManyToOne
@JoinColumn(name = "agent_role_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ class AEMOutOfMigrationRescueTest {
assertThat(migrationRescue.nbrOfRescuedOperation).isEqualTo(nbrOfRescuedOperation);
}

@Test
fun `Should not thow null pointer exception event if nbrPersonsRescued is null`() {
val action = NavActionEntity(
id = UUID.randomUUID(),
missionId = 761,
actionType = ActionType.ILLEGAL_IMMIGRATION,
startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"),
endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"),
rescueAction = ActionRescueEntity(
missionId = 761,
id = UUID.randomUUID(),
startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"),
endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"),
observations = "",
numberPersonsRescued = null,
numberOfDeaths = 0,
isMigrationRescue = false
)
)
val migrationRescue = AEMOutOfMigrationRescue(navActions = listOf(action));
assertThat(migrationRescue).isNotNull();
assertThat(migrationRescue.nbrPersonsRescued).isEqualTo(0.0);
}

private fun navActionEntities(): List<NavActionEntity> {
val actions = listOf(
NavActionEntity(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.crew

import fr.gouv.dgampa.rapportnav.domain.repositories.mission.crew.IMissionCrewRepository
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.crew.GetAgentsCrewByMissionId
import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.crew.AgentModel
import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.crew.AgentRoleModel
import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.crew.MissionCrewModel
import junit.framework.TestCase.assertEquals
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.mock.mockito.MockBean

@SpringBootTest(classes = [GetAgentsCrewByMissionId::class])
class GetAgentsCrewByMissionIdTest {

@Autowired
private lateinit var getAgentsCrewByMissionId: GetAgentsCrewByMissionId

@MockBean
private lateinit var agentCrewRepository: IMissionCrewRepository


@Test
fun `execute should return sorted list of crew members by role priority`() {

val missionId = 1

val johnDoe = AgentModel(
firstName = "John",
lastName = "Doe",
id = 1
)

val janeDoe = AgentModel(
firstName = "Jane",
lastName = "Doe",
id = 2
)

val alfredDeMusset = AgentModel(
firstName = "Alfred",
lastName = "de Musset",
id = 3
)

val guyDeMaupassant = AgentModel(
firstName = "Guy",
lastName = "de Maupassant",
id = 4
)

val chefMecano = AgentRoleModel(
title = "Chef mécanicien",
id = 1
)

val secondCapitaine = AgentRoleModel(
title = "Second capitaine",
id = 2
)

val cuisinier = AgentRoleModel(
title = "Cuisinier",
id = 3
)

val commandant = AgentRoleModel(
title = "Commandant",
id = 4
)

val crewMembers = listOf(
MissionCrewModel(role = chefMecano, agent = janeDoe, missionId = missionId, id = 1),
MissionCrewModel(role = secondCapitaine, agent = johnDoe, missionId = missionId, id = 2),
MissionCrewModel(role = cuisinier, agent = alfredDeMusset, missionId = missionId, id = 3),
MissionCrewModel(role = commandant, agent = guyDeMaupassant, missionId = missionId, id = 4),
)

`when`(agentCrewRepository.findByMissionId(missionId)).thenReturn(crewMembers)

val sortedCrew = getAgentsCrewByMissionId.execute(missionId, commentDefaultsToString = false)

// Assert
val expectedRoles = listOf("Commandant", "Second capitaine", "Chef mécanicien", "Cuisinier")
assertEquals(expectedRoles, sortedCrew.map { it.role.title })
}
}
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "2.2.5",
"version": "2.2.6",
"private": true,
"type": "module",
"engines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as useActionByIdModule from '@features/pam/mission/hooks/use-action-by-
import * as useIsMissionFinishedModule from '@features/pam/mission/hooks/use-is-mission-finished.tsx'
import { vi } from 'vitest'
import { render } from '../../../../../../test-utils.tsx'
import { THEME } from '@mtes-mct/monitor-ui'

vi.mock('react-router-dom', async importOriginal => {
const actual = await importOriginal()
Expand Down Expand Up @@ -50,9 +51,10 @@ describe('ActionIllegalImmigrationForm', () => {
})

it('should render error when no values and mission is finished', async () => {
const red = '#e1000f'
vi.spyOn(useIsMissionFinishedModule, 'default').mockReturnValue(true)
const wrapper = render(<ActionIllegalImmigrationForm action={action} />)
expect(wrapper.getByRole('nbOfInterceptedVessels')).toHaveStyle(`border: 1px solid ${red};`)
expect(wrapper.getByRole('nbOfInterceptedVessels')).toHaveStyle(
`border: 1px solid ${THEME.color.maximumRed.toLowerCase()};`
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { vi } from 'vitest'
import { fireEvent, render, screen } from '../../../../../../test-utils.tsx'
import UIThemeWrapper from '../../../../../common/components/ui/ui-theme-wrapper.tsx'
import MissionRecognizedVessel from './mission-recognized-vessel.tsx'
import * as useIsMissionFinishedModule from '@features/pam/mission/hooks/use-is-mission-finished.tsx'
import { THEME } from '@mtes-mct/monitor-ui'

const info = {
id: 3,
distanceInNauticalMiles: 23,
consumedGOInLiters: 0,
consumedFuelInLiters: 0,
serviceId: 5,
nbrOfRecognizedVessel: 0
nbrOfRecognizedVessel: 5
} as MissionGeneralInfo

const mutateMock = vi.fn()
Expand All @@ -35,23 +37,52 @@ describe('MissionRecognizedVessel', () => {
expect(screen.getByText(`Nombre total de navires reconnus dans les approches maritimes (ZEE)`)).toBeTruthy()
})

it('should call update information general', () => {
const nbrOfRecognizedVessel = 9
vi.useFakeTimers({ shouldAdvanceTime: true })
const wrapper = render(
<UIThemeWrapper>
<MissionRecognizedVessel missionId={1} generalInfo={info} />
</UIThemeWrapper>
)
const element = wrapper.getByTestId('mission-information-general-recognized-vessel')
fireEvent.change(element, {
target: { value: nbrOfRecognizedVessel }
describe('Validation', () => {
it('should show error validation when mission is finished but no info ', () => {
vi.spyOn(useIsMissionFinishedModule, 'default').mockReturnValue(true)
render(<MissionRecognizedVessel missionId={1} generalInfo={undefined} />)
const element = screen.getByLabelText('Nombre total de navires reconnus dans les approches maritimes (ZEE)')
expect(getComputedStyle(element).borderColor).toBe(THEME.color.maximumRed.toLowerCase())
})
expect(mutateMock).not.toHaveBeenCalled()
vi.advanceTimersByTime(5000)
expect(mutateMock).toHaveBeenCalledTimes(1)
expect(mutateMock).toHaveBeenCalledWith({
variables: { info: expect.objectContaining({ nbrOfRecognizedVessel }) }
it('should not show error validation when mission is finished but info ', () => {
vi.spyOn(useIsMissionFinishedModule, 'default').mockReturnValue(true)
render(<MissionRecognizedVessel missionId={1} generalInfo={info} />)
const element = screen.getByLabelText('Nombre total de navires reconnus dans les approches maritimes (ZEE)')
expect(getComputedStyle(element).borderColor).not.toBe(THEME.color.maximumRed.toLowerCase())
})
it('should not show error validation when mission is not finished but info ', () => {
vi.spyOn(useIsMissionFinishedModule, 'default').mockReturnValue(false)
render(<MissionRecognizedVessel missionId={1} generalInfo={info} />)
const element = screen.getByLabelText('Nombre total de navires reconnus dans les approches maritimes (ZEE)')
expect(getComputedStyle(element).borderColor).not.toBe(THEME.color.maximumRed.toLowerCase())
})
it('should not show error validation when mission is not finished and no info ', () => {
vi.spyOn(useIsMissionFinishedModule, 'default').mockReturnValue(false)
render(<MissionRecognizedVessel missionId={1} generalInfo={undefined} />)
const element = screen.getByLabelText('Nombre total de navires reconnus dans les approches maritimes (ZEE)')
expect(getComputedStyle(element).borderColor).not.toBe(THEME.color.maximumRed.toLowerCase())
})
})

describe('Updating data', () => {
it('should call update information general on change', () => {
const nbrOfRecognizedVessel = 9
vi.useFakeTimers({ shouldAdvanceTime: true })
const wrapper = render(
<UIThemeWrapper>
<MissionRecognizedVessel missionId={1} generalInfo={info} />
</UIThemeWrapper>
)
const element = wrapper.getByTestId('mission-information-general-recognized-vessel')
fireEvent.change(element, {
target: { value: nbrOfRecognizedVessel }
})
expect(mutateMock).not.toHaveBeenCalled()
vi.advanceTimersByTime(5000)
expect(mutateMock).toHaveBeenCalledTimes(1)
expect(mutateMock).toHaveBeenCalledWith({
variables: { info: expect.objectContaining({ nbrOfRecognizedVessel }) }
})
})
})
})
Loading

0 comments on commit 961277e

Please sign in to comment.