Skip to content

Commit c68f015

Browse files
1 parent a2791b2 commit c68f015

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/test/kotlin/uk/gov/justice/hmpps/probationsearch/contactsearch/ContactSearchIntegrationTest.kt

+22
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import org.junit.jupiter.api.BeforeEach
1111
import org.junit.jupiter.api.Test
1212
import org.junit.jupiter.params.ParameterizedTest
1313
import org.junit.jupiter.params.provider.MethodSource
14+
import org.mockito.kotlin.any
15+
import org.mockito.kotlin.eq
16+
import org.mockito.kotlin.verify
1417
import org.opensearch.action.admin.indices.alias.Alias
1518
import org.opensearch.action.admin.indices.delete.DeleteIndexRequest
1619
import org.opensearch.client.RequestOptions
@@ -22,11 +25,13 @@ import org.opensearch.data.client.orhlc.OpenSearchRestTemplate
2225
import org.springframework.beans.factory.annotation.Autowired
2326
import org.springframework.beans.factory.annotation.Value
2427
import org.springframework.boot.test.context.SpringBootTest
28+
import org.springframework.boot.test.mock.mockito.MockBean
2529
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates
2630
import org.springframework.data.elasticsearch.core.query.Query
2731
import org.springframework.http.MediaType
2832
import org.springframework.test.context.ActiveProfiles
2933
import org.springframework.util.ResourceUtils
34+
import uk.gov.justice.digital.hmpps.hmppsauditsdk.AuditService
3035
import uk.gov.justice.hmpps.probationsearch.contactsearch.ContactGenerator.contacts
3136
import uk.gov.justice.hmpps.probationsearch.util.JwtAuthenticationHelper
3237

@@ -43,6 +48,9 @@ class ContactSearchIntegrationTest {
4348
@Value("\${local.server.port}")
4449
internal val port: Int = 0
4550

51+
@MockBean
52+
internal lateinit var auditService: AuditService
53+
4654
@BeforeEach
4755
internal fun before() {
4856
RestAssured.port = port
@@ -87,6 +95,8 @@ class ContactSearchIntegrationTest {
8795
.map { it.id }
8896
.take(3),
8997
)
98+
99+
verify(auditService).publishEvent(eq("Search Contacts"), any(), eq(crn), eq("CRN"), any(), "probation-search")
90100
}
91101

92102
@ParameterizedTest
@@ -102,6 +112,8 @@ class ContactSearchIntegrationTest {
102112
val found = results.results.first()
103113
assertThat(found.crn).isEqualTo(crn)
104114
assertThat(found.highlights).containsExactlyInAnyOrderEntriesOf(mapOf("type" to listOf("<em>FIND_ME</em>")))
115+
116+
verify(auditService).publishEvent(eq("Search Contacts"), any(), eq(crn), eq("CRN"), any(), "probation-search")
105117
}
106118

107119
@Test
@@ -122,6 +134,8 @@ class ContactSearchIntegrationTest {
122134
.map { it.id }
123135
.take(4),
124136
)
137+
138+
verify(auditService).publishEvent(eq("Search Contacts"), any(), eq(crn), eq("CRN"), any(), "probation-search")
125139
}
126140

127141
@Test
@@ -142,6 +156,8 @@ class ContactSearchIntegrationTest {
142156
.map { it.id }
143157
.take(4),
144158
)
159+
160+
verify(auditService).publishEvent(eq("Search Contacts"), any(), eq(crn), eq("CRN"), any(), "probation-search")
145161
}
146162

147163
@Test
@@ -162,6 +178,8 @@ class ContactSearchIntegrationTest {
162178
.map { it.id }
163179
.take(4),
164180
)
181+
182+
verify(auditService).publishEvent(eq("Search Contacts"), any(), eq(crn), eq("CRN"), any(), "probation-search")
165183
}
166184

167185
@ParameterizedTest
@@ -176,6 +194,8 @@ class ContactSearchIntegrationTest {
176194

177195
assertThat(results.size).isEqualTo(1)
178196
assertThat(results.results.first().crn).isEqualTo(crn)
197+
198+
verify(auditService).publishEvent(eq("Search Contacts"), any(), eq(crn), eq("CRN"), any(), "probation-search")
179199
}
180200

181201
@Test
@@ -196,6 +216,8 @@ class ContactSearchIntegrationTest {
196216
"outcome" to listOf("Matches were <em>highlighted</em>"),
197217
),
198218
)
219+
220+
verify(auditService).publishEvent(eq("Search Contacts"), any(), eq(crn), eq("CRN"), any(), "probation-search")
199221
}
200222

201223
companion object {

0 commit comments

Comments
 (0)