Skip to content

Commit

Permalink
PI-2667 Common Platform Address records - OS Places API
Browse files Browse the repository at this point in the history
- Added wiremock mappings files
- Fixed failing tests
  • Loading branch information
joseph-bcl committed Dec 6, 2024
1 parent 0267333 commit f4e41fe
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"header": { "totalresults": 0 },
"results": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"header": { "totalresults": 1 },
"results": [
{
"DPA": {
"ADDRESS": "123 Test Street, Test, AB1 2CD",
"POSTCODE": "AB1 2CD",
"BUILDING_NUMBER": "123",
"THOROUGHFARE_NAME": "Test Street",
"POST_TOWN": "Test",
"MATCH": 0.9
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"request": {
"method": "GET",
"urlPath": "/address-lookup/search/places/v1/find"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"bodyFileName": "address-lookup-single-result.json"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"request": {
"method": "POST",
"urlPath": "/probation-search/match"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"bodyFileName": "probation-search-no-results.json"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,67 +97,27 @@ internal class IntegrationTest {

@Test
fun `When a message with no prosecution cases is found no insert is performed`() {
wireMockServer.stubFor(
post(urlPathEqualTo("/probation-search/match"))
.willReturn(
aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBodyFile("probation-search-no-results.json")
)
)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT_NO_CASES)
channelManager.getChannel(queueName).publishAndWait(notification)
thenNoRecordsAreInserted()
}

@Test
fun `When a message without a judicial result of remanded in custody is found`() {
wireMockServer.stubFor(
post(urlPathEqualTo("/probation-search/match"))
.willReturn(
aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBodyFile("probation-search-no-results.json")
)
)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT_NO_REMAND)
channelManager.getChannel(queueName).publishAndWait(notification)
thenNoRecordsAreInserted()
}

@Test
fun `When a person under 10 years old is found no insert is performed`() {
wireMockServer.stubFor(
post(urlPathEqualTo("/probation-search/match"))
.willReturn(
aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBodyFile("probation-search-no-results.json")
)
)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT_DOB_ERROR)
channelManager.getChannel(queueName).publishAndWait(notification)
thenNoRecordsAreInserted()
}

@Test
fun `When a probation search match is not detected then a person is inserted`() {
wireMockServer.stubFor(
post(urlPathEqualTo("/probation-search/match"))
.willReturn(
aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBodyFile("probation-search-no-results.json")
)
)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT)
channelManager.getChannel(queueName).publishAndWait(notification)

Expand All @@ -181,33 +141,13 @@ internal class IntegrationTest {

@Test
fun `When a hearing message with missing required fields is detected no records are inserted`() {
wireMockServer.stubFor(
post(urlPathEqualTo("/probation-search/match"))
.willReturn(
aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBodyFile("probation-search-no-results.json")
)
)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT_NULL_FIELDS)
channelManager.getChannel(queueName).publishAndWait(notification)
thenNoRecordsAreInserted()
}

@Test
fun `When a hearing with an address is received then an address record is inserted`() {
wireMockServer.stubFor(
post(urlPathEqualTo("/probation-search/match"))
.willReturn(
aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBodyFile("probation-search-no-results.json")
)
)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT)
channelManager.getChannel(queueName).publishAndWait(notification)

Expand Down Expand Up @@ -236,16 +176,6 @@ internal class IntegrationTest {

@Test
fun `When a hearing with an empty address is received then an address record is not inserted`() {
wireMockServer.stubFor(
post(urlPathEqualTo("/probation-search/match"))
.willReturn(
aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBodyFile("probation-search-no-results.json")
)
)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT_BLANK_ADDRESS)
channelManager.getChannel(queueName).publishAndWait(notification)

Expand All @@ -265,16 +195,6 @@ internal class IntegrationTest {
@Order(1)
@Test
fun `engagement created and address created sns messages are published on insert person`() {
wireMockServer.stubFor(
post(urlPathEqualTo("/probation-search/match"))
.willReturn(
aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBodyFile("probation-search-no-results.json")
)
)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT)
channelManager.getChannel(queueName).publishAndWait(notification)

Expand Down Expand Up @@ -377,31 +297,6 @@ internal class IntegrationTest {

@Test
fun `Address lookup api is inserted when result is found`() {
wireMockServer.stubFor(
get(urlPathEqualTo("/address-lookup/search/places/v1/find"))
.willReturn(
okJson(
"""
{
"header": { "totalresults": 1 },
"results": [
{
"DPA": {
"address": "123 Test Street, Test, AB1 2CD",
"postcode": "AB1 2CD",
"buildingNumber": "123",
"thoroughfareName": "Test Street",
"postTown": "Test",
"match": 0.9
}
}
]
}
"""
)
)
)

val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT)
channelManager.getChannel(queueName).publishAndWait(notification)

Expand Down Expand Up @@ -429,4 +324,9 @@ internal class IntegrationTest {
verify(auditedInteractionService, Mockito.never())
.createAuditedInteraction(any(), any(), eq(AuditedInteraction.Outcome.SUCCESS), any(), anyOrNull())
}

@AfterEach
fun resetWireMock() {
wireMockServer.resetAll()
}
}

0 comments on commit f4e41fe

Please sign in to comment.