<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

import java.sql.Timestamp
import org.joda.time.{LocalDate, LocalDateTime}
import org.scalatest.mock.MockitoSugar
import org.scalatestplus.play.PlaySpec
import play.api.libs.json.Json

class ReadStatusResponseSpec extends PlaySpec with MockitoSugar {

  "ReadStatusResponse" must {

    "serialise to json when optional fields are not present" in {

      val expectedJson =
        Json.obj(
          "processingDate" -> "2019-12-30T00:00:00Z",
          "formBundleStatus" -> "bundle",
          "statusReason" -> "status",
          "deRegistrationDate" -> "2017-01-01",
          "currentRegYearStartDate" -> "2018-02-02",
          "currentRegYearEndDate" -> "2019-03-03",
          "renewalConFlag" -> true
        )


      val response = ReadStatusResponse(
        processingDate = new LocalDateTime(Timestamp.valueOf("2019-12-30 00:00:00.000")),
        formBundleStatus = "bundle",
        statusReason = Some("status"),
        deRegistrationDate = Some(new LocalDate("2017-01-01")),
        currentRegYearStartDate = Some(new LocalDate("2018-02-02")),
        currentRegYearEndDate = Some(new LocalDate("2019-03-03")),
        renewalConFlag = true
      )

      Json toJson response mustEqual expectedJson
    }

    "serialise to json with all fields" in {

      val expectedJson =
        Json.obj(
          "processingDate" -> "2019-12-30T00:00:00Z",
          "formBundleStatus" -> "bundle",
          "statusReason" -> "status",
          "deRegistrationDate" -> "2017-01-01",
          "currentRegYearStartDate" -> "2018-02-02",
          "currentRegYearEndDate" -> "2019-03-03",
          "renewalConFlag" -> true,
          "renewalSubmissionFlag" -> true,
          "currentAMLSOutstandingBalance" -> "balance",
          "businessContactNumber" -> "number",
          "safeId" -> "idNumber"
        )


      val response = ReadStatusResponse(
        processingDate = new LocalDateTime(Timestamp.valueOf("2019-12-30 00:00:00.000")),
        formBundleStatus = "bundle",
        statusReason = Some("status"),
        deRegistrationDate = Some(new LocalDate("2017-01-01")),
        currentRegYearStartDate = Some(new LocalDate("2018-02-02")),
        currentRegYearEndDate = Some(new LocalDate("2019-03-03")),
        renewalConFlag = true,
        renewalSubmissionFlag = Some(true),
        currentAMLSOutstandingBalance = Some("balance"),
        businessContactNumber = Some("number"),
        safeId = Some("idNumber")
      )

      Json toJson response mustEqual expectedJson
    }
  }
}<commit_msg>added test around serialising a json to ReadStatusResponse model<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

import java.sql.Timestamp

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

class ReadStatusResponseSpec extends PlaySpec with MockitoSugar {

