<commit_before>package controllers.disposal_of_vehicle

import helpers.UnitSpec
import helpers.disposal_of_vehicle.Helper._
import mappings.disposal_of_vehicle.SetupTradeDetails._
import pages.disposal_of_vehicle._
import play.api.test.Helpers._
import play.api.test.{FakeRequest, WithApplication}
import services.fakes.FakeAddressLookupService._
import play.api.mvc.Cookies
import helpers.disposal_of_vehicle.CookieFactoryForUnitSpecs

class SetUpTradeDetailsUnitSpec extends UnitSpec {
  "present" should {
    "display page" in new WithApplication {
      val request = FakeRequest().withSession()
      val result = setUpTradeDetails().present(request)
      whenReady(result) {
        r => r.header.status should equal(OK)
      }
    }

    "populate fields when cookie exists" in new WithApplication {
      val request = FakeRequest().withSession().
        withCookies(CookieFactoryForUnitSpecs.setupTradeDetails())
      val result = setUpTradeDetails().present(request)
      val content = contentAsString(result)
      content should include(traderBusinessNameValid)
      content should include(postcodeValid)
    }
  }

  "SetUpTradeDetails - Controller" should {
    "redirect to next page when the form is completed successfully" in new WithApplication {
      val request = buildCorrectlyPopulatedRequest()
      val result = setUpTradeDetails().submit(request)
      whenReady(result) {
        r => r.header.headers.get(LOCATION) should equal(Some(BusinessChooseYourAddressPage.address))
      }
    }

    "return a bad request if no details are entered" in new WithApplication {
      val request = buildCorrectlyPopulatedRequest(dealerName = "", dealerPostcode = "")
      val result = setUpTradeDetails().submit(request)<commit_msg>US137 test that when no cookie is present that empty fields are displayed on SetUpTradeDetails<commit_after>package controllers.disposal_of_vehicle

import helpers.UnitSpec
import helpers.disposal_of_vehicle.Helper._
import mappings.disposal_of_vehicle.SetupTradeDetails._
import pages.disposal_of_vehicle._
import play.api.test.Helpers._
import play.api.test.{FakeRequest, WithApplication}
import services.fakes.FakeAddressLookupService._
import play.api.mvc.Cookies
import helpers.disposal_of_vehicle.CookieFactoryForUnitSpecs

class SetUpTradeDetailsUnitSpec extends UnitSpec {
  "present" should {
    "display page" in new WithApplication {
      val request = FakeRequest().withSession()
      val result = setUpTradeDetails().present(request)
      whenReady(result) {
        r => r.header.status should equal(OK)
      }
    }

    "display populated fields when cookie exists" in new WithApplication {
      val request = FakeRequest().withSession().
        withCookies(CookieFactoryForUnitSpecs.setupTradeDetails())
      val result = setUpTradeDetails().present(request)
      val content = contentAsString(result)
      content should include(traderBusinessNameValid)
      content should include(postcodeValid)
    }

    "display empty fields when cookie exists" in new WithApplication {
      val request = FakeRequest().withSession()
      val result = setUpTradeDetails().present(request)
      val content = contentAsString(result)
      content should not include traderBusinessNameValid
      content should not include postcodeValid
    }
  }

  "SetUpTradeDetails - Controller" should {
    "redirect to next page when the form is completed successfully" in new WithApplication {
      val request = buildCorrectlyPopulatedRequest()
      val result = setUpTradeDetails().submit(request)
      whenReady(result) {
        r => r.header.headers.get(LOCATION) should equal(Some(BusinessChooseYourAddressPage.address))
      }
    }

    "return a bad request if no details are entered" in new WithApplication {
      val request = buildCorrectlyPopulatedRequest(dealerName = "", dealerPostcode = "")
      val result = setUpTradeDetails().submit(request)
{'fraction_non_alphanumeric': 0.07756866734486266, 'fraction_numerical': 0.000762970498474059, 'mean_word_length': 4.161417322834645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4503764', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1039, 'n_words': 268}