|
| 1 | +package hmda.publication.reports.disclosure |
| 2 | + |
| 3 | +import akka.NotUsed |
| 4 | +import akka.actor.ActorSystem |
| 5 | +import akka.stream.ActorMaterializer |
| 6 | +import akka.stream.scaladsl.Source |
| 7 | +import hmda.model.fi.lar.{ LarGenerators, LoanApplicationRegister } |
| 8 | +import hmda.model.publication.reports.ActionTakenTypeEnum._ |
| 9 | +import hmda.model.publication.reports.ApplicantIncomeEnum.LessThan50PercentOfMSAMedian |
| 10 | +import hmda.model.publication.reports.{ EthnicityBorrowerCharacteristic, MSAReport, MinorityStatusBorrowerCharacteristic, RaceBorrowerCharacteristic } |
| 11 | +import hmda.query.model.filing.LoanApplicationRegisterQuery |
| 12 | +import hmda.query.repository.filing.LarConverter._ |
| 13 | +import org.scalacheck.Gen |
| 14 | +import org.scalatest.{ AsyncWordSpec, BeforeAndAfterAll, MustMatchers } |
| 15 | + |
| 16 | +import scala.concurrent.Future |
| 17 | + |
| 18 | +class D52Spec extends AsyncWordSpec with MustMatchers with LarGenerators with BeforeAndAfterAll { |
| 19 | + |
| 20 | + implicit val system = ActorSystem() |
| 21 | + implicit val ec = system.dispatcher |
| 22 | + implicit val materializer = ActorMaterializer() |
| 23 | + |
| 24 | + override def afterAll(): Unit = { |
| 25 | + super.afterAll() |
| 26 | + system.terminate() |
| 27 | + } |
| 28 | + |
| 29 | + val respId = "98765" |
| 30 | + val fips = 18700 //Corvallis, OR |
| 31 | + def propType = Gen.oneOf(1, 2).sample.get |
| 32 | + |
| 33 | + val lars = lar100ListGen.sample.get.map { lar: LoanApplicationRegister => |
| 34 | + val geo = lar.geography.copy(msa = fips.toString) |
| 35 | + val loan = lar.loan.copy(loanType = 1, propertyType = propType, purpose = 1) |
| 36 | + lar.copy(respondentId = respId, geography = geo, loan = loan) |
| 37 | + } |
| 38 | + |
| 39 | + val source: Source[LoanApplicationRegisterQuery, NotUsed] = Source |
| 40 | + .fromIterator(() => lars.toIterator) |
| 41 | + .map(lar => toLoanApplicationRegisterQuery(lar)) |
| 42 | + |
| 43 | + val expectedDispositions = List(ApplicationReceived, LoansOriginated, ApprovedButNotAccepted, ApplicationsDenied, ApplicationsWithdrawn, ClosedForIncompleteness) |
| 44 | + |
| 45 | + "Generate a Disclosure 5-2 report" in { |
| 46 | + D52.generate(source, fips, respId, Future("Corvallis Test Bank")).map { result => |
| 47 | + |
| 48 | + result.msa mustBe MSAReport("18700", "Corvallis, OR", "OR", "Oregon") |
| 49 | + result.table mustBe "5-2" |
| 50 | + result.respondentId mustBe "98765" |
| 51 | + result.institutionName mustBe "Corvallis Test Bank" |
| 52 | + result.applicantIncomes.size mustBe 5 |
| 53 | + |
| 54 | + val lowestIncome = result.applicantIncomes.head |
| 55 | + lowestIncome.applicantIncome mustBe LessThan50PercentOfMSAMedian |
| 56 | + |
| 57 | + val races = lowestIncome.borrowerCharacteristics.head.asInstanceOf[RaceBorrowerCharacteristic].races |
| 58 | + races.size mustBe 8 |
| 59 | + |
| 60 | + val ethnicities = lowestIncome.borrowerCharacteristics(1).asInstanceOf[EthnicityBorrowerCharacteristic].ethnicities |
| 61 | + ethnicities.size mustBe 4 |
| 62 | + |
| 63 | + val minorityStatuses = lowestIncome.borrowerCharacteristics(2).asInstanceOf[MinorityStatusBorrowerCharacteristic].minoritystatus |
| 64 | + minorityStatuses.size mustBe 2 |
| 65 | + |
| 66 | + races.head.dispositions.map(_.disposition) mustBe expectedDispositions |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments