<commit_before>package controllers

import helpers.UnitSpec

final class ConfirmBusinessUnitSpec extends UnitSpec {

  //  "present" should {
  //
  //    "display the page when required cookies are cached" in new WithApplication {
  //      whenReady(present, timeout) { r =>
  //        r.header.status should equal(OK)
  //      }
  //    }
  //
  //    "redirect to VehicleLookup when required cookies do not exist" in new WithApplication {
  //      val request = FakeRequest()
  //      val result = confirmBusiness.present(request)
  //      whenReady(result) { r =>
  //        r.header.headers.get(LOCATION) should equal(Some(VehicleLookupPage.address))
  //      }
  //    }
  //
  //    "display a summary of previously entered user data" in new WithApplication {
  //      val content = contentAsString(present)
  //      content should include(BusinessAddressLine1Valid)
  //      content should include(BusinessAddressLine2Valid)
  //      content should include(BusinessAddressPostTownValid)
  //      content should include(RegistrationNumberValid)
  //      content should include(VehicleMakeValid.get)
  //      content should include(VehicleModelValid.get)
  //    }
  //  }
  //
  //  "submit" should {
  //
  //    "write StoreBusinessDetails cookie when user type is Business and consent is true" in new WithApplication {
  //      val mockAuditService = mock[AuditService]
  //
  //      val injector = testInjector(
  //        new TestAuditService(mockAuditService),
  //        new TestDateService)
  //
  //      val confirmBusiness = injector.getInstance(classOf[ConfirmBusiness])
  //      val dateService = injector.getInstance(classOf[DateService])
  //
  //      val data = Seq(("transactionId", "ABC123123123123"),
  //        ("timestamp", dateService.dateTimeISOChronology),
  //        ("replacementVrm", "SA11AA"),
  //        ("currentVrm", "AB12AWR"),
  //        ("make", "Alfa Romeo"),
  //        ("model", "Alfasud ti"),
  //        ("keeperName","<NAME> JONES"),
  //        ("keeperAddress", "1 HIGH STREET, SKEWEN, POSTTOWN STUB, SA11AA"),
  //        ("businessName", "example trader contact"),
  //        ("businessAddress", "example trader name, business line1 stub, business line2 stub, business postTown stub, QQ99QQ"),
  //        ("businessEmail", "<EMAIL>"))
  //      val auditMessage = new AuditMessage(AuditMessage.ConfirmBusinessToConfirm, AuditMessage.PersonalisedRegServiceType, data: _*)
  //      val request = buildRequest(storeDetailsConsent = true).
  //        withCookies(
  //          vehicleAndKeeperLookupFormModel(keeperConsent = UserType_Business),
  //          vehicleAndKeeperDetailsModel(),
  //          businessDetailsModel(),
  //          transactionId()
  //        )
  //      val result = confirmBusiness.submit(request)
  //      whenReady(result) { r =>
  //        val cookies = fetchCookiesFromHeaders(r)
  //        cookies.map(_.name) should contain(StoreBusinessDetailsCacheKey)
  //        verify(mockAuditService).send(auditMessage)
  //      }
  //    }
  //
  //    "write StoreBusinessDetails cookie with maxAge 7 days" in new WithApplication {
  //      val expected = 7.days.toSeconds.toInt
  //      val request = buildRequest(storeDetailsConsent = true).
  //        withCookies(
  //          vehicleAndKeeperLookupFormModel(keeperConsent = UserType_Business),
  //          vehicleAndKeeperDetailsModel(),
  //          businessDetailsModel(),
  //          transactionId(),
  //          storeBusinessDetailsConsent()
  //        )
  //      val result = confirmWithCookieFlags.submit(request)
  //      whenReady(result) { r =>
  //        val cookies = fetchCookiesFromHeaders(r)
  //        cookies.map(_.name) should contain (StoreBusinessDetailsCacheKey)
  //        cookies.find(cookie => cookie.name == StoreBusinessDetailsCacheKey).get.maxAge should equal(Some(expected))
  //      }
  //    }
  //
  //    "write StoreBusinessDetails cookie when user type is Business and consent is false" in new WithApplication {
  //      val request = buildRequest(storeDetailsConsent = false).
  //        withCookies(
  //          vehicleAndKeeperLookupFormModel(keeperConsent = UserType_Business),
  //          vehicleAndKeeperDetailsModel(),
  //          businessDetailsModel(),
  //          transactionId()
  //        )
  //      val result = confirmBusiness.submit(request)
  //      whenReady(result) { r =>
  //        val cookies = fetchCookiesFromHeaders(r)
  //        cookies.map(_.name) should contain (StoreBusinessDetailsCacheKey)
  //      }
  //    }
  //  }
  //
  //
  //  "exit" should {
  //
  //    "redirect to mock feedback page" in new WithApplication {
  //      val request = buildRequest(storeDetailsConsent = false).
  //        withCookies(
  //          vehicleAndKeeperLookupFormModel(keeperConsent = UserType_Business),
  //          vehicleAndKeeperDetailsModel(),
  //          businessDetailsModel(),
  //          transactionId()
  //        )
  //      val result = confirmBusiness.exit(request)
  //      whenReady(result) { r =>
  //        r.header.headers.get(LOCATION) should equal(Some(MockFeedbackPage.address))
  //      }
  //    }
  //  }
  //
  //
  //  private def buildRequest(storeDetailsConsent: Boolean = false) = {
  //    FakeRequest().withFormUrlEncodedBody(
  //      StoreDetailsConsentId -> storeDetailsConsent.toString
  //    )
  //  }
  //
  //  private def confirmBusiness = testInjector(new TestAuditService).getInstance(classOf[ConfirmBusiness])
  //
  //  private def present = {
  //    val request = FakeRequest().
  //      withCookies(
  //        vehicleAndKeeperLookupFormModel(keeperConsent = BusinessConsentValid),
  //        vehicleAndKeeperDetailsModel(),
  //        businessDetailsModel()
  //      )
  //    confirmBusiness.present(request)
  //  }
  //
  //  private def confirmWithCookieFlags = {
  //    testInjector(new TestAuditService,
  //      new ScalaModule() {
  //      override def configure(): Unit = {
  //        bind[CookieFlags].to[CookieFlagsassign].asEagerSingleton()
  //      }
  //    }).getInstance(classOf[ConfirmBusiness])
  //  }
}<commit_msg>uncomment and fix another test<commit_after>package controllers


