Skip to content

Commit

Permalink
Merge pull request #15 from hmrc/RAS-71
Browse files Browse the repository at this point in the history
RAS-71: Added endpoint and test data
  • Loading branch information
joepowell96 authored Jun 20, 2017
2 parents 023f8c5 + 6e0674e commit d6b7d75
Show file tree
Hide file tree
Showing 13 changed files with 543 additions and 19 deletions.
50 changes: 50 additions & 0 deletions app/uk/gov/hmrc/rasapi/connectors/CachingConnector.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2017 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.rasapi.connectors

import uk.gov.hmrc.rasapi.models.CustomerDetails

trait CachingConnector {

def getCachedData(uuid: String): Option[CustomerDetails] = {

//TODO: Update this function to call our caching service(to be created) to access the data below

uuid match {
case "2800a7ab-fe20-42ca-98d7-c33f4133cfc2" => Some(CustomerDetails("AA123456A", "Jim", "Jimson", "1989-09-29"))
case "633e0ee7-315b-49e6-baed-d79c3dffe467" => Some(CustomerDetails("BB123456B", "John", "Smith", "1975-05-25"))
case "77648d82-309e-484d-a310-d0ffd2997791" => Some(CustomerDetails("CC123456C", "Jane", "Doe", "1969-06-09"))
case "79f21755-8cd4-4785-9c10-13253f7a8bb6" => Some(CustomerDetails("EE123456E", "Joe", "Bloggs", "1982-02-17"))
case "2900a7ab-fe20-42ca-98d8-c33f4133cfc2" => Some(CustomerDetails("AB234567B", "Peter", "Armstrong", "1969-01-01"))
case "743e0ee7-315b-49e7-baed-d79c3dffe467" => Some(CustomerDetails("BC234567C", "Steven", "Smith", "1947-08-15"))
case "88648d82-309e-484e-a310-d0ffd2997791" => Some(CustomerDetails("CD234567D", "Simon", "Handyside", "1984-10-31"))
case "88648d82-309e-484d-a310-d0ffd2997792" => Some(CustomerDetails("EF234567F", "Linda", "Marshall", "1966-06-21"))
case "3000a7ab-fe20-42ca-98d9-c33f4133cfc2" => Some(CustomerDetails("AC345678C", "Kelly", "Thompslon", "1990-02-15"))
case "853e0ee7-315b-49e8-baed-d79c3dffe467" => Some(CustomerDetails("BD345678D", "Simon", "Handyside", "1984-10-31"))
case "99648d82-309e-484f-a310-d0ffd2997791" => Some(CustomerDetails("CE345678E", "Zack", "Jackson", "1966-04-04"))
case "99648d82-309e-484d-a310-d0ffd2997793" => Some(CustomerDetails("EF234567F", "Linda", "Marshall", "1966-06-21"))
case "3100a7ab-fe20-42ca-98d1-c33f4133cfc2" => Some(CustomerDetails("AD456789D", "Oscar", "Smith", "1986-06-14"))
case "963e0ee7-315b-49e-baed-d79c3dffe467" => Some(CustomerDetails("BE456789E", "Louise", "Oscar", "1966-04-04"))
case "11648d82-309e-484g-a310-d0ffd2997791" => Some(CustomerDetails("CF456789F", "Raj", "Patel", "1984-10-31"))
case "76648d82-309e-484d-a310-d0ffd2997794" => Some(CustomerDetails("EH456789H", "Mary", "Brown", "1982-02-17"))
case "76648d82-309e-484d-a310-d0ffd2997795" => Some(CustomerDetails("AA666888B","Ramin","Raj", "1947-08-15"))
case _ => None
}
}
}

object CachingConnector extends CachingConnector
50 changes: 50 additions & 0 deletions app/uk/gov/hmrc/rasapi/connectors/DesConnector.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2017 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.rasapi.connectors

import uk.gov.hmrc.rasapi.models.{CustomerDetails, ResidencyStatus}

