-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: move v2 missions endpoints to REST #497
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 0 additions & 9 deletions
9
...kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/MissionsFetchEnvInput.kt
This file was deleted.
Oops, something went wrong.
65 changes: 0 additions & 65 deletions
65
.../src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionController.kt
This file was deleted.
Oops, something went wrong.
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
159 changes: 159 additions & 0 deletions
159
...lin/fr/gouv/gmampa/rapportnav/infrastructure/bff/controllers/MissionRestControllerTest.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,159 @@ | ||
package fr.gouv.gmampa.rapportnav.infrastructure.bff.controllers | ||
|
||
import fr.gouv.dgampa.rapportnav.RapportNavApplication | ||
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.CreateEnvMission | ||
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.FakeMissionData | ||
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.GetEnvMissions | ||
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.GetMission | ||
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.GetEnvMissionById2 | ||
import fr.gouv.dgampa.rapportnav.domain.use_cases.user.GetControlUnitsForUser | ||
import fr.gouv.dgampa.rapportnav.domain.use_cases.user.GetUserFromToken | ||
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.v2.MissionRestController | ||
import fr.gouv.gmampa.rapportnav.mocks.mission.EnvMissionMock | ||
import fr.gouv.gmampa.rapportnav.mocks.mission.EnvMissionMockv2 | ||
import fr.gouv.gmampa.rapportnav.mocks.mission.LegacyControlUnitEntityMock | ||
import fr.gouv.gmampa.rapportnav.mocks.mission.MissionEntityMock | ||
import fr.gouv.gmampa.rapportnav.mocks.mission.MissionGeneralInfo2Mock | ||
import fr.gouv.gmampa.rapportnav.mocks.user.UserMock | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.ArgumentMatchers.any | ||
import org.mockito.Mockito.`when` | ||
import org.mockito.kotlin.anyOrNull | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest | ||
import org.springframework.http.MediaType | ||
import org.springframework.test.context.ContextConfiguration | ||
import org.springframework.test.context.bean.override.mockito.MockitoBean | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post | ||
import fr.gouv.dgampa.rapportnav.infrastructure.utils.GsonSerializer | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content | ||
import java.time.Instant | ||
|
||
@AutoConfigureMockMvc(addFilters = false) | ||
@ContextConfiguration(classes = [RapportNavApplication::class]) | ||
@WebMvcTest(MissionRestController::class) | ||
class MissionRestControllerTest { | ||
|
||
@Autowired | ||
private lateinit var mockMvc: MockMvc | ||
|
||
@MockitoBean | ||
private lateinit var getEnvMissions: GetEnvMissions | ||
|
||
@MockitoBean | ||
private lateinit var getControlUnitsForUser: GetControlUnitsForUser | ||
|
||
@MockitoBean | ||
private lateinit var getMission: GetMission | ||
|
||
@MockitoBean | ||
private lateinit var getUserFromToken: GetUserFromToken | ||
|
||
@MockitoBean | ||
private lateinit var fakeMissionData: FakeMissionData | ||
|
||
@MockitoBean | ||
private lateinit var createEnvMission: CreateEnvMission | ||
|
||
@MockitoBean | ||
private lateinit var getEnvMissionById2: GetEnvMissionById2 | ||
|
||
@Test | ||
fun `should return a list of missions`() { | ||
// Arrange | ||
val mockEnvMissions = listOf( | ||
EnvMissionMock.create(id = 1), | ||
EnvMissionMock.create(id = 2), | ||
) | ||
val mockMissionEntity = MissionEntityMock.create(id = 1) | ||
|
||
|
||
val mockUser = UserMock.create() | ||
|
||
`when`(getControlUnitsForUser.execute()).thenReturn(listOf(1)) | ||
`when`(getEnvMissions.execute(any(), any(), anyOrNull(), anyOrNull(), any())).thenReturn(mockEnvMissions) | ||
`when`(getMission.execute(any(), any())).thenReturn(mockMissionEntity) | ||
`when`(getUserFromToken.execute()).thenReturn(mockUser) | ||
`when`(fakeMissionData.getFakeMissionsforUser(mockUser)).thenReturn(emptyList()) | ||
|
||
// Act & Assert | ||
mockMvc.perform( | ||
get("/api/v2/missions") | ||
.param("startDateTimeUtc", Instant.now().toString()) | ||
) | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("$.length()").value(mockEnvMissions.size)) | ||
} | ||
|
||
@Test | ||
fun `should return a mission by id`() { | ||
// Arrange | ||
val missionId = 1 | ||
val mockMission = EnvMissionMock.create(id = missionId) | ||
`when`(getEnvMissionById2.execute(missionId)).thenReturn(mockMission) | ||
|
||
// Act & Assert | ||
mockMvc.perform(get("/api/v2/missions/{missionId}", missionId)) | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("$.id").value(missionId)) | ||
} | ||
|
||
@Test | ||
fun `should create a new mission`() { | ||
val gson = GsonSerializer().create() | ||
// Arrange | ||
val requestBody = MissionGeneralInfo2Mock.create() | ||
val controlUnitsIds = listOf(456) | ||
val mockMission = EnvMissionMockv2.create( | ||
id = 123, | ||
controlUnits = listOf(LegacyControlUnitEntityMock.create(id = controlUnitsIds.first())) | ||
) | ||
`when`(getControlUnitsForUser.execute()).thenReturn(controlUnitsIds) | ||
`when`(createEnvMission.execute(requestBody, controlUnitsIds)).thenReturn(mockMission) | ||
|
||
// Act & Assert | ||
mockMvc.perform( | ||
post("/api/v2/missions") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.characterEncoding("UTF-8") | ||
.content(gson.toJson(requestBody)) | ||
) | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("$.id").value(123)) | ||
} | ||
|
||
@Test | ||
fun `should return null when mission creation fails`() { | ||
val gson = GsonSerializer().create() | ||
|
||
// Arrange | ||
val requestBody = MissionGeneralInfo2Mock.create() | ||
val controlUnitsIds = listOf(456) | ||
`when`(getControlUnitsForUser.execute()).thenReturn(controlUnitsIds) | ||
// Simulate mission creation returning null | ||
`when`( | ||
createEnvMission.execute( | ||
requestBody, | ||
controlUnitsIds | ||
) | ||
).thenThrow(RuntimeException("Mission creation failed")) | ||
// Act & Assert | ||
mockMvc.perform( | ||
post("/api/v2/missions") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.characterEncoding("UTF-8") | ||
.content(gson.toJson(requestBody)) | ||
) | ||
.andExpect(status().isOk) // The status should be 200 OK | ||
.andExpect( | ||
content().string("") | ||
) | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really need to find a way to remove fake missions, really