import audit.{AuditMessage, AuditService}
import composition.{TestAuditService, TestDateService, WithApplication}
import helpers.UnitSpec
import helpers.common.CookieHelper._
import helpers.vrm_assign.CookieFactoryForUnitSpecs._
import org.mockito.Mockito._
import pages.vrm_assign.{LeaveFeedbackPage, VehicleLookupPage}
import play.api.test.FakeRequest
import play.api.test.Helpers.{LOCATION, OK, contentAsString, defaultAwaitTimeout}
import uk.gov.dvla.vehicles.presentation.common.services.DateService
import views.vrm_assign.ConfirmBusiness._
import views.vrm_assign.VehicleLookup._
import webserviceclients.fakes.AddressLookupServiceConstants._
import webserviceclients.fakes.VehicleAndKeeperLookupWebServiceConstants._


final class ConfirmBusinessUnitSpec extends UnitSpec {

  "present" should {

    "display the page when required cookies are cached" in new WithApplication {
      whenReady(present, timeout) { r =>
        r.header.status should equal(OK)
      }
    }

    "redirect to VehicleLookup when required cookies do not exist" in new WithApplication {
      val request = FakeRequest()
      val result = confirmBusiness.present(request)
      whenReady(result) { r =>
        r.header.headers.get(LOCATION) should equal(Some(VehicleLookupPage.address))
      }
    }

    "display a summary of previously entered user data" in new WithApplication {
      val content = contentAsString(present)
      content should include(BusinessAddressLine1Valid)
      content should include(BusinessAddressLine2Valid)
      content should include(BusinessAddressPostTownValid)
      content should include(RegistrationNumberValid)
      content should include(VehicleMakeValid.get)
      content should include(VehicleModelValid.get)
    }
  }