trait DESConnector {

def getResidencyStatus(customerDetails: CustomerDetails): Option[ResidencyStatus] = {

//TODO: Update this function to call ras-stubs to access the data below

customerDetails match {
case CustomerDetails("AA123456A", "Jim", "Jimson", "1989-09-29") => Some(ResidencyStatus("otherUKResident","otherUKResident"))
case CustomerDetails("BB123456B", "John", "Smith", "1975-05-25") => Some(ResidencyStatus("otherUKResident","scotResident"))
case CustomerDetails("CC123456C", "Jane", "Doe", "1969-06-09") => Some(ResidencyStatus("scotResident","otherUKResident"))
case CustomerDetails("EE123456E", "Joe", "Bloggs", "1982-02-17") => Some(ResidencyStatus("scotResident","scotResident"))
case CustomerDetails("AB234567B", "Peter", "Armstrong", "1969-01-01") => Some(ResidencyStatus("otherUKResident","otherUKResident"))
case CustomerDetails("BC234567C", "Steven", "Smith", "1947-08-15") => Some(ResidencyStatus("otherUKResident","scotResident"))
case CustomerDetails("CD234567D", "Simon", "Handyside", "1984-10-31") => Some(ResidencyStatus("scotResident","otherUKResident"))
case CustomerDetails("EF234567F", "Linda", "Marshall", "1966-06-21") => Some(ResidencyStatus("scotResident","scotResident"))
case CustomerDetails("AC345678C", "Kelly", "Thompson", "1990-02-15") => Some(ResidencyStatus("otherUKResident","otherUKResident"))
case CustomerDetails("BD345678D", "Simon", "Handyside", "1984-10-31") => Some(ResidencyStatus("otherUKResident","scotResident"))
case CustomerDetails("CE345678E", "Zack", "Jackson", "1966-04-04") => Some(ResidencyStatus("scotResident","otherUKResident"))
case CustomerDetails("EG345678G", "Linda", "Marshall", "1966-06-21") => Some(ResidencyStatus("scotResident","scotResident"))
case CustomerDetails("AD456789D", "Oscar", "Smith", "1986-06-14") => Some(ResidencyStatus("otherUKResident","otherUKResident"))
case CustomerDetails("BE456789E", "Louise", "Oscar", "1966-04-04") => Some(ResidencyStatus("otherUKResident","scotResident"))
case CustomerDetails("CF456789F", "Raj", "Patel", "1984-10-31") => Some(ResidencyStatus("scotResident","otherUKResident"))
case CustomerDetails("EH456789H", "Mary", "Brown", "1982-02-17") => Some(ResidencyStatus("scotResident","scotResident"))
case _ => None
}
}

}

object DESConnector extends DESConnector
40 changes: 32 additions & 8 deletions app/uk/gov/hmrc/rasapi/controllers/LookupController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,43 @@ package uk.gov.hmrc.rasapi.controllers

import play.api.mvc.{Action, AnyContent}
import uk.gov.hmrc.play.microservice.controller.BaseController
import uk.gov.hmrc.api.controllers.HeaderValidator
import uk.gov.hmrc.play.config.RunMode
import uk.gov.hmrc.rasapi.connectors.{CachingConnector, DESConnector}
import uk.gov.hmrc.rasapi.models.{CustomerDetails, InvalidUUIDForbiddenResponse, ResidencyStatus}
import play.api.libs.json.Json._
import play.api.Logger
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

