Skip to content

Commit

Permalink
[test-update] modify mtd date in QueryParam tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkAKelly committed Apr 4, 2018
1 parent 44a71d7 commit 71e0752
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/uk/gov/hmrc/vatapi/models/FinancialDataQueryParams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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"
}
Expand Down

0 comments on commit 71e0752

Please sign in to comment.