diff --git a/app/uk/gov/hmrc/vatapi/models/FinancialDataQueryParams.scala b/app/uk/gov/hmrc/vatapi/models/FinancialDataQueryParams.scala index 6f243112..e71de5c1 100644 --- a/app/uk/gov/hmrc/vatapi/models/FinancialDataQueryParams.scala +++ b/app/uk/gov/hmrc/vatapi/models/FinancialDataQueryParams.scala @@ -33,6 +33,8 @@ object FinancialDataQueryParams { def from(fromOpt: OptEither[String], toOpt: OptEither[String]): Either[String, FinancialDataQueryParams] = { + Logger.debug(s"[FinancialDataQueryParams][from] FromDate:$fromOpt toDate:$toOpt minDate: $minDate") + val from = checkMinFromDate(dateQueryParam(fromOpt, "DATE_FROM_INVALID")) val to = checkFutureToDate(dateQueryParam(toOpt, "DATE_TO_INVALID")) @@ -63,6 +65,8 @@ object FinancialDataQueryParams { } def validDateRange(fromOpt: OptEither[LocalDate], toOpt: OptEither[LocalDate]): Option[Either[SourceId, Unit] with Product with Serializable] = { + + for { fromVal <- fromOpt if fromVal.isRight diff --git a/test/uk/gov/hmrc/vatapi/models/FinancialDataQueryParamsSpec.scala b/test/uk/gov/hmrc/vatapi/models/FinancialDataQueryParamsSpec.scala index efe1f874..554684e6 100644 --- a/test/uk/gov/hmrc/vatapi/models/FinancialDataQueryParamsSpec.scala +++ b/test/uk/gov/hmrc/vatapi/models/FinancialDataQueryParamsSpec.scala @@ -18,17 +18,17 @@ package uk.gov.hmrc.vatapi.models import org.joda.time.LocalDate import org.scalatest.TestData -import org.scalatestplus.play.OneAppPerTest +import org.scalatestplus.play.guice.GuiceOneAppPerTest import play.api.Application import play.api.inject.guice.GuiceApplicationBuilder import uk.gov.hmrc.vatapi.UnitSpec -class FinancialDataQueryParamsSpec extends UnitSpec with OneAppPerTest { +class FinancialDataQueryParamsSpec extends UnitSpec with GuiceOneAppPerTest { val testTime: LocalDate = LocalDate.now() implicit override def newAppForTest(testData: TestData): Application = - new GuiceApplicationBuilder().configure(Map("Test.mtd-date" -> testTime.minusYears(10).toString)).build() + new GuiceApplicationBuilder().configure(Map(s"Test.mtd-date" -> testTime.minusYears(10).toString)).build() "DateRangeQueryParams" should { @@ -84,8 +84,8 @@ class FinancialDataQueryParamsSpec extends UnitSpec with OneAppPerTest { response.left.get shouldBe "DATE_TO_INVALID" } - "return error when from date is after to date " in { - val response = FinancialDataQueryParams.from(Some(Right(testTime.minusYears(3).toString)), Some(Right(testTime.minusYears(3).minusDays(1).toString))) + s"return error when from date is after to date" in { + val response = FinancialDataQueryParams.from(Some(Right(testTime.minusYears(1).toString)), Some(Right(testTime.minusYears(1).minusDays(1).toString))) response.isLeft shouldBe true response.left.get shouldBe "DATE_RANGE_INVALID" }