diff --git a/app/uk/gov/hmrc/rasapi/connectors/DesConnector.scala b/app/uk/gov/hmrc/rasapi/connectors/DesConnector.scala index d6901af5..671706c5 100644 --- a/app/uk/gov/hmrc/rasapi/connectors/DesConnector.scala +++ b/app/uk/gov/hmrc/rasapi/connectors/DesConnector.scala @@ -31,7 +31,9 @@ trait DesConnector extends ServicesConfig { val httpGet: HttpGet val httpPost: HttpPost val desBaseUrl: String + def getResidencyStatusUrl(nino: String): String + val edhUrl: String def getResidencyStatus(nino: Nino)(implicit hc: HeaderCarrier): Future[HttpResponse] = { @@ -48,21 +50,21 @@ trait DesConnector extends ServicesConfig { residencyStatus.nextYearForecastResidencyStatus))(implicitly[Writes[EDHAudit]], implicitly[HttpReads[HttpResponse]], updateHeaderCarrier(hc)) } -// private val httpReads: HttpReads[HttpResponse] = new HttpReads[HttpResponse] { -// override def read(method: String, url: String, response: HttpResponse) = response -// } private def updateHeaderCarrier(headerCarrier: HeaderCarrier) = headerCarrier.copy(extraHeaders = Seq("Environment" -> AppContext.desUrlHeaderEnv), authorization = Some(Authorization(s"Bearer ${AppContext.desAuthToken}"))) } -object DesConnector extends DesConnector{ +object DesConnector extends DesConnector { // $COVERAGE-OFF$Trivial and never going to be called by a test that uses it's own object implementation override val httpGet: HttpGet = WSHttp override val httpPost: HttpPost = WSHttp override val desBaseUrl = baseUrl("des") - override def getResidencyStatusUrl(nino: String) = String.format(AppContext.residencyStatusUrl, nino) //"/ras-stubs/get-residency-status" + + override def getResidencyStatusUrl(nino: String) = String.format(AppContext.residencyStatusUrl, nino) + + //"/ras-stubs/get-residency-status" override val edhUrl: String = desBaseUrl + AppContext.edhUrl // $COVERAGE-ON$ } diff --git a/app/uk/gov/hmrc/rasapi/services/HttpResponseHandlerService.scala b/app/uk/gov/hmrc/rasapi/services/HttpResponseHandlerService.scala index d4ea6ae0..9a7a512f 100644 --- a/app/uk/gov/hmrc/rasapi/services/HttpResponseHandlerService.scala +++ b/app/uk/gov/hmrc/rasapi/services/HttpResponseHandlerService.scala @@ -34,14 +34,14 @@ trait HttpResponseHandlerService { val desConnector: DesConnector val auditService: AuditService - def handleResidencyStatusResponse(nino: Nino, userId: String)(implicit request: Request[AnyContent], hc: HeaderCarrier) : Future[Either[ResidencyStatus, String]] = { + def handleResidencyStatusResponse(nino: Nino, userId: String)(implicit request: Request[AnyContent], hc: HeaderCarrier): Future[Either[ResidencyStatus, String]] = { desConnector.getResidencyStatus(nino).map { response => Try(response.json.validate[ResidencyStatusSuccess]) match { case Success(JsSuccess(payload, _)) => val resStatus = transformResidencyStatusValues(ResidencyStatus(currentYearResidencyStatus = payload.currentYearResidencyStatus, nextYearForecastResidencyStatus = payload.nextYearResidencyStatus)) - desConnector.sendDataToEDH(userId, nino.nino, resStatus).map{ httpResponse => + desConnector.sendDataToEDH(userId, nino.nino, resStatus).map { httpResponse => auditEDHResponse(userId = userId, nino = nino.nino, auditSuccess = true) } recover { case _ => @@ -66,19 +66,16 @@ trait HttpResponseHandlerService { } ResidencyStatus(transformResidencyStatusValue(residencyStatus.currentYearResidencyStatus), - transformResidencyStatusValue(residencyStatus.nextYearForecastResidencyStatus)) + transformResidencyStatusValue(residencyStatus.nextYearForecastResidencyStatus)) } -// -// private def is2xx(statusCode: Int): Boolean = { -// statusCode >= 200 && statusCode < 300 -// } + private def auditEDHResponse(userId: String, nino: String, auditSuccess: Boolean) (implicit request: Request[AnyContent], hc: HeaderCarrier): Unit = { val auditDataMap = Map("userId" -> userId, - "nino" -> nino, - "edhAuditSuccess" -> auditSuccess.toString) + "nino" -> nino, + "edhAuditSuccess" -> auditSuccess.toString) auditService.audit(auditType = "ReliefAtSourceAudit", path = request.path,