Skip to content

Commit

Permalink
Merge pull request #34 from hmrc/TAV-381
Browse files Browse the repository at this point in the history
[PS] TAV-381 - Add poBox field to address search results
  • Loading branch information
beyond-code-github authored Sep 14, 2021
2 parents 212fb1d + e8032dd commit 4418e29
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/address/model/AddressRecord.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ case class AddressRecord(
language: String,
localCustodian: Option[LocalCustodian],
location: Option[Seq[BigDecimal]],
administrativeArea: Option[String] = None) {
administrativeArea: Option[String] = None,
poBox: Option[String] = None) {

require(location.isEmpty || location.get.size == 2, location.get)

Expand Down
2 changes: 1 addition & 1 deletion app/address/model/AddressRecordConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object AddressRecordConverter {

val a = new Address(d.lines, d.town, d.postcode, optSubdivision, country)

new AddressRecord(d.id, Some(d.uprn), a, language, optLC, location, d.administrativeArea)
AddressRecord(d.id, Some(d.uprn), a, language, optLC, location, d.administrativeArea, d.poBox)
}

final val English = "en"
Expand Down
3 changes: 2 additions & 1 deletion app/osgb/outmodel/AddressReadable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ object AddressReadable {
(JsPath \ "language").read[String] and
(JsPath \ "localCustodian").readNullable[LocalCustodian] and
(JsPath \ "location").readNullable[Seq[BigDecimal]] and
(JsPath \ "administrativeArea").readNullable[String]
(JsPath \ "administrativeArea").readNullable[String] and
(JsPath \ "poBox").readNullable[String]
) (AddressRecord.apply _)

}
3 changes: 2 additions & 1 deletion app/osgb/outmodel/AddressWriteable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ object AddressWriteable {
(JsPath \ "language").write[String] and
(JsPath \ "localCustodian").writeNullable[LocalCustodian] and
(JsPath \ "location").writeNullable[Seq[BigDecimal]] and
(JsPath \ "administrativeArea").writeNullable[String]
(JsPath \ "administrativeArea").writeNullable[String] and
(JsPath \ "poBox").writeNullable[String]
) (unlift(AddressRecord.unapply))

}
1 change: 1 addition & 0 deletions conf/data/testaddresses.csv
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,5 @@
4510720604, "", 12-20 AStreet, "", ACity, FX1 1PG
4510147314, "FLAT 5", 44 AStreet, "", ACity, FX1 1PG
4510732929, "GROUND FLOOR", 52 AStreet, "", ACity, FX1 1PG
4510732930, "PO BOX 1234", "", "", "", PO1 1PO, , ,1234
9999999999, "GROUND FLOOR", 52 AStreet, "FLOOR 1", ACity, FX1 1PG
9 changes: 9 additions & 0 deletions test/it/it/suites/PostcodeLookupSuiteV2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ class PostcodeLookupSuiteV2 ()
address1.postcode mustBe "FX4 7AL"
}

"give a successful response for a po box postcode" in {
val response = get("/v2/uk/addresses?postcode=PO11PO")
assert(response.status === OK, dump(response))
val json = Json.parse(response.body)
val arr = json.asInstanceOf[JsArray].value
val address1 = Json.fromJson[AddressRecord](arr.head).get
address1.poBox mustBe Some("1234")
}

"set the content type to application/json" in {
val response = get("/v2/uk/addresses?postcode=FX1+9PY")
val contentType = response.header("Content-Type").get
Expand Down
14 changes: 11 additions & 3 deletions test/unit/osgb/services/ResponseProcessorTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,16 @@ class ResponseProcessorTest extends AnyFunSuite {
val dbNI2: DbAddress = DbAddress("GB10008", List("wxyz1", "wxyz2", "wxyz3"), "ATown", "FX11 4HG",
Some("GB-NIR"), Some("UK"), Some(8132), Some("en"), None, Some(locNI2.toString))

val expNI1M: AddressRecord = AddressRecord("GB10007", Some(10007L), Address(List("Line1", "Line2", "Line3"), "ATown", "FX11 4HG", Some(NorthernIreland), UK), en, lc8132, Some(locNI1.toSeq))
val expNI1M: AddressRecord = AddressRecord("GB10007", Some(10007L), Address(List("Line1", "Line2", "Line3"),
"ATown", "FX11 4HG", Some(NorthernIreland), UK), en, lc8132, Some(locNI1.toSeq))

val expNI2M: AddressRecord = AddressRecord("GB10008", Some(10008L), Address(List("wxyz1", "wxyz2", "wxyz3"), "ATown", "FX11 4HG", Some(NorthernIreland), UK), en, lc8132, Some(locNI2.toSeq))
val expNI2M: AddressRecord = AddressRecord("GB10008", Some(10008L), Address(List("wxyz1", "wxyz2", "wxyz3"),
"ATown", "FX11 4HG", Some(NorthernIreland), UK), en, lc8132, Some(locNI2.toSeq))

val dbPoBox: DbAddress = DbAddress("GB10008", List("PO BOX 1234", "", ""), "", "PO1 1PO",
Some("GB-NIR"), Some("UK"), Some(8132), Some("en"), None, Some(locNI2.toString), Some("1234"))
val expPoBox: AddressRecord = AddressRecord("GB10008", Some(10008L), Address(List("PO BOX 1234", "", ""),
"", "PO1 1PO", Some(NorthernIreland), UK), en, lc8132, Some(locNI2.toSeq), None, Some("1234"))

val refData: ReferenceData = ReferenceData.load("sample_local_custodian_table.csv")

Expand All @@ -86,7 +93,8 @@ class ResponseProcessorTest extends AnyFunSuite {
and include the metadata
""") {
val rp = new ResponseProcessor(refData)
for (de <- List(dbGB1 -> expGB1M, dbGB2 -> expGB2M, dbGB10 -> expGB10M, dbGB11 -> expGB11M, dbGBZ -> expGBZM, dbNI1 -> expNI1M, dbNI2 -> expNI2M)) {
for (de <- List(dbGB1 -> expGB1M, dbGB2 -> expGB2M, dbGB10 -> expGB10M, dbGB11 -> expGB11M, dbGBZ -> expGBZM,
dbNI1 -> expNI1M, dbNI2 -> expNI2M, dbPoBox -> expPoBox)) {
val in = List(de._1)
val exp = List(de._2)
val adr = rp.convertAddressList(in)
Expand Down

0 comments on commit 4418e29

Please sign in to comment.