<commit_before>package controllers.disposal_of_vehicle

import mappings.disposal_of_vehicle.VehicleLookup._
import helpers.disposal_of_vehicle.Helper._
import org.mockito.Mockito._
import org.mockito.Matchers._
import models.domain.disposal_of_vehicle._
import services.fakes.FakeResponse
import controllers.disposal_of_vehicle
import helpers.UnitSpec
import services.VehicleLookupServiceImpl
import services.vehicle_lookup.VehicleLookupWebService
import scala.concurrent.{ExecutionContext, Future}
import play.api.libs.json.Json
import ExecutionContext.Implicits.global

class VehicleLookupFormSpec extends UnitSpec {

  "Vehicle lookup form" should {
    val vehicleLookup = {
      val ws: VehicleLookupWebService = mock[VehicleLookupWebService]
      when(ws.callVehicleLookupService(any[VehicleDetailsRequest])).thenReturn(Future {
        val vehicleDetailsResponse =
          VehicleDetailsResponse(true,
            message = "Fake Web Lookup Service - Good response",
            vehicleDetailsDto = VehicleDetailsDto(registrationNumber = "PJ056YY",
              vehicleMake = "Alfa Romeo",
              vehicleModel = "Alfasud ti",
              keeperName = "Keeper Name",
              keeperAddress = AddressDto(uprn = Some(10123456789L), address = Seq("line1", "line2", "line2"))))
        val responseAsJson = Json.toJson(vehicleDetailsResponse)

        new FakeResponse(status = 200, fakeJson = Some(responseAsJson)) // Any call to a webservice will always return this successful response.
      })

      val vehicleLookupServiceImpl = new VehicleLookupServiceImpl(ws)

      new disposal_of_vehicle.VehicleLookup(vehicleLookupServiceImpl)
    }

    def formWithValidDefaults(referenceNumber: String = referenceNumberValid,
                              registrationNumber: String = registrationNumberValid,
                              consent: String = consentValid) = {
      vehicleLookup.vehicleLookupForm.bind(
        Map(
          referenceNumberId -> referenceNumber,
          registrationNumberId -> registrationNumber,
          consentId -> consent
        )
      )
    }

    /** *********************
      * referenceNumber tests
      */
    "reject if referenceNumber is blank" in {
      formWithValidDefaults(referenceNumber = "").errors should have length 3
    }

    "reject if referenceNumber is less than min length" in {
      formWithValidDefaults(referenceNumber = "1234567891").errors should have length 1
    }

    "reject if referenceNumber is greater than max length" in {
      formWithValidDefaults(referenceNumber = "123456789101").errors should have length 1
    }

    "reject if referenceNumber contains letters" in {
      formWithValidDefaults(referenceNumber = "qwertyuiopl").errors should have length 1
    }

    "reject if referenceNumber contains special characters" in {
      formWithValidDefaults(referenceNumber = "£££££££££££").errors should have length 1
    }

    "accept if referenceNumber is valid" in {
      formWithValidDefaults(registrationNumber = registrationNumberValid).get.referenceNumber should equal(referenceNumberValid)
    }

    /** ************************
      * registrationNumber tests
      */

    "reject if registrationNumber is empty" in {
      formWithValidDefaults(registrationNumber = "").errors should have length 2
    }

    "reject if registrationNumber is less than min length" in {
      formWithValidDefaults(registrationNumber = "a").errors should have length 2
    }

    "reject if registrationNumber is more than max length" in {
      formWithValidDefaults(registrationNumber = "AB53WERT").errors should have length 1
    }

    "reject if registrationNumber contains special characters" in {
      formWithValidDefaults(registrationNumber = "ab53ab%").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AA" in {
      formWithValidDefaults(registrationNumber = "AA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 11" in {
      formWithValidDefaults(registrationNumber = "11").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AAA" in {
      formWithValidDefaults(registrationNumber = "AAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format A1A" in {
      formWithValidDefaults(registrationNumber = "A1A").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AAAA" in {
      formWithValidDefaults(registrationNumber = "AAAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 1111" in {
      formWithValidDefaults(registrationNumber = "1111").errors should have length 1
    }


    "reject if registrationNumber is in an incorrect format AAAAA" in {
      formWithValidDefaults(registrationNumber = "AAAAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 1AAAA" in {
      formWithValidDefaults(registrationNumber = "1AAAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 11111" in {
      formWithValidDefaults(registrationNumber = "11111").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format A99999" in {
      formWithValidDefaults(registrationNumber = "A99999").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AAAA99" in {
      formWithValidDefaults(registrationNumber = "AAAA99").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AAAAA9" in {
      formWithValidDefaults(registrationNumber = "AAAAA9").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format " in {
      formWithValidDefaults(registrationNumber = "AAAAAAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 1AAAAA" in {
      formWithValidDefaults(registrationNumber = "1AAAAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 11AAAA" in {
      formWithValidDefaults(registrationNumber = "11AAAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 11111A" in {
      formWithValidDefaults(registrationNumber = "11111A").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 111111" in {
      formWithValidDefaults(registrationNumber = "111111").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AA999999" in {<commit_msg>extra max legnth test added to VehicleLookupFormSpec which was failing in microservice. Regex picks this up in front end<commit_after>package controllers.disposal_of_vehicle

import mappings.disposal_of_vehicle.VehicleLookup._
import helpers.disposal_of_vehicle.Helper._
import org.mockito.Mockito._
import org.mockito.Matchers._
import models.domain.disposal_of_vehicle._
import services.fakes.FakeResponse
import controllers.disposal_of_vehicle
import helpers.UnitSpec
import services.VehicleLookupServiceImpl
import services.vehicle_lookup.VehicleLookupWebService
import scala.concurrent.{ExecutionContext, Future}
import play.api.libs.json.Json
import ExecutionContext.Implicits.global

class VehicleLookupFormSpec extends UnitSpec {

  "Vehicle lookup form" should {
    val vehicleLookup = {
      val ws: VehicleLookupWebService = mock[VehicleLookupWebService]
      when(ws.callVehicleLookupService(any[VehicleDetailsRequest])).thenReturn(Future {
        val vehicleDetailsResponse =
          VehicleDetailsResponse(true,
            message = "Fake Web Lookup Service - Good response",
            vehicleDetailsDto = VehicleDetailsDto(registrationNumber = "PJ056YY",
              vehicleMake = "Alfa Romeo",
              vehicleModel = "Alfasud ti",
              keeperName = "<NAME>",
              keeperAddress = AddressDto(uprn = Some(10123456789L), address = Seq("line1", "line2", "line2"))))
        val responseAsJson = Json.toJson(vehicleDetailsResponse)

        new FakeResponse(status = 200, fakeJson = Some(responseAsJson)) // Any call to a webservice will always return this successful response.
      })

      val vehicleLookupServiceImpl = new VehicleLookupServiceImpl(ws)

      new disposal_of_vehicle.VehicleLookup(vehicleLookupServiceImpl)
    }

    def formWithValidDefaults(referenceNumber: String = referenceNumberValid,
                              registrationNumber: String = registrationNumberValid,
                              consent: String = consentValid) = {
      vehicleLookup.vehicleLookupForm.bind(
        Map(
          referenceNumberId -> referenceNumber,
          registrationNumberId -> registrationNumber,
          consentId -> consent
        )
      )
    }

    /** *********************
      * referenceNumber tests
      */
    "reject if referenceNumber is blank" in {
      formWithValidDefaults(referenceNumber = "").errors should have length 3
    }

    "reject if referenceNumber is less than min length" in {
      formWithValidDefaults(referenceNumber = "1234567891").errors should have length 1
    }

    "reject if referenceNumber is greater than max length" in {
      formWithValidDefaults(referenceNumber = "123456789101").errors should have length 1
    }

    "reject if referenceNumber contains letters" in {
      formWithValidDefaults(referenceNumber = "qwertyuiopl").errors should have length 1
    }

    "reject if referenceNumber contains special characters" in {
      formWithValidDefaults(referenceNumber = "£££££££££££").errors should have length 1
    }

    "accept if referenceNumber is valid" in {
      formWithValidDefaults(registrationNumber = registrationNumberValid).get.referenceNumber should equal(referenceNumberValid)
    }

    /** ************************
      * registrationNumber tests
      */

    "reject if registrationNumber is empty" in {
      formWithValidDefaults(registrationNumber = "").errors should have length 2
    }

    "reject if registrationNumber is less than min length" in {
      formWithValidDefaults(registrationNumber = "a").errors should have length 2
    }

    "reject if registrationNumber is more than max length" in {
      formWithValidDefaults(registrationNumber = "AB53WERT").errors should have length 1
    }


    "reject if registrationNumber is more than max length 2" in {
      formWithValidDefaults(registrationNumber = "PJ056YYY").errors should have length 1
    }


    "reject if registrationNumber contains special characters" in {
      formWithValidDefaults(registrationNumber = "ab53ab%").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AA" in {
      formWithValidDefaults(registrationNumber = "AA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 11" in {
      formWithValidDefaults(registrationNumber = "11").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AAA" in {
      formWithValidDefaults(registrationNumber = "AAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format A1A" in {
      formWithValidDefaults(registrationNumber = "A1A").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AAAA" in {
      formWithValidDefaults(registrationNumber = "AAAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 1111" in {
      formWithValidDefaults(registrationNumber = "1111").errors should have length 1
    }


    "reject if registrationNumber is in an incorrect format AAAAA" in {
      formWithValidDefaults(registrationNumber = "AAAAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 1AAAA" in {
      formWithValidDefaults(registrationNumber = "1AAAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 11111" in {
      formWithValidDefaults(registrationNumber = "11111").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format A99999" in {
      formWithValidDefaults(registrationNumber = "A99999").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AAAA99" in {
      formWithValidDefaults(registrationNumber = "AAAA99").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AAAAA9" in {
      formWithValidDefaults(registrationNumber = "AAAAA9").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AAAAAAA" in {
      formWithValidDefaults(registrationNumber = "AAAAAAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 1AAAAA" in {
      formWithValidDefaults(registrationNumber = "1AAAAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 11AAAA" in {
      formWithValidDefaults(registrationNumber = "11AAAA").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 11111A" in {
      formWithValidDefaults(registrationNumber = "11111A").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format 111111" in {
      formWithValidDefaults(registrationNumber = "111111").errors should have length 1
    }

    "reject if registrationNumber is in an incorrect format AA999999" in {
{'fraction_non_alphanumeric': 0.07362098014797451, 'fraction_numerical': 0.022049666691084904, 'mean_word_length': 3.5720026791694575, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, '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': '3955888', 'n_tokens_mistral': 3746, 'n_tokens_neox': 3326, 'n_words': 1100}