<commit_before>/*
 * Copyright 2019 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.businessmatching

import generators.businessmatching.BusinessMatchingGenerator
import models.Country
import models.businesscustomer.{Address, ReviewDetails}
import models.registrationprogress.{Completed, NotStarted, Section, Started}
import org.mockito.Matchers.{eq => eqTo, _}
import org.mockito.Mockito._
import uk.gov.hmrc.http.cache.client.CacheMap
import uk.gov.hmrc.play.frontend.auth.AuthContext
import utils.AmlsSpec

class BusinessMatchingSpec extends AmlsSpec with BusinessMatchingGenerator {

  "BusinessMatchingSpec" must {
    import play.api.libs.json._

    val msbServices = BusinessMatchingMsbServices(
      Set(
        TransmittingMoney,
        CurrencyExchange,
        ChequeCashingNotScrapMetal,
        ChequeCashingScrapMetal
      )
    )

    val businessActivitiesModel = BusinessActivities(Set(MoneyServiceBusiness, TrustAndCompanyServices, TelephonePaymentService))
    val businessActivitiesWithouMSB = BusinessActivities(Set(TrustAndCompanyServices, TelephonePaymentService))
    val businessAddress = Address("line1", "line2", Some("line3"), Some("line4"), Some("AA11 1AA"), Country("United Kingdom", "GB"))
    val reviewDetailsModel = ReviewDetails("BusinessName", Some(BusinessType.SoleProprietor), businessAddress, "XE0000000000000")
    val typeOfBusinessModel = TypeOfBusiness("test")
    val companyRegistrationNumberModel = CompanyRegistrationNumber("12345678")
    val businessAppliedForPSRNumberModel = BusinessAppliedForPSRNumberYes("123456")

    val jsonBusinessMatching = Json.obj(
      "businessActivities" -> Seq("05", "06", "07"),
      "msbServices" -> Seq("01", "02", "03", "04"),
      "businessName" -> "BusinessName",
      "businessType" -> "Sole Trader",
      "businessAddress" -> Json.obj(
        "line_1" -> "line1",
        "line_2" -> "line2",
        "line_3" -> "line3",
        "line_4" -> "line4",
        "postcode" -> "AA11 1AA",
        "country" -> "GB"
      ),
      "safeId" -> "XE0000000000000",
      "typeOfBusiness" -> "test",
      "companyRegistrationNumber" -> "12345678",
      "appliedFor" -> true,
      "regNumber" -> "123456"
      ,
      "hasChanged" -> false,
      "hasAccepted" -> true,
      "preAppComplete" -> 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),
      "altCorrespondenceAddress" -> true,
      "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
    )

    val businessMatching = BusinessMatching(
      Some(reviewDetailsModel),
      Some(businessActivitiesModel),
      Some(msbServices),
      Some(typeOfBusinessModel),
      Some(companyRegistrationNumberModel),
      Some(businessAppliedForPSRNumberModel),
      hasAccepted = true,
      preAppComplete = true)

    "READ the JSON successfully and return the domain Object" in {
      Json.fromJson[BusinessMatching](jsonBusinessMatching - "hasChanged") must be(JsSuccess(businessMatching))
    }

    "WRITE the JSON successfully from the domain Object" in {
      Json.toJson(businessMatching) must be(jsonBusinessMatching)<commit_msg>Revert business matching<commit_after>/*
 * Copyright 2019 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.businessmatching

import generators.businessmatching.BusinessMatchingGenerator
import models.Country
import models.businesscustomer.{Address, ReviewDetails}
import models.registrationprogress.{Completed, NotStarted, Section, Started}
import org.mockito.Matchers.{eq => eqTo, _}
import org.mockito.Mockito._
import uk.gov.hmrc.http.cache.client.CacheMap
import uk.gov.hmrc.play.frontend.auth.AuthContext
import utils.AmlsSpec

class BusinessMatchingSpec extends AmlsSpec with BusinessMatchingGenerator {

  "BusinessMatchingSpec" must {
    import play.api.libs.json._

    val msbServices = BusinessMatchingMsbServices(
      Set(
        TransmittingMoney,
        CurrencyExchange,
        ChequeCashingNotScrapMetal,
        ChequeCashingScrapMetal
      )
    )

    val businessActivitiesModel = BusinessActivities(Set(MoneyServiceBusiness, TrustAndCompanyServices, TelephonePaymentService))
    val businessActivitiesWithouMSB = BusinessActivities(Set(TrustAndCompanyServices, TelephonePaymentService))
    val businessAddress = Address("line1", "line2", Some("line3"), Some("line4"), Some("AA11 1AA"), Country("United Kingdom", "GB"))
    val reviewDetailsModel = ReviewDetails("BusinessName", Some(BusinessType.SoleProprietor), businessAddress, "XE0000000000000")
    val typeOfBusinessModel = TypeOfBusiness("test")
    val companyRegistrationNumberModel = CompanyRegistrationNumber("12345678")
    val businessAppliedForPSRNumberModel = BusinessAppliedForPSRNumberYes("123456")

    val jsonBusinessMatching = Json.obj(
      "businessActivities" -> Seq("05", "06", "07"),
      "msbServices" -> Seq("01", "02", "03", "04"),
      "businessName" -> "BusinessName",
      "businessType" -> "Sole Trader",
      "businessAddress" -> Json.obj(
        "line_1" -> "line1",
        "line_2" -> "line2",
        "line_3" -> "line3",
        "line_4" -> "line4",
        "postcode" -> "AA11 1AA",
        "country" -> "GB"
      ),
      "safeId" -> "XE0000000000000",
      "typeOfBusiness" -> "test",
      "companyRegistrationNumber" -> "12345678",
      "appliedFor" -> true,
      "regNumber" -> "123456"
      ,
      "hasChanged" -> false,
      "hasAccepted" -> true,
      "preAppComplete" -> true
    )

    val businessMatching = BusinessMatching(
      Some(reviewDetailsModel),
      Some(businessActivitiesModel),
      Some(msbServices),
      Some(typeOfBusinessModel),
      Some(companyRegistrationNumberModel),
      Some(businessAppliedForPSRNumberModel),
      hasAccepted = true,
      preAppComplete = true)

    "READ the JSON successfully and return the domain Object" in {
      Json.fromJson[BusinessMatching](jsonBusinessMatching - "hasChanged") must be(JsSuccess(businessMatching))
    }

    "WRITE the JSON successfully from the domain Object" in {
      Json.toJson(businessMatching) must be(jsonBusinessMatching)
{'fraction_non_alphanumeric': 0.1143786910931662, 'fraction_numerical': 0.03049294925876823, 'mean_word_length': 3.5997782705099777, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '7554928', 'n_tokens_mistral': 2588, 'n_tokens_neox': 2347, 'n_words': 570}