diff --git a/app/connectors/SubmissionsConnector.scala b/app/connectors/SubmissionsConnector.scala index eed5236..902fc11 100644 --- a/app/connectors/SubmissionsConnector.scala +++ b/app/connectors/SubmissionsConnector.scala @@ -17,7 +17,7 @@ package connectors import config.Service -import connectors.SubmissionsConnector.SubmissionsExistFailure +import connectors.SubmissionsConnector.{AssumedReportsExistFailure, SubmissionsExistFailure} import models.submissions.ViewSubmissionsRequest import play.api.Configuration import play.api.http.Status.{NOT_FOUND, OK} @@ -34,11 +34,11 @@ class SubmissionsConnector @Inject()(configuration: Configuration, private val digitalPlatformReporting: Service = configuration.get[Service]("microservice.services.digital-platform-reporting") - def submissionsExist(assumedReporting: Boolean)(implicit hc: HeaderCarrier): Future[Boolean] = { + def submissionsExist(implicit hc: HeaderCarrier): Future[Boolean] = { - val request = ViewSubmissionsRequest(assumedReporting) + val request = ViewSubmissionsRequest(assumedReporting = false) - httpClient.post(url"$digitalPlatformReporting/digital-platform-reporting/submission/list") + httpClient.post(url"$digitalPlatformReporting/digital-platform-reporting/submission/delivered/list") .withBody(Json.toJson(request)) .execute[HttpResponse] .flatMap { response => @@ -49,6 +49,17 @@ class SubmissionsConnector @Inject()(configuration: Configuration, } } } + + def assumedReportsExist(implicit hc: HeaderCarrier): Future[Boolean] = + httpClient.get(url"$digitalPlatformReporting/digital-platform-reporting/submission/assumed") + .execute[HttpResponse] + .flatMap { response => + response.status match { + case OK => Future.successful(true) + case NOT_FOUND => Future.successful(false) + case status => Future.failed(AssumedReportsExistFailure(status)) + } + } } object SubmissionsConnector { @@ -56,4 +67,8 @@ object SubmissionsConnector { final case class SubmissionsExistFailure(status: Int) extends Throwable { override def getMessage: String = s"Call to check if submissions exist failed with status: $status" } + + final case class AssumedReportsExistFailure(status: Int) extends Throwable { + override def getMessage: String = s"Call to check if manual assumed reports exist failed with status: $status" + } } \ No newline at end of file diff --git a/app/controllers/IndexController.scala b/app/controllers/IndexController.scala index 1c624ad..019b96f 100644 --- a/app/controllers/IndexController.scala +++ b/app/controllers/IndexController.scala @@ -78,7 +78,7 @@ class IndexController @Inject()( private def getFileSubmissionsCard(operators: Seq[PlatformOperator], appConfig: FrontendAppConfig) (implicit request: Request[_]): Future[FileSubmissionsCardViewModel] = { if (appConfig.fileSubmissionsEnabled) { - submissionsConnector.submissionsExist(assumedReporting = false).map { response => + submissionsConnector.submissionsExist.map { response => FileSubmissionsCardViewModel(response, operators, appConfig) } } else { @@ -89,7 +89,7 @@ class IndexController @Inject()( private def getAssumedReportingCard(operators: Seq[PlatformOperator], appConfig: FrontendAppConfig) (implicit request: Request[_]): Future[AssumedReportingCardViewModel] = { if (appConfig.assumedReportingEnabled) { - submissionsConnector.submissionsExist(assumedReporting = true).map { response => + submissionsConnector.assumedReportsExist.map { response => AssumedReportingCardViewModel(response, operators, appConfig) } } else { diff --git a/it/test/connectors/SubmissionsConnectorSpec.scala b/it/test/connectors/SubmissionsConnectorSpec.scala index 3954cc6..4569570 100644 --- a/it/test/connectors/SubmissionsConnectorSpec.scala +++ b/it/test/connectors/SubmissionsConnectorSpec.scala @@ -17,7 +17,7 @@ package connectors import com.github.tomakehurst.wiremock.client.WireMock._ -import connectors.SubmissionsConnector.SubmissionsExistFailure +import connectors.SubmissionsConnector.{AssumedReportsExistFailure, SubmissionsExistFailure} import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures} import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.must.Matchers @@ -51,40 +51,82 @@ class SubmissionsConnectorSpec extends AnyFreeSpec "must return true when the server returns OK" in { wireMockServer.stubFor( - post(urlPathEqualTo("/digital-platform-reporting/submission/list")) + post(urlPathEqualTo("/digital-platform-reporting/submission/delivered/list")) .withHeader("Authorization", equalTo("authToken")) .willReturn(ok()) ) - val result = connector.submissionsExist(assumedReporting = true).futureValue + val result = connector.submissionsExist.futureValue result mustEqual true } "must return false when the server returns NOT_FOUND" in { wireMockServer.stubFor( - post(urlPathEqualTo("/digital-platform-reporting/submission/list")) + post(urlPathEqualTo("/digital-platform-reporting/submission/delivered/list")) .withHeader("Authorization", equalTo("authToken")) .willReturn(notFound()) ) - val result = connector.submissionsExist(assumedReporting = true).futureValue + val result = connector.submissionsExist.futureValue result mustEqual false } "must return a failed future when the server returns an error" in { wireMockServer.stubFor( - post(urlPathEqualTo("/digital-platform-reporting/submission/list")) + post(urlPathEqualTo("/digital-platform-reporting/submission/delivered/list")) .withHeader("Authorization", equalTo("authToken")) .willReturn(serverError()) ) - val result = connector.submissionsExist(assumedReporting = true).failed.futureValue + val result = connector.submissionsExist.failed.futureValue result mustBe a[SubmissionsExistFailure] val failure = result.asInstanceOf[SubmissionsExistFailure] failure.status mustEqual INTERNAL_SERVER_ERROR } } + + "assumedReportsExist" - { + + "must return true when the server returns OK" in { + + wireMockServer.stubFor( + get(urlPathEqualTo("/digital-platform-reporting/submission/assumed")) + .withHeader("Authorization", equalTo("authToken")) + .willReturn(ok()) + ) + + val result = connector.assumedReportsExist.futureValue + result mustEqual true + } + + "must return false when the server returns NOT_FOUND" in { + + wireMockServer.stubFor( + get(urlPathEqualTo("/digital-platform-reporting/submission/assumed")) + .withHeader("Authorization", equalTo("authToken")) + .willReturn(notFound()) + ) + + val result = connector.assumedReportsExist.futureValue + result mustEqual false + } + + "must return a failed future when the server returns an error" in { + + wireMockServer.stubFor( + get(urlPathEqualTo("/digital-platform-reporting/submission/assumed")) + .withHeader("Authorization", equalTo("authToken")) + .willReturn(serverError()) + ) + + val result = connector.assumedReportsExist.failed.futureValue + result mustBe a[AssumedReportsExistFailure] + + val failure = result.asInstanceOf[AssumedReportsExistFailure] + failure.status mustEqual INTERNAL_SERVER_ERROR + } + } } diff --git a/test/controllers/IndexControllerSpec.scala b/test/controllers/IndexControllerSpec.scala index 42c56ff..6c91cbe 100644 --- a/test/controllers/IndexControllerSpec.scala +++ b/test/controllers/IndexControllerSpec.scala @@ -115,7 +115,7 @@ class IndexControllerSpec extends SpecBase with MockitoSugar with BeforeAndAfter "must display the platform operator, reporting notification and file submission cards" in { when(mockPlatformOperatorConnector.viewPlatformOperators(any())) thenReturn Future.successful(ViewPlatformOperatorsResponse(Nil)) - when(mockSubmissionsConnector.submissionsExist(any())(any())) thenReturn Future.successful(false) + when(mockSubmissionsConnector.submissionsExist(any())) thenReturn Future.successful(false) val application = applicationBuilder(userAnswers = None) @@ -146,8 +146,8 @@ class IndexControllerSpec extends SpecBase with MockitoSugar with BeforeAndAfter contentAsString(result) mustEqual view(viewModel)(request, messages(application)).toString - verify(mockSubmissionsConnector, times(1)).submissionsExist(eqTo(false))(any()) - verify(mockSubmissionsConnector, never()).submissionsExist(eqTo(true))(any()) + verify(mockSubmissionsConnector, times(1)).submissionsExist(any()) + verify(mockSubmissionsConnector, never()).assumedReportsExist(any()) } } } @@ -157,7 +157,7 @@ class IndexControllerSpec extends SpecBase with MockitoSugar with BeforeAndAfter "must display the platform operator, reporting notification and assumed reporting cards" in { when(mockPlatformOperatorConnector.viewPlatformOperators(any())) thenReturn Future.successful(ViewPlatformOperatorsResponse(Nil)) - when(mockSubmissionsConnector.submissionsExist(any())(any())) thenReturn Future.successful(false) + when(mockSubmissionsConnector.assumedReportsExist(any())) thenReturn Future.successful(false) val application = applicationBuilder(userAnswers = None) @@ -188,8 +188,8 @@ class IndexControllerSpec extends SpecBase with MockitoSugar with BeforeAndAfter contentAsString(result) mustEqual view(viewModel)(request, messages(application)).toString - verify(mockSubmissionsConnector, times(1)).submissionsExist(eqTo(true))(any()) - verify(mockSubmissionsConnector, never()).submissionsExist(eqTo(false))(any()) + verify(mockSubmissionsConnector, times(1)).assumedReportsExist(any()) + verify(mockSubmissionsConnector, never()).submissionsExist(any()) } } } @@ -199,7 +199,8 @@ class IndexControllerSpec extends SpecBase with MockitoSugar with BeforeAndAfter "must display the platform operator, reporting notification, file submission and assumed reporting cards" in { when(mockPlatformOperatorConnector.viewPlatformOperators(any())) thenReturn Future.successful(ViewPlatformOperatorsResponse(Nil)) - when(mockSubmissionsConnector.submissionsExist(any())(any())) thenReturn Future.successful(false) + when(mockSubmissionsConnector.submissionsExist(any())) thenReturn Future.successful(false) + when(mockSubmissionsConnector.assumedReportsExist(any())) thenReturn Future.successful(false) val application = applicationBuilder(userAnswers = None) @@ -230,8 +231,8 @@ class IndexControllerSpec extends SpecBase with MockitoSugar with BeforeAndAfter contentAsString(result) mustEqual view(viewModel)(request, messages(application)).toString - verify(mockSubmissionsConnector, times(1)).submissionsExist(eqTo(true))(any()) - verify(mockSubmissionsConnector, times(1)).submissionsExist(eqTo(false))(any()) + verify(mockSubmissionsConnector, times(1)).submissionsExist(any()) + verify(mockSubmissionsConnector, times(1)).assumedReportsExist(any()) } } }