  "ReadStatusResponse" must {

    "serialise to json when optional fields are not present" in {

      val expectedJson =
        Json.obj(
          "processingDate" -> "2019-12-30T00:00:00Z",
          "formBundleStatus" -> "bundle",
          "statusReason" -> "status",
          "deRegistrationDate" -> "2017-01-01",
          "currentRegYearStartDate" -> "2018-02-02",
          "currentRegYearEndDate" -> "2019-03-03",
          "renewalConFlag" -> true
        )


      val response = ReadStatusResponse(
        processingDate = new LocalDateTime(Timestamp.valueOf("2019-12-30 00:00:00.000")),
        formBundleStatus = "bundle",
        statusReason = Some("status"),
        deRegistrationDate = Some(new LocalDate("2017-01-01")),
        currentRegYearStartDate = Some(new LocalDate("2018-02-02")),
        currentRegYearEndDate = Some(new LocalDate("2019-03-03")),
        renewalConFlag = true
      )

      Json toJson response mustEqual expectedJson
    }

    "serialise to json with all fields" in {

      val expectedJson =
        Json.obj(
          "processingDate" -> "2019-12-30T00:00:00Z",
          "formBundleStatus" -> "bundle",
          "statusReason" -> "status",
          "deRegistrationDate" -> "2017-01-01",
          "currentRegYearStartDate" -> "2018-02-02",
          "currentRegYearEndDate" -> "2019-03-03",
          "renewalConFlag" -> true,
          "renewalSubmissionFlag" -> true,
          "currentAMLSOutstandingBalance" -> "balance",
          "businessContactNumber" -> "number",
          "safeId" -> "idNumber"
        )


      val response = ReadStatusResponse(
        processingDate = new LocalDateTime(Timestamp.valueOf("2019-12-30 00:00:00.000")),
        formBundleStatus = "bundle",
        statusReason = Some("status"),
        deRegistrationDate = Some(new LocalDate("2017-01-01")),
        currentRegYearStartDate = Some(new LocalDate("2018-02-02")),
        currentRegYearEndDate = Some(new LocalDate("2019-03-03")),
        renewalConFlag = true,
        renewalSubmissionFlag = Some(true),
        currentAMLSOutstandingBalance = Some("balance"),
        businessContactNumber = Some("number"),
        safeId = Some("idNumber")
      )

      Json toJson response mustEqual expectedJson
    }

    "create model from json with all fields" in {

      val json =
        Json.obj(
          "processingDate" -> "2019-12-30T00:00:00Z",
          "formBundleStatus" -> "bundle",
          "statusReason" -> "status",
          "deRegistrationDate" -> "2017-01-01",
          "currentRegYearStartDate" -> "2018-02-02",
          "currentRegYearEndDate" -> "2019-03-03",
          "renewalConFlag" -> true,
          "renewalSubmissionFlag" -> true,
          "currentAMLSOutstandingBalance" -> "balance",
          "businessContactNumber" -> "number",
          "safeId" -> "idNumber"
        )

      val actual: JsResult[ReadStatusResponse] = Json.fromJson[ReadStatusResponse](json)

      val expected = ReadStatusResponse(
        processingDate = new LocalDateTime(Timestamp.valueOf("2019-12-30 00:00:00.000")),
        formBundleStatus = "bundle",
        statusReason = Some("status"),
        deRegistrationDate = Some(new LocalDate("2017-01-01")),
        currentRegYearStartDate = Some(new LocalDate("2018-02-02")),
        currentRegYearEndDate = Some(new LocalDate("2019-03-03")),
        renewalConFlag = true,
        renewalSubmissionFlag = Some(true),
        currentAMLSOutstandingBalance = Some("balance"),
        businessContactNumber = Some("number"),
        safeId = Some("idNumber")
      )

      actual mustEqual JsSuccess(expected)
    }

    "create model from json with only mandatory fields" in {

      val json =
        Json.obj(
          "processingDate" -> "2019-12-30T00:00:00Z",
          "formBundleStatus" -> "bundle",
          "statusReason" -> "status",
          "deRegistrationDate" -> "2017-01-01",
          "currentRegYearStartDate" -> "2018-02-02",
          "currentRegYearEndDate" -> "2019-03-03",
          "renewalConFlag" -> true
        )

      val actual: JsResult[ReadStatusResponse] = Json.fromJson[ReadStatusResponse](json)

      val expected = ReadStatusResponse(
        processingDate = new LocalDateTime(Timestamp.valueOf("2019-12-30 00:00:00.000")),
        formBundleStatus = "bundle",
        statusReason = Some("status"),
        deRegistrationDate = Some(new LocalDate("2017-01-01")),
        currentRegYearStartDate = Some(new LocalDate("2018-02-02")),
        currentRegYearEndDate = Some(new LocalDate("2019-03-03")),
        renewalConFlag = true
      )

      actual mustEqual JsSuccess(expected)
    }
  }
}
{'fraction_non_alphanumeric': 0.11823556161891768, 'fraction_numerical': 0.055707139608913145, 'mean_word_length': 2.7386315342116445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 57, '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': '3941047', 'n_tokens_mistral': 2817, 'n_tokens_neox': 2468, 'n_words': 587}