Skip to content

Commit 8a0a5a1

Browse files
committed
WIP: adding specs for RaceUtils
Maybe coRaces should be allowed to be blank?
1 parent 3452d0d commit 8a0a5a1

File tree

1 file changed

+240
-0
lines changed

1 file changed

+240
-0
lines changed
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
package hmda.publication.reports
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.{ Applicant, LarGenerators, LoanApplicationRegister }
8+
import hmda.model.publication.reports.ActionTakenTypeEnum.{ ApplicationReceived, LoansOriginated }
9+
import hmda.model.publication.reports.{ RaceBorrowerCharacteristic, RaceCharacteristic }
10+
import hmda.model.publication.reports.RaceEnum._
11+
import hmda.publication.reports.util.DispositionType.{ OriginatedDisp, ReceivedDisp }
12+
import hmda.publication.reports.util.RaceUtil._
13+
import hmda.query.model.filing.LoanApplicationRegisterQuery
14+
import hmda.query.repository.filing.LarConverter._
15+
import hmda.util.SourceUtils
16+
import org.scalacheck.Gen
17+
import org.scalatest.{ AsyncWordSpec, MustMatchers }
18+
19+
class RaceUtilSpec extends AsyncWordSpec with MustMatchers with LarGenerators with SourceUtils {
20+
21+
implicit val system = ActorSystem()
22+
implicit val ec = system.dispatcher
23+
implicit val materializer = ActorMaterializer()
24+
25+
def larCollection(transformation: (LoanApplicationRegister => LoanApplicationRegister)): List[LoanApplicationRegister] = {
26+
lar100ListGen.sample.get.map(transformation)
27+
}
28+
29+
def source(lars: List[LoanApplicationRegister]): Source[LoanApplicationRegisterQuery, NotUsed] = Source
30+
.fromIterator(() => lars.toIterator)
31+
.map(lar => toLoanApplicationRegisterQuery(lar))
32+
33+
def nonWhiteRaceGen = Gen.oneOf("1", "2", "3", "4").sample.get
34+
def coApplicantNotWhite(app: Applicant) = {
35+
app.copy(coRace1 = nonWhiteRaceGen.toInt, coRace2 = nonWhiteRaceGen, coRace3 = nonWhiteRaceGen,
36+
coRace4 = nonWhiteRaceGen, coRace5 = nonWhiteRaceGen)
37+
}
38+
def whiteOrBlank = Gen.oneOf("5", "").sample.get
39+
def applicantRace3to5Blank(app: Applicant) = app.copy(race3 = "", race4 = "", race5 = "")
40+
41+
"'American Indian or Alaska Native' race filter" must {
42+
"include applications that meet 'American Indian or Alaska Native' criteria" in {
43+
val lars = larCollection { lar =>
44+
val app = lar.applicant
45+
val withQualifyingRace = applicantRace3to5Blank(app.copy(race1 = 1, race2 = whiteOrBlank))
46+
val withCoApplicant = coApplicantNotWhite(withQualifyingRace)
47+
lar.copy(applicant = withCoApplicant)
48+
}
49+
val nativeLars = filterRace(source(lars), AmericanIndianOrAlaskaNative)
50+
count(nativeLars).map(_ mustBe 100)
51+
}
52+
"exclude applications that do not meet 'American Indian or Alaska Native' criteria" in {
53+
val larsExcludedByApplicant = larCollection { lar =>
54+
val applicant = lar.applicant.copy(race1 = 1, race2 = "2")
55+
lar.copy(applicant = applicant)
56+
}
57+
val larsExcludedByCoApplicant = larCollection { lar =>
58+
val applicant = lar.applicant.copy(race1 = 1, coRace1 = 5)
59+
lar.copy(applicant = applicant)
60+
}
61+
val nonNativeLars1 = filterRace(source(larsExcludedByApplicant), AmericanIndianOrAlaskaNative)
62+
val nonNativeLars2 = filterRace(source(larsExcludedByCoApplicant), AmericanIndianOrAlaskaNative)
63+
count(nonNativeLars1).map(_ mustBe 0)
64+
count(nonNativeLars2).map(_ mustBe 0)
65+
}
66+
}
67+
68+
"'Asian' race filter" must {
69+
"include applications that meet 'Asian' criteria" in {
70+
val lars = larCollection { lar =>
71+
val app = lar.applicant
72+
val withQualifyingRace = applicantRace3to5Blank(app.copy(race1 = 2, race2 = whiteOrBlank))
73+
val withCoApplicant = coApplicantNotWhite(withQualifyingRace)
74+
lar.copy(applicant = withCoApplicant)
75+
}
76+
val asianLars = filterRace(source(lars), Asian)
77+
count(asianLars).map(_ mustBe 100)
78+
}
79+
"exclude applications that do not meet 'Asian' criteria" in {
80+
val larsExcludedByApplicant = larCollection { lar =>
81+
val applicant = lar.applicant.copy(race1 = 2, race2 = "3")
82+
lar.copy(applicant = applicant)
83+
}
84+
val larsExcludedByCoApplicant = larCollection { lar =>
85+
val applicant = lar.applicant.copy(race1 = 2, coRace1 = 5)
86+
lar.copy(applicant = applicant)
87+
}
88+
val nonAsianLars1 = filterRace(source(larsExcludedByApplicant), Asian)
89+
val nonAsianLars2 = filterRace(source(larsExcludedByCoApplicant), Asian)
90+
count(nonAsianLars1).map(_ mustBe 0)
91+
count(nonAsianLars2).map(_ mustBe 0)
92+
}
93+
}
94+
/*
95+
"'Black or African American' race filter" must {
96+
"include applications that meet 'Black or African American' criteria" in {
97+
val lars = larCollection { lar =>
98+
}
99+
val nativeLars = filterRace(source(lars), BlackOrAfricanAmerican)
100+
count(nativeLars).map(_ mustBe 100)
101+
}
102+
"exclude applications that do not meet 'Black or African American' criteria" in {
103+
val larsExcludedByApplicant = larCollection { lar =>
104+
val applicant = lar.applicant.copy(ethnicity = 2, coEthnicity = 3)
105+
lar.copy(applicant = applicant)
106+
}
107+
val larsExcludedByCoApplicant = larCollection { lar =>
108+
val applicant = lar.applicant.copy(ethnicity = 1, coEthnicity = 2)
109+
lar.copy(applicant = applicant)
110+
}
111+
val nonBlackLars = filterRace(source(lars), BlackOrAfricanAmerican)
112+
count(nonBlackLars).map(_ mustBe 0)
113+
}
114+
}
115+
"'Hawaiian or Pacific Islander' race filter" must {
116+
"include applications that meet 'Hawaiian or Pacific Islander' criteria" in {
117+
val lars = larCollection { lar =>
118+
}
119+
val hawaiianLars = filterRace(source(lars), HawaiianOrPacific)
120+
count(hawaiianLars).map(_ mustBe 100)
121+
}
122+
"exclude applications that do not meet 'Hawaiian or Pacific Islander' criteria" in {
123+
val larsExcludedByApplicant = larCollection { lar =>
124+
val applicant = lar.applicant.copy(ethnicity = 2, coEthnicity = 3)
125+
lar.copy(applicant = applicant)
126+
}
127+
val larsExcludedByCoApplicant = larCollection { lar =>
128+
val applicant = lar.applicant.copy(ethnicity = 1, coEthnicity = 2)
129+
lar.copy(applicant = applicant)
130+
}
131+
val hawaiianLars = filterRace(source(lars), HawaiianOrPacific)
132+
count(hawaiianLars).map(_ mustBe 0)
133+
}
134+
}
135+
"'White' race filter" must {
136+
"include applications that meet 'White' criteria" in {
137+
val lars = larCollection { lar =>
138+
}
139+
val whiteLars = filterRace(source(lars), White)
140+
count(whiteLars).map(_ mustBe 100)
141+
}
142+
"exclude applications that do not meet 'White' criteria" in {
143+
val larsExcludedByApplicant = larCollection { lar =>
144+
val applicant = lar.applicant.copy(ethnicity = 2, coEthnicity = 3)
145+
lar.copy(applicant = applicant)
146+
}
147+
val larsExcludedByCoApplicant = larCollection { lar =>
148+
val applicant = lar.applicant.copy(ethnicity = 1, coEthnicity = 2)
149+
lar.copy(applicant = applicant)
150+
}
151+
val nonWhiteLars = filterRace(source(lars), White)
152+
count(nonWhiteLars).map(_ mustBe 0)
153+
}
154+
}
155+
"'Not Provided' race filter" must {
156+
"include applications that meet 'Not Provided' criteria" in {
157+
val lars = larCollection { lar =>
158+
}
159+
val notProvidedLars = filterRace(source(lars), NotProvided)
160+
count(notProvidedLars).map(_ mustBe 100)
161+
}
162+
"exclude applications that do not meet 'Not Provided' criteria" in {
163+
val larsExcludedByApplicant = larCollection { lar =>
164+
val applicant = lar.applicant.copy(ethnicity = 2, coEthnicity = 3)
165+
lar.copy(applicant = applicant)
166+
}
167+
val larsExcludedByCoApplicant = larCollection { lar =>
168+
val applicant = lar.applicant.copy(ethnicity = 1, coEthnicity = 2)
169+
lar.copy(applicant = applicant)
170+
}
171+
val otherLars = filterRace(source(lars), NotProvided)
172+
count(otherLars).map(_ mustBe 0)
173+
}
174+
}
175+
"'Two Or More Minority' race filter" must {
176+
"include applications that meet 'Two Or More Minority' criteria" in {
177+
val lars = larCollection { lar =>
178+
}
179+
val multiMinorityLars = filterRace(source(lars), TwoOrMoreMinority)
180+
count(multiMinorityLars).map(_ mustBe 100)
181+
}
182+
"exclude applications that do not meet 'Two Or More Minority' criteria" in {
183+
val larsExcludedByApplicant = larCollection { lar =>
184+
val applicant = lar.applicant.copy(ethnicity = 2, coEthnicity = 3)
185+
lar.copy(applicant = applicant)
186+
}
187+
val larsExcludedByCoApplicant = larCollection { lar =>
188+
val applicant = lar.applicant.copy(ethnicity = 1, coEthnicity = 2)
189+
lar.copy(applicant = applicant)
190+
}
191+
val nonMultiMinority = filterRace(source(lars), TwoOrMoreMinority)
192+
count(nonMultiMinority).map(_ mustBe 0)
193+
}
194+
}
195+
"'Joint' race filter" must {
196+
"include applications that meet 'Joint' criteria" in {
197+
val lars = larCollection { lar =>
198+
}
199+
val jointLars = filterRace(source(lars), Joint)
200+
count(jointLars).map(_ mustBe 100)
201+
}
202+
"exclude applications that do not meet 'Joint' criteria" in {
203+
val larsExcludedByApplicant = larCollection { lar =>
204+
val applicant = lar.applicant.copy(ethnicity = 2, coEthnicity = 3)
205+
lar.copy(applicant = applicant)
206+
}
207+
val larsExcludedByCoApplicant = larCollection { lar =>
208+
val applicant = lar.applicant.copy(ethnicity = 1, coEthnicity = 2)
209+
lar.copy(applicant = applicant)
210+
}
211+
val nonJointLars = filterRace(source(lars), Joint)
212+
count(nonJointLars).map(_ mustBe 0)
213+
}
214+
}
215+
216+
*/
217+
218+
/*
219+
"ethnicityBorrowerCharacteristic" must {
220+
"generate a EthnicityBorrowCharacteristic with all 4 ethnicity categories and the specified dispositions" in {
221+
val lars = lar100ListGen.sample.get
222+
val dispositions = List(ReceivedDisp, OriginatedDisp)
223+
224+
val resultF = ethnicityBorrowerCharacteristic(source(lars), dispositions)
225+
226+
resultF.map { result =>
227+
result mustBe a[EthnicityBorrowerCharacteristic]
228+
229+
result.ethnicities.size mustBe 4
230+
231+
val firstEthCharacteristic = result.ethnicities.head
232+
firstEthCharacteristic mustBe a[EthnicityCharacteristic]
233+
firstEthCharacteristic.ethnicity mustBe HispanicOrLatino
234+
firstEthCharacteristic.dispositions.map(_.disposition) mustBe List(ApplicationReceived, LoansOriginated)
235+
}
236+
}
237+
}
238+
*/
239+
240+
}

0 commit comments

Comments
 (0)