<commit_before>/*
 * Copyright 2017 HM Revenue & Customs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package models.aboutthebusiness

import org.joda.time.LocalDate
import org.scalatest.mock.MockitoSugar
import org.scalatestplus.play.PlaySpec
import play.api.libs.json.{JsNull, Json}

class AboutTheBusinessSpec extends PlaySpec with MockitoSugar {

  val previouslyRegistered = PreviouslyRegisteredYes("12345678")

  val regForVAT = VATRegisteredYes("123456789")

  // scalastyle:off
  val  activityStartDate = ActivityStartDate(new LocalDate(1990, 2, 24))

  val  newActivityStartDate = ActivityStartDate(new LocalDate(1990, 2, 24))

  val regForCorpTax = CorporationTaxRegisteredYes("1234567890")

  val contactingYou = ContactingYou(Some("1234567890"), Some("<EMAIL>"))

  val regOfficeOrMainPlaceUK =  RegisteredOfficeUK("38B", "line2", None, None, "AA1 1AA")

  val uKCorrespondenceAddress = UKCorrespondenceAddress("Name",
    "Business Name",
    "address 1",
    "address 2",
    Some("address 3"),
    Some("address 4"),
    "AA11 1AA")

  val completeModel = AboutTheBusiness(
    previouslyRegistered = Some(previouslyRegistered),
    activityStartDate = Some(activityStartDate),
    vatRegistered = Some(regForVAT),
    corporationTaxRegistered = Some(regForCorpTax),
    contactingYou = Some(contactingYou),
    registeredOffice = Some(regOfficeOrMainPlaceUK),
    correspondenceAddress = Some(uKCorrespondenceAddress),
    hasAccepted = true
  )

  val completeJson = Json.obj(
    "previouslyRegistered" -> Json.obj("previouslyRegistered" -> true,
      "prevMLRRegNo" -> "12345678"),
    "activityStartDate" -> Json.obj(
      "startDate" -> "1990-02-24"),
    "vatRegistered" -> Json.obj("registeredForVAT" -> true,
      "vrnNumber" -> "123456789"),
    "corporationTaxRegistered" -> Json.obj("registeredForCorporationTax" -> true,
      "corporationTaxReference" -> "1234567890"),
    "contactingYou" -> Json.obj(
      "phoneNumber" -> "1234567890",
      "email" -> "<EMAIL>"),
    "registeredOffice" -> Json.obj(
      "addressLine1" -> "38B",
      "addressLine2" -> "line2",
      "addressLine3" -> JsNull,
      "addressLine4" -> JsNull,
      "postCode" -> "AA1 1AA",
      "dateOfChange" -> JsNull),
    "correspondenceAddress" -> Json.obj(
      "yourName" -> "Name",
      "businessName" -> "Business Name",
      "correspondenceAddressLine1" -> "address 1",
      "correspondenceAddressLine2" -> "address 2",
      "correspondenceAddressLine3" -> "address 3",
      "correspondenceAddressLine4" -> "address 4",
      "correspondencePostCode" -> "AA11 1AA"
    ),
    "hasChanged" -> false,
    "hasAccepted" -> true
  )

  "AboutTheBusiness Serialisation" must {
    "Serialise as expected" in {
      Json.toJson(completeModel) must
        be(completeJson)
    }

    "Deserialise as expected" in {
      completeJson.as[AboutTheBusiness] must
        be(completeModel)
    }
  }

  it when {
    "hasChanged is missing from the Json" must {
      "Deserialise correctly" in {
        (completeJson - "hasChanged").as[AboutTheBusiness] must
          be (completeModel)
      }
    }
  }

  "isComplete must return true" in {
    completeModel.isComplete must be(true)
  }

  "Partially complete AboutTheBusiness" must {

    val partialJson = Json.obj(
      "previouslyRegistered" -> Json.obj("previouslyRegistered" -> true,
      "prevMLRRegNo" -> "12345678"
      ),
      "hasChanged" -> false,
      "hasAccepted" -> false
    )
<commit_msg>AMLS-2906 added fakeapplication to ABT test to cope with toggle<commit_after>/*
 * Copyright 2017 HM Revenue & Customs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package models.aboutthebusiness

import org.joda.time.LocalDate
import org.scalatest.mock.MockitoSugar
import org.scalatestplus.play.{OneAppPerSuite, PlaySpec}
import play.api.libs.json.{JsNull, Json}
import play.api.test.FakeApplication

class AboutTheBusinessSpec extends PlaySpec with MockitoSugar  with OneAppPerSuite {

  override lazy val app = FakeApplication(additionalConfiguration = Map("microservice.services.feature-toggle.has-accepted" -> true))

  val previouslyRegistered = PreviouslyRegisteredYes("12345678")

  val regForVAT = VATRegisteredYes("123456789")

  // scalastyle:off
  val  activityStartDate = ActivityStartDate(new LocalDate(1990, 2, 24))

  val  newActivityStartDate = ActivityStartDate(new LocalDate(1990, 2, 24))

  val regForCorpTax = CorporationTaxRegisteredYes("1234567890")

  val contactingYou = ContactingYou(Some("1234567890"), Some("<EMAIL>"))

  val regOfficeOrMainPlaceUK =  RegisteredOfficeUK("38B", "line2", None, None, "AA1 1AA")

  val uKCorrespondenceAddress = UKCorrespondenceAddress("Name",
    "Business Name",
    "address 1",
    "address 2",
    Some("address 3"),
    Some("address 4"),
    "AA11 1AA")

  val completeModel = AboutTheBusiness(
    previouslyRegistered = Some(previouslyRegistered),
    activityStartDate = Some(activityStartDate),
    vatRegistered = Some(regForVAT),
    corporationTaxRegistered = Some(regForCorpTax),
    contactingYou = Some(contactingYou),
    registeredOffice = Some(regOfficeOrMainPlaceUK),
    correspondenceAddress = Some(uKCorrespondenceAddress),
    hasAccepted = true
  )

  val completeJson = Json.obj(
    "previouslyRegistered" -> Json.obj("previouslyRegistered" -> true,
      "prevMLRRegNo" -> "12345678"),
    "activityStartDate" -> Json.obj(
      "startDate" -> "1990-02-24"),
    "vatRegistered" -> Json.obj("registeredForVAT" -> true,
      "vrnNumber" -> "123456789"),
    "corporationTaxRegistered" -> Json.obj("registeredForCorporationTax" -> true,
      "corporationTaxReference" -> "1234567890"),
    "contactingYou" -> Json.obj(
      "phoneNumber" -> "1234567890",
      "email" -> "<EMAIL>"),
    "registeredOffice" -> Json.obj(
      "addressLine1" -> "38B",
      "addressLine2" -> "line2",
      "addressLine3" -> JsNull,
      "addressLine4" -> JsNull,
      "postCode" -> "AA1 1AA",
      "dateOfChange" -> JsNull),
    "correspondenceAddress" -> Json.obj(
      "yourName" -> "Name",
      "businessName" -> "Business Name",
      "correspondenceAddressLine1" -> "address 1",
      "correspondenceAddressLine2" -> "address 2",
      "correspondenceAddressLine3" -> "address 3",
      "correspondenceAddressLine4" -> "address 4",
      "correspondencePostCode" -> "AA11 1AA"
    ),
    "hasChanged" -> false,
    "hasAccepted" -> true
  )

  "AboutTheBusiness Serialisation" must {
    "Serialise as expected" in {
      Json.toJson(completeModel) must
        be(completeJson)
    }

    "Deserialise as expected" in {
      completeJson.as[AboutTheBusiness] must
        be(completeModel)
    }

    "isComplete must return true" in {
      completeModel.isComplete must be(true)
    }
  }

  it when {
    "hasChanged is missing from the Json" must {
      "Deserialise correctly" in {
        (completeJson - "hasChanged").as[AboutTheBusiness] must
          be (completeModel)
      }
    }
  }

  "Partially complete AboutTheBusiness" must {

    val partialJson = Json.obj(
      "previouslyRegistered" -> Json.obj("previouslyRegistered" -> true,
      "prevMLRRegNo" -> "12345678"
      ),
      "hasChanged" -> false,
      "hasAccepted" -> false
    )

{'fraction_non_alphanumeric': 0.11712038717483364, 'fraction_numerical': 0.035329703569268, 'mean_word_length': 3.5492570170610898, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 80, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '413012', 'n_tokens_mistral': 2757, 'n_tokens_neox': 2473, 'n_words': 613}