<commit_before>package hmda.api.protocol.admin

import hmda.api.model.ModelGenerators
import hmda.model.institution.Institution
import org.scalatest.{ MustMatchers, PropSpec }
import org.scalatest.prop.PropertyChecks
import spray.json._

class WriteInstitutionProtocolSpec extends PropSpec with PropertyChecks with MustMatchers with ModelGenerators with WriteInstitutionProtocol {

  property("Institution should convert to and from json") {
    forAll(institutionGen) { institution =>
      institution.toJson.convertTo[Institution] mustBe institution
    }
  }

}<commit_msg>Add protocol json test<commit_after>package hmda.api.protocol.admin

import hmda.api.model.ModelGenerators
import hmda.model.institution.Institution
import org.scalatest.{ MustMatchers, PropSpec }
import org.scalatest.prop.PropertyChecks
import spray.json._

class WriteInstitutionProtocolSpec extends PropSpec with PropertyChecks with MustMatchers with ModelGenerators with WriteInstitutionProtocol {

  property("Institution should convert to and from json") {
    forAll(institutionGen) { institution =>
      institution.toJson.convertTo[Institution] mustBe institution
    }
  }

  property("Institution JSON must be the correct format") {
    forAll(institutionGen) { i =>
      i.toJson mustBe
        JsObject(
          ("id", JsString(i.id)),
          ("name", JsString(i.name)),
          ("cra", JsBoolean(i.cra)),
          ("agency", JsString(i.agency.name)),
          ("externalIds", JsArray(i.externalIds.map { x =>
            JsObject(
              ("id", JsString(x.id)),
              ("idType", JsString(x.idType.entryName))
            )
          }.toVector)),
          ("status", JsObject(
            ("code", JsNumber(i.status.code)),
            ("message", JsString(i.status.message))
          )),
          ("hasParent", JsBoolean(i.hasParent)),
          ("institutionType", JsString(i.institutionType.entryName))
        )
    }
  }

}
{'fraction_non_alphanumeric': 0.10882956878850103, 'fraction_numerical': 0.0, 'mean_word_length': 3.30242825607064, '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': '6442704', 'n_tokens_mistral': 578, 'n_tokens_neox': 567, 'n_words': 118}