@@ -22,8 +22,11 @@ class RaceUtilSpec extends AsyncWordSpec with MustMatchers with LarGenerators wi
22
22
implicit val ec = system.dispatcher
23
23
implicit val materializer = ActorMaterializer ()
24
24
25
- def larCollection (transformation : (LoanApplicationRegister => LoanApplicationRegister )): List [LoanApplicationRegister ] = {
26
- lar100ListGen.sample.get.map(transformation)
25
+ def larCollectionWithApplicant (transformation : (Applicant => Applicant )): List [LoanApplicationRegister ] = {
26
+ lar100ListGen.sample.get.map { lar =>
27
+ val newApplicant = transformation(lar.applicant)
28
+ lar.copy(applicant = newApplicant)
29
+ }
27
30
}
28
31
29
32
def source (lars : List [LoanApplicationRegister ]): Source [LoanApplicationRegisterQuery , NotUsed ] = Source
@@ -40,158 +43,147 @@ class RaceUtilSpec extends AsyncWordSpec with MustMatchers with LarGenerators wi
40
43
41
44
" 'American Indian or Alaska Native' race filter" must {
42
45
" 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)
46
+ val lars = larCollectionWithApplicant { app =>
47
+ val withQualifyingCoApp = coApplicantNotWhite(app)
48
+ applicantRace3to5Blank(withQualifyingCoApp.copy(race1 = 1 , race2 = whiteOrBlank))
48
49
}
49
50
val nativeLars = filterRace(source(lars), AmericanIndianOrAlaskaNative )
50
51
count(nativeLars).map(_ mustBe 100 )
51
52
}
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 )
53
+ " exclude lars where applicant does not meet criteria" in {
54
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 1 , race2 = " 2" ))
55
+ val nonNativeLars = filterRace(source(excludedLars), AmericanIndianOrAlaskaNative )
56
+ count(nonNativeLars).map(_ mustBe 0 )
57
+ }
58
+ " exclude lars where coApplicant does not meet criteria" in {
59
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 1 , coRace1 = 5 ))
60
+ val nonNativeLars = filterRace(source(excludedLars), AmericanIndianOrAlaskaNative )
61
+ count(nonNativeLars).map(_ mustBe 0 )
65
62
}
66
63
}
67
64
68
65
" 'Asian' race filter" must {
69
66
" 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)
67
+ val lars = larCollectionWithApplicant { app =>
68
+ val withQualifyingCoApp = coApplicantNotWhite(app)
69
+ applicantRace3to5Blank(withQualifyingCoApp.copy(race1 = 2 , race2 = whiteOrBlank))
75
70
}
76
71
val asianLars = filterRace(source(lars), Asian )
77
72
count(asianLars).map(_ mustBe 100 )
78
73
}
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 )
74
+ " exclude lars where applicant does not meet criteria" in {
75
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 2 , race2 = " 3" ))
76
+ val nonAsianLars = filterRace(source(excludedLars), Asian )
77
+ count(nonAsianLars).map(_ mustBe 0 )
78
+ }
79
+ " exclude lars where coApplicant does not meet criteria" in {
80
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 2 , coRace1 = 5 ))
81
+ val nonAsianLars = filterRace(source(excludedLars), Asian )
82
+ count(nonAsianLars).map(_ mustBe 0 )
92
83
}
93
84
}
94
- /*
85
+
95
86
" 'Black or African American' race filter" must {
96
87
" include applications that meet 'Black or African American' criteria" in {
97
- val lars = larCollection { lar =>
88
+ val lars = larCollectionWithApplicant { app =>
89
+ val withQualifyingCoApp = coApplicantNotWhite(app)
90
+ applicantRace3to5Blank(withQualifyingCoApp.copy(race1 = 3 , race2 = whiteOrBlank))
98
91
}
99
- val nativeLars = filterRace(source(lars), BlackOrAfricanAmerican)
100
- count(nativeLars ).map(_ mustBe 100)
92
+ val blackLars = filterRace(source(lars), BlackOrAfricanAmerican )
93
+ count(blackLars ).map(_ mustBe 100 )
101
94
}
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)
95
+ " exclude lars where applicant does not meet criteria" in {
96
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 3 , race2 = " 4" ))
97
+ val nonBlackLars = filterRace(source(excludedLars), BlackOrAfricanAmerican )
98
+ count(nonBlackLars).map(_ mustBe 0 )
99
+ }
100
+ " exclude lars where coApplicant does not meet criteria" in {
101
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 3 , coRace1 = 5 ))
102
+ val nonBlackLars = filterRace(source(excludedLars), BlackOrAfricanAmerican )
112
103
count(nonBlackLars).map(_ mustBe 0 )
113
104
}
114
105
}
106
+
115
107
" 'Hawaiian or Pacific Islander' race filter" must {
116
108
" include applications that meet 'Hawaiian or Pacific Islander' criteria" in {
117
- val lars = larCollection { lar =>
109
+ val lars = larCollectionWithApplicant { app =>
110
+ val withQualifyingCoApp = coApplicantNotWhite(app)
111
+ applicantRace3to5Blank(withQualifyingCoApp.copy(race1 = 4 , race2 = whiteOrBlank))
118
112
}
119
- val hawaiianLars = filterRace(source(lars), HawaiianOrPacific)
120
- count(hawaiianLars ).map(_ mustBe 100)
113
+ val blackLars = filterRace(source(lars), HawaiianOrPacific )
114
+ count(blackLars ).map(_ mustBe 100 )
121
115
}
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)
116
+ " exclude lars where applicant does not meet criteria" in {
117
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 4 , race2 = " 3" ))
118
+ val nonBlackLars = filterRace(source(excludedLars), HawaiianOrPacific )
119
+ count(nonBlackLars).map(_ mustBe 0 )
120
+ }
121
+ " exclude lars where coApplicant does not meet criteria" in {
122
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 4 , coRace1 = 5 ))
123
+ val nonBlackLars = filterRace(source(excludedLars), HawaiianOrPacific )
124
+ count(nonBlackLars).map(_ mustBe 0 )
133
125
}
134
126
}
127
+
135
128
" 'White' race filter" must {
136
129
" include applications that meet 'White' criteria" in {
137
- val lars = larCollection { lar =>
130
+ def nonWhiteCoApp = Gen .oneOf(5 , 6 , 7 , 8 ).sample.get
131
+ val lars = larCollectionWithApplicant { app =>
132
+ val whiteApp = app.copy(race1 = 5 , race2 = " " , race3 = " " , race4 = " " , race5 = " " )
133
+ whiteApp.copy(coRace1 = nonWhiteCoApp, coRace2 = " " , coRace3 = " " , coRace4 = " " , coRace5 = " " )
138
134
}
139
135
val whiteLars = filterRace(source(lars), White )
140
136
count(whiteLars).map(_ mustBe 100 )
141
137
}
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)
138
+ " exclude lars where applicant does not meet criteria" in {
139
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 5 , race2 = " 3" ))
140
+ val nonWhiteLars = filterRace(source(excludedLars), White )
141
+ count(nonWhiteLars).map(_ mustBe 0 )
142
+ }
143
+ " exclude lars where coApplicant does not meet criteria" in {
144
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 5 , coRace1 = 3 ))
145
+ val nonWhiteLars = filterRace(source(excludedLars), White )
152
146
count(nonWhiteLars).map(_ mustBe 0 )
153
147
}
154
148
}
149
+
155
150
" 'Not Provided' race filter" must {
156
151
" include applications that meet 'Not Provided' criteria" in {
157
- val lars = larCollection { lar =>
158
- }
152
+ def notProvided = Gen .oneOf( 6 , 7 ).sample.get
153
+ val lars = larCollectionWithApplicant(_.copy(race1 = notProvided))
159
154
val notProvidedLars = filterRace(source(lars), NotProvided )
160
155
count(notProvidedLars).map(_ mustBe 100 )
161
156
}
162
157
" 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)
158
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 4 ))
159
+ val otherLars = filterRace(source(excludedLars), NotProvided )
172
160
count(otherLars).map(_ mustBe 0 )
173
161
}
174
162
}
163
+
175
164
" 'Two Or More Minority' race filter" must {
165
+ def minority = Gen .oneOf(1 , 2 , 3 , 4 ).sample.get
166
+
176
167
" include applications that meet 'Two Or More Minority' criteria" in {
177
- val lars = larCollection { lar =>
168
+ val lars = larCollectionWithApplicant { app =>
169
+ val withQualifyingCoApp = coApplicantNotWhite(app)
170
+ withQualifyingCoApp.copy(race1 = minority, race2 = minority.toString, race3 = " " , race4 = " " , race5 = " " )
178
171
}
179
172
val multiMinorityLars = filterRace(source(lars), TwoOrMoreMinority )
180
173
count(multiMinorityLars).map(_ mustBe 100 )
181
174
}
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)
175
+ " exclude lars where applicant does not meet criteria" in {
176
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 2 , race2 = " 5" ))
177
+ val otherLars = filterRace(source(excludedLars), TwoOrMoreMinority )
178
+ count(otherLars).map(_ mustBe 0 )
179
+ }
180
+ " exclude lars where coApplicant does not meet criteria" in {
181
+ val excludedLars = larCollectionWithApplicant(_.copy(race1 = 1 , race2 = " 2" , coRace1 = 5 ))
182
+ val otherLars = filterRace(source(excludedLars), TwoOrMoreMinority )
183
+ count(otherLars).map(_ mustBe 0 )
193
184
}
194
185
}
186
+ /*
195
187
"'Joint' race filter" must {
196
188
"include applications that meet 'Joint' criteria" in {
197
189
val lars = larCollection { lar =>
0 commit comments