diff --git a/app/uk/gov/hmrc/vatapi/connectors/BaseConnector.scala b/app/uk/gov/hmrc/vatapi/connectors/BaseConnector.scala index c61bbe7d..978b59bb 100644 --- a/app/uk/gov/hmrc/vatapi/connectors/BaseConnector.scala +++ b/app/uk/gov/hmrc/vatapi/connectors/BaseConnector.scala @@ -37,9 +37,9 @@ trait BaseConnector { private def withDesHeaders: HeaderCarrier => HeaderCarrier = { hc => val newHc: HeaderCarrier = hc - .copy(authorization = Some(Authorization(s"Bearer ${AppContext.desToken}"))) + .copy(authorization = Some(Authorization(s"Bearer ${appContext.desToken}"))) .withExtraHeaders( - "Environment" -> AppContext.desEnv, + "Environment" -> appContext.desEnv, "Accept" -> "application/json", "Originator-Id" -> "DA_SDI" ) diff --git a/app/uk/gov/hmrc/vatapi/connectors/ObligationsConnector.scala b/app/uk/gov/hmrc/vatapi/connectors/ObligationsConnector.scala index d872a872..6cc3c840 100644 --- a/app/uk/gov/hmrc/vatapi/connectors/ObligationsConnector.scala +++ b/app/uk/gov/hmrc/vatapi/connectors/ObligationsConnector.scala @@ -42,6 +42,7 @@ trait ObligationsConnector extends BaseConnector { logger.debug(s"[ObligationsConnector][get] Retrieve obligations for VRN $vrn with the given query parameters.") val queryString = s"from=${queryParams.from}&to=${queryParams.to}&status=${queryParams.status}" + httpGet[ObligationsResponse](baseUrl + s"/enterprise/obligation-data/vrn/$vrn/VATC?$queryString", ObligationsResponse) } } diff --git a/project/MicroService.scala b/project/MicroService.scala index 1f6db118..5c482beb 100644 --- a/project/MicroService.scala +++ b/project/MicroService.scala @@ -25,7 +25,7 @@ trait MicroService { Seq( ScoverageKeys.coverageExcludedPackages := ";.*(Reverse|BuildInfo|Routes).*", ScoverageKeys.coverageMinimum := 80, - ScoverageKeys.coverageFailOnMinimum := false, + ScoverageKeys.coverageFailOnMinimum := true, ScoverageKeys.coverageHighlighting := true ) } diff --git a/test/uk/gov/hmrc/vatapi/connectors/ObligationsConnectorSpec.scala b/test/uk/gov/hmrc/vatapi/connectors/ObligationsConnectorSpec.scala index db2c6fb9..a3c8b371 100644 --- a/test/uk/gov/hmrc/vatapi/connectors/ObligationsConnectorSpec.scala +++ b/test/uk/gov/hmrc/vatapi/connectors/ObligationsConnectorSpec.scala @@ -18,6 +18,7 @@ package uk.gov.hmrc.vatapi.connectors import org.scalatestplus.play.OneAppPerSuite import play.api.libs.json.JsValue +import play.mvc.Http.{HeaderNames, MimeTypes} import uk.gov.hmrc.domain.Vrn import uk.gov.hmrc.http.{HeaderCarrier, HttpResponse} import uk.gov.hmrc.vatapi.UnitSpec @@ -40,8 +41,12 @@ class ObligationsConnectorSpec extends UnitSpec with OneAppPerSuite override val appContext = mockAppContext } MockAppContext.desUrl returns desBaseUrl + MockAppContext.desToken returns desToken + MockAppContext.desEnv returns desEnvironment } + lazy val desToken = "test-token" + lazy val desEnvironment = "test-env" lazy val desBaseUrl = "des-base-url" val vrn: Vrn = generateVrn @@ -50,13 +55,26 @@ class ObligationsConnectorSpec extends UnitSpec with OneAppPerSuite val desUrl = s"$desBaseUrl/enterprise/obligation-data/vrn/$vrn/VATC?$queryString" val desObligationsJson: JsValue = Jsons.Obligations.desResponse(vrn) + val desHttpResponse = HttpResponse(200, Some(desObligationsJson)) + implicit val hc = HeaderCarrier() "get" should { - "returns an ObligationsResponse" when { - "DES returns a 200 response" in new Setup { - val desHttpResponse = HttpResponse(200, Some(desObligationsJson)) + "have the DES headers in the request" in new Setup { + MockHttp.GET[HttpResponse](desUrl) + .returns(Future.successful(desHttpResponse)) + + await(testObligationsConnector.get(vrn, queryParams)) + val headers = MockHttp.fetchHeaderCarrier.headers.toMap + headers("Accept") shouldBe MimeTypes.JSON + headers("Environment") shouldBe desEnvironment + headers("Authorization") shouldBe s"Bearer $desToken" + headers("Originator-Id") shouldBe "DA_SDI" + } + + "return an ObligationsResponse" when { + "DES returns a 200 response" in new Setup { MockHttp.GET[HttpResponse](desUrl) .returns(Future.successful(desHttpResponse)) diff --git a/test/uk/gov/hmrc/vatapi/mocks/MockHttp.scala b/test/uk/gov/hmrc/vatapi/mocks/MockHttp.scala index 6938b000..001307cd 100644 --- a/test/uk/gov/hmrc/vatapi/mocks/MockHttp.scala +++ b/test/uk/gov/hmrc/vatapi/mocks/MockHttp.scala @@ -16,7 +16,7 @@ package uk.gov.hmrc.vatapi.mocks -import org.mockito.Matchers +import org.mockito.{ArgumentCaptor, Matchers} import org.mockito.stubbing.OngoingStubbing import org.scalatest.Suite import play.api.libs.json.Writes @@ -35,10 +35,14 @@ trait MockHttp extends Mock { _: Suite => reset(mockHttp) } - object MockHttp{ + object MockHttp { + private val headerCarrierCaptor = ArgumentCaptor.forClass(classOf[HeaderCarrier]) + def GET[T](url: String): OngoingStubbing[Future[T]] = { - when(mockHttp.GET[T](eqTo(url))(any(), any(), any())) + when(mockHttp.GET[T](eqTo(url))(any(), headerCarrierCaptor.capture(), any())) } + + def fetchHeaderCarrier: HeaderCarrier = headerCarrierCaptor.getValue } def setupMockHttpGet(url: String)(response: HttpResponse): OngoingStubbing[Future[HttpResponse]] = diff --git a/test/uk/gov/hmrc/vatapi/mocks/config/MockAppContext.scala b/test/uk/gov/hmrc/vatapi/mocks/config/MockAppContext.scala index 0826a96e..d8b2c651 100644 --- a/test/uk/gov/hmrc/vatapi/mocks/config/MockAppContext.scala +++ b/test/uk/gov/hmrc/vatapi/mocks/config/MockAppContext.scala @@ -26,6 +26,8 @@ trait MockAppContext extends Mock { _: Suite => object MockAppContext { def desUrl = when(mockAppContext.desUrl) + def desToken = when(mockAppContext.desToken) + def desEnv = when(mockAppContext.desEnv) } override protected def beforeEach(): Unit = { diff --git a/test/uk/gov/hmrc/vatapi/services/NRSServiceSpec.scala b/test/uk/gov/hmrc/vatapi/services/NRSServiceSpec.scala index 40e2b290..6aaecb8a 100644 --- a/test/uk/gov/hmrc/vatapi/services/NRSServiceSpec.scala +++ b/test/uk/gov/hmrc/vatapi/services/NRSServiceSpec.scala @@ -15,6 +15,7 @@ */ package uk.gov.hmrc.vatapi.services + import org.joda.time.DateTime import org.scalatest.concurrent.ScalaFutures import org.scalatest.mockito.MockitoSugar