@@ -6,6 +6,7 @@ import com.nhaarman.mockitokotlin2.given
6
6
import fr.gouv.cnsp.monitorfish.config.*
7
7
import fr.gouv.cnsp.monitorfish.domain.use_cases.authorization.GetIsAuthorizedUser
8
8
import fr.gouv.cnsp.monitorfish.domain.use_cases.vessel_groups.AddOrUpdateDynamicVesselGroup
9
+ import fr.gouv.cnsp.monitorfish.domain.use_cases.vessel_groups.GetAllVesselGroups
9
10
import fr.gouv.cnsp.monitorfish.infrastructure.api.log.CustomAuthenticationEntryPoint
10
11
import fr.gouv.cnsp.monitorfish.infrastructure.api.security.TestUtils.Companion.getMockApiClient
11
12
import fr.gouv.cnsp.monitorfish.infrastructure.api.security.UserAuthorizationCheckFilter
@@ -23,6 +24,7 @@ import org.springframework.context.annotation.Import
23
24
import org.springframework.http.MediaType
24
25
import org.springframework.security.oauth2.jwt.JwtDecoder
25
26
import org.springframework.test.web.servlet.MockMvc
27
+ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
26
28
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
27
29
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
28
30
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
@@ -49,9 +51,6 @@ class VesselGroupControllerITests {
49
51
@Autowired
50
52
private lateinit var api: MockMvc
51
53
52
- @MockBean
53
- private lateinit var addOrUpdateDynamicVesselGroup: AddOrUpdateDynamicVesselGroup
54
-
55
54
@Autowired
56
55
private lateinit var jwtDecoder: JwtDecoder
57
56
@@ -64,6 +63,12 @@ class VesselGroupControllerITests {
64
63
fun mockApiClient (): ApiClient = getMockApiClient()
65
64
}
66
65
66
+ @MockBean
67
+ private lateinit var addOrUpdateDynamicVesselGroup: AddOrUpdateDynamicVesselGroup
68
+
69
+ @MockBean
70
+ private lateinit var getAllVesselGroups: GetAllVesselGroups
71
+
67
72
@Autowired
68
73
private lateinit var objectMapper: ObjectMapper
69
74
@@ -88,4 +93,26 @@ class VesselGroupControllerITests {
88
93
89
94
Mockito .verify(addOrUpdateDynamicVesselGroup).execute(" email@domain-name.com" , groupToSave.copy(id = null ))
90
95
}
96
+
97
+ @Test
98
+ fun `Should get all dynamic vessel groups` () {
99
+ // Given
100
+ given(getIsAuthorizedUser.execute(any(), any())).willReturn(true )
101
+ given(getAllVesselGroups.execute(any())).willReturn(TestUtils .getDynamicVesselGroups())
102
+
103
+ // When
104
+ api
105
+ .perform(
106
+ get(" /bff/v1/vessel_groups" )
107
+ .header(" Authorization" , " Bearer ${UserAuthorizationControllerITests .VALID_JWT } " )
108
+ .contentType(MediaType .APPLICATION_JSON ),
109
+ )
110
+ // Then
111
+ .andExpect(status().isOk)
112
+ .andExpect(jsonPath(" $.length()" , equalTo(2 )))
113
+ .andExpect(jsonPath(" $[0].name" , equalTo(" Mission Thémis – chaluts de fonds" )))
114
+ .andExpect(jsonPath(" $[0].filters.hasLogbook" , equalTo(true )))
115
+
116
+ Mockito .verify(getAllVesselGroups).execute(" email@domain-name.com" )
117
+ }
91
118
}
0 commit comments