  "submit" should {

    "write StoreBusinessDetails cookie when user type is Business and consent is true" in new WithApplication {
      val mockAuditService = mock[AuditService]

      val injector = testInjector(
        new TestAuditService(mockAuditService),
        new TestDateService)

      val confirmBusiness = injector.getInstance(classOf[ConfirmBusiness])
      val dateService = injector.getInstance(classOf[DateService])

      val data = Seq(("transactionId", "ABC123123123123"),
        ("timestamp", dateService.dateTimeISOChronology),
        ("currentVrm", "AB12AWR"),
        ("make", "Alfa Romeo"),
        ("model", "Alfasud ti"),
        ("keeperName", "<NAME>"),
        ("keeperAddress", "1 HIGH STREET, SKEWEN, POSTTOWN STUB, SA11AA"),
        ("businessName", "example trader contact"),
        ("businessAddress", "example trader name, business line1 stub, business line2 stub, business postTown stub, QQ99QQ"),
        ("businessEmail", "<EMAIL>"))
      val auditMessage = new AuditMessage(AuditMessage.ConfirmBusinessToCaptureCertificateDetails, AuditMessage.PersonalisedRegServiceType, data: _*)
      val request = buildRequest(storeDetailsConsent = true).
        withCookies(
          vehicleAndKeeperLookupFormModel(keeperConsent = UserType_Business),
          vehicleAndKeeperDetailsModel(),
          businessDetailsModel(),
          transactionId()
        )
      val result = confirmBusiness.submit(request)
      whenReady(result) { r =>
        val cookies = fetchCookiesFromHeaders(r)
        cookies.map(_.name) should contain(StoreBusinessDetailsCacheKey)
        verify(mockAuditService).send(auditMessage)
      }
    }

    //      "write StoreBusinessDetails cookie with maxAge 7 days" in new WithApplication {
    //        val expected = 7.days.toSeconds.toInt
    //        val request = buildRequest(storeDetailsConsent = true).
    //          withCookies(
    //            vehicleAndKeeperLookupFormModel(keeperConsent = UserType_Business),
    //            vehicleAndKeeperDetailsModel(),
    //            businessDetailsModel(),
    //            transactionId(),
    //            storeBusinessDetailsConsent()
    //          )
    //        val result = confirmWithCookieFlags.submit(request)
    //        whenReady(result) { r =>
    //          val cookies = fetchCookiesFromHeaders(r)
    //          cookies.map(_.name) should contain (StoreBusinessDetailsCacheKey)
    //          cookies.find(cookie => cookie.name == StoreBusinessDetailsCacheKey).get.maxAge should equal(Some(expected))
    //        }
    //      }

    "write StoreBusinessDetails cookie when user type is Business and consent is false" in new WithApplication {
      val request = buildRequest(storeDetailsConsent = false).
        withCookies(
          vehicleAndKeeperLookupFormModel(keeperConsent = UserType_Business),
          vehicleAndKeeperDetailsModel(),
          businessDetailsModel(),
          transactionId()
        )
      val result = confirmBusiness.submit(request)
      whenReady(result) { r =>
        val cookies = fetchCookiesFromHeaders(r)
        cookies.map(_.name) should contain(StoreBusinessDetailsCacheKey)
      }
    }
  }


  "exit" should {

    "redirect to mock feedback page" in new WithApplication {
      val request = buildRequest(storeDetailsConsent = false).
        withCookies(
          vehicleAndKeeperLookupFormModel(keeperConsent = UserType_Business),
          vehicleAndKeeperDetailsModel(),
          businessDetailsModel(),
          transactionId()
        )
      val result = confirmBusiness.exit(request)
      whenReady(result) { r =>
        r.header.headers.get(LOCATION) should equal(Some(LeaveFeedbackPage.address))
      }
    }
  }


  private def buildRequest(storeDetailsConsent: Boolean = false) = {
    FakeRequest().withFormUrlEncodedBody(
      StoreDetailsConsentId -> storeDetailsConsent.toString
    )
  }

  private def confirmBusiness = testInjector(new TestAuditService).getInstance(classOf[ConfirmBusiness])

  private def present = {
    val request = FakeRequest().
      withCookies(
        vehicleAndKeeperLookupFormModel(keeperConsent = BusinessConsentValid),
        vehicleAndKeeperDetailsModel(),
        businessDetailsModel()
      )
    confirmBusiness.present(request)
  }

}
{'fraction_non_alphanumeric': 0.10567849007484542, 'fraction_numerical': 0.004230393752033843, 'mean_word_length': 2.6816412099430966, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5317202', 'n_tokens_mistral': 3494, 'n_tokens_neox': 3349, 'n_words': 689}