trait LookupController extends BaseController{
trait LookupController extends BaseController with HeaderValidator with RunMode {

def helloWorld(): Action[AnyContent] = ???
}

object LookupController extends LookupController {
val cachingConnector: CachingConnector
val desConnector: DESConnector

override def helloWorld() = {Action.async {
def getResidencyStatus(uuid: String): Action[AnyContent] = validateAccept(acceptHeaderValidationRules).async {
implicit request =>

Future(Ok("Hello World"))
}}
cachingConnector.getCachedData(uuid) match {
case Some(customerDetails) => {
desConnector.getResidencyStatus(customerDetails) match {
case Some(rs) => Future(Ok(toJson(rs)))
case _ => {
Logger.debug("Failed to retrieve residency status[LookupController][getResidencyStatus]")
Future(InternalServerError)
}
}
}
case _ => {
Logger.debug("Failed to retrieve customer details[LookupController][getResidencyStatus]")
Future(Forbidden(toJson(InvalidUUIDForbiddenResponse)))
}
}
}

}

object LookupController extends LookupController {
override val cachingConnector: CachingConnector = CachingConnector
override val desConnector: DESConnector = DESConnector
}
26 changes: 26 additions & 0 deletions app/uk/gov/hmrc/rasapi/models/CustomerDetails.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2017 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.rasapi.models

import play.api.libs.json.Json

case class CustomerDetails(nino: String = "", firstName: String = "", lastName: String = "", dateOfBirth: String = "")

object CustomerDetails {
implicit val format = Json.format[CustomerDetails]
implicit val rds = Json.reads[CustomerDetails]
}
36 changes: 36 additions & 0 deletions app/uk/gov/hmrc/rasapi/models/ErrorResponses.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2017 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.rasapi.models

import play.api.libs.json.{JsValue, Json, Writes}

sealed abstract class ErrorResponse(
val httpStatusCode: Int,
val errorCode: String,
val message: String)

case object InvalidUUIDForbiddenResponse extends ErrorResponse(
403,
"INVALID_UUID",
"The match has timed out and the UUID is no longer valid. " +
"The match (POST to /match) will need to be repeated.") with JsonFormats

trait JsonFormats {
implicit val errorResponseWrites = new Writes[ErrorResponse] {
def writes(e: ErrorResponse): JsValue = Json.obj("code" -> e.errorCode, "message" -> e.message)
}
}
25 changes: 25 additions & 0 deletions app/uk/gov/hmrc/rasapi/models/ResidencyStatus.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2017 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.rasapi.models

import play.api.libs.json.Json

case class ResidencyStatus(currentYearResidencyStatus: String = "", nextYearForecastResidencyStatus: String = "")

object ResidencyStatus{
implicit val format = Json.format[ResidencyStatus]
}
2 changes: 1 addition & 1 deletion conf/app.routes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# microservice specific routes

GET /hello-world uk.gov.hmrc.rasapi.controllers.LookupController.helloWorld()
GET /customer/matched/:customerUUID/get-residency-status uk.gov.hmrc.rasapi.controllers.LookupController.getResidencyStatus(customerUUID)
2 changes: 1 addition & 1 deletion conf/prod.routes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Add all the application routes to the app.routes file
-> /ras-api app.Routes
-> / app.Routes
-> / health.Routes
-> / definition.Routes

Expand Down
2 changes: 1 addition & 1 deletion project/MicroService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait MicroService {

lazy val scoverageSettings = {
Seq(
ScoverageKeys.coverageExcludedPackages := "<empty>;testOnlyDoNotUseInAppConf.*;uk.gov.hmrc.rasapi.config.*;",
ScoverageKeys.coverageExcludedPackages := "<empty>;testOnlyDoNotUseInAppConf.*;uk.gov.hmrc.rasapi.config.*;conf.*;uk.gov.hmrc.rasapi.models.*;prod;app;uk.gov.hmrc;uk.gov.hmrc.rasapi;uk.gov.hmrc.rasapi.views.*;definition.*;ras.*;uk.gov.hmrc.rasapi.controllers.Documentation;uk.gov.hmrc.rasapi.connectors.ServiceLocatorConnector;dev.*;matching.* ",
ScoverageKeys.coverageMinimum := 70,
ScoverageKeys.coverageFailOnMinimum := false,
ScoverageKeys.coverageHighlighting := true,
Expand Down
128 changes: 128 additions & 0 deletions test/uk/gov/hmrc/rasapi/connectors/CachingConnectorSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright 2017 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.rasapi.connectors

import org.scalatest.mock.MockitoSugar
import org.scalatest.{WordSpec, _}
import uk.gov.hmrc.rasapi.models.CustomerDetails

class CachingConnectorSpec extends WordSpec with MockitoSugar with ShouldMatchers {

val SUT = CachingConnector

//TODO: The tests below will need to be updated after the migration of test data to stub

"getCachedData" should {
"return an option of some CustomerDetails" when {

"a valid uuid (2800a7ab-fe20-42ca-98d7-c33f4133cfc2) is found" in {
val result = SUT.getCachedData("2800a7ab-fe20-42ca-98d7-c33f4133cfc2")
result shouldBe Some(CustomerDetails("AA123456A", "Jim", "Jimson", "1989-09-29"))
}

"a valid uuid (633e0ee7-315b-49e6-baed-d79c3dffe467) is found" in {
val result = SUT.getCachedData("633e0ee7-315b-49e6-baed-d79c3dffe467")
result shouldBe Some(CustomerDetails("BB123456B", "John", "Smith", "1975-05-25"))
}

"a valid uuid (77648d82-309e-484d-a310-d0ffd2997791) is found" in {
val result = SUT.getCachedData("77648d82-309e-484d-a310-d0ffd2997791")
result shouldBe Some(CustomerDetails("CC123456C", "Jane", "Doe", "1969-06-09"))
}

"a valid uuid (79f21755-8cd4-4785-9c10-13253f7a8bb6) is found" in {
val result = SUT.getCachedData("79f21755-8cd4-4785-9c10-13253f7a8bb6")
result shouldBe Some(CustomerDetails("EE123456E", "Joe", "Bloggs", "1982-02-17"))
}

"a valid uuid (2900a7ab-fe20-42ca-98d8-c33f4133cfc2) is found" in {
val result = SUT.getCachedData("2900a7ab-fe20-42ca-98d8-c33f4133cfc2")
result shouldBe Some(CustomerDetails("AB234567B", "Peter", "Armstrong", "1969-01-01"))
}

"a valid uuid (743e0ee7-315b-49e7-baed-d79c3dffe467) is found" in {
val result = SUT.getCachedData("743e0ee7-315b-49e7-baed-d79c3dffe467")
result shouldBe Some(CustomerDetails("BC234567C", "Steven", "Smith", "1947-08-15"))
}

"a valid uuid (88648d82-309e-484e-a310-d0ffd2997791) is found" in {
val result = SUT.getCachedData("88648d82-309e-484e-a310-d0ffd2997791")
result shouldBe Some(CustomerDetails("CD234567D", "Simon", "Handyside", "1984-10-31"))
}

"a valid uuid (88648d82-309e-484d-a310-d0ffd2997792) is found" in {
val result = SUT.getCachedData("88648d82-309e-484d-a310-d0ffd2997792")
result shouldBe Some(CustomerDetails("EF234567F", "Linda", "Marshall", "1966-06-21"))
}

"a valid uuid (3000a7ab-fe20-42ca-98d9-c33f4133cfc2) is found" in {
val result = SUT.getCachedData("3000a7ab-fe20-42ca-98d9-c33f4133cfc2")
result shouldBe Some(CustomerDetails("AC345678C", "Kelly", "Thompslon", "1990-02-15"))
}

"a valid uuid (853e0ee7-315b-49e8-baed-d79c3dffe467) is found" in {
val result = SUT.getCachedData("853e0ee7-315b-49e8-baed-d79c3dffe467")
result shouldBe Some(CustomerDetails("BD345678D", "Simon", "Handyside", "1984-10-31"))
}

"a valid uuid (99648d82-309e-484f-a310-d0ffd2997791) is found" in {
val result = SUT.getCachedData("99648d82-309e-484f-a310-d0ffd2997791")
result shouldBe Some(CustomerDetails("CE345678E", "Zack", "Jackson", "1966-04-04"))
}

"a valid uuid (99648d82-309e-484d-a310-d0ffd2997793) is found" in {
val result = SUT.getCachedData("99648d82-309e-484d-a310-d0ffd2997793")
result shouldBe Some(CustomerDetails("EF234567F", "Linda", "Marshall", "1966-06-21"))
}

"a valid uuid (3100a7ab-fe20-42ca-98d1-c33f4133cfc2) is found" in {
val result = SUT.getCachedData("3100a7ab-fe20-42ca-98d1-c33f4133cfc2")
result shouldBe Some(CustomerDetails("AD456789D", "Oscar", "Smith", "1986-06-14"))
}

"a valid uuid (963e0ee7-315b-49e-baed-d79c3dffe467) is found" in {
val result = SUT.getCachedData("963e0ee7-315b-49e-baed-d79c3dffe467")
result shouldBe Some(CustomerDetails("BE456789E", "Louise", "Oscar", "1966-04-04"))
}

"a valid uuid (11648d82-309e-484g-a310-d0ffd2997791) is found" in {
val result = SUT.getCachedData("11648d82-309e-484g-a310-d0ffd2997791")
result shouldBe Some(CustomerDetails("CF456789F", "Raj", "Patel", "1984-10-31"))
}

"a valid uuid (76648d82-309e-484d-a310-d0ffd2997794) is found" in {
val result = SUT.getCachedData("76648d82-309e-484d-a310-d0ffd2997794")
result shouldBe Some(CustomerDetails("EH456789H", "Mary", "Brown", "1982-02-17"))
}

"a valid uuid (76648d82-309e-484d-a310-d0ffd2997795) is found" in {
val result = SUT.getCachedData("76648d82-309e-484d-a310-d0ffd2997795")
result shouldBe Some(CustomerDetails("AA666888B", "Ramin", "Raj", "1947-08-15"))
}
}

"return an option of none" when {
"an invalid UUID is given" in {
val uuid = "2800a7ab-fe20-42ca-98d7-c33f4133cgw4"

val result = SUT.getCachedData(uuid)

result shouldBe None
}
}
}
}
Loading

0 comments on commit d6b7d75

Please sign in to comment.