-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #401 from MTES-MCT/398-trier-liste-équipage-selon-…
…grade bugfix(398) sort agent by role priority
- Loading branch information
Showing
3 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...n/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/crew/GetAgentsCrewByMissionIdTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | ||
} | ||
} |