Skip to content

Commit e00e07d

Browse files
author
Nick Grippin
committed
return empty set for blank email
1 parent 36b690e commit e00e07d

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

query/src/main/scala/hmda/query/view/institutions/InstitutionView.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ class InstitutionView extends HmdaPersistentActor {
9393
sender() ! state.institutions
9494

9595
case FindInstitutionByPeriodAndDomain(domain) =>
96-
sender() ! state.institutions.filter(i => i.emailDomains.map(e => extractDomain(e)).contains(domain.toLowerCase))
97-
96+
if (domain.isEmpty) {
97+
sender() ! Set.empty[Institution]
98+
} else {
99+
sender() ! state.institutions.filter(i => i.emailDomains.map(e => extractDomain(e)).contains(domain.toLowerCase))
100+
}
98101
}
99102

100103
override def receiveRecover: Receive = super.receiveRecover orElse {

query/src/test/scala/hmda/query/view/institutions/InstitutionViewSpec.scala

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package hmda.query.view.institutions
22

33
import akka.actor.ActorRef
44
import akka.testkit.TestProbe
5-
import hmda.model.institution.InstitutionGenerators
5+
import hmda.model.institution.{ Institution, InstitutionGenerators }
66
import hmda.persistence.messages.CommonMessages.GetState
77
import hmda.persistence.messages.events.institutions.InstitutionEvents.{ InstitutionCreated, InstitutionModified }
88
import hmda.persistence.model.ActorSpec
@@ -17,6 +17,10 @@ class InstitutionViewSpec extends ActorSpec {
1717
val i3 = InstitutionGenerators.sampleInstitution
1818
val i4 = i3.copy(cra = true)
1919

20+
val e1 = Institution.empty.copy(id = "1", emailDomains = Set("test.com", "", ""))
21+
val e2 = Institution.empty.copy(id = "2", emailDomains = Set("", "", ""))
22+
val e3 = Institution.empty.copy(id = "3", emailDomains = Set("test.com", "", ""))
23+
2024
val institutionQuery = createInstitutionView(system)
2125

2226
implicit val ec = system.dispatcher
@@ -29,6 +33,9 @@ class InstitutionViewSpec extends ActorSpec {
2933
institutionQuery ! EventWithSeqNr(2, InstitutionCreated(i2))
3034
institutionQuery ! EventWithSeqNr(3, InstitutionCreated(i3))
3135
institutionQuery ! EventWithSeqNr(4, InstitutionModified(i4))
36+
institutionQuery ! EventWithSeqNr(5, InstitutionCreated(e1))
37+
institutionQuery ! EventWithSeqNr(6, InstitutionCreated(e2))
38+
institutionQuery ! EventWithSeqNr(7, InstitutionCreated(e3))
3239
}
3340

3441
"Institutions View" must {
@@ -50,7 +57,7 @@ class InstitutionViewSpec extends ActorSpec {
5057
}
5158
"return full list of institutions" in {
5259
probe.send(institutionQuery, GetState)
53-
probe.expectMsg(Set(i1, i2, i4))
60+
probe.expectMsg(Set(i1, i2, i4, e1, e2, e3))
5461
}
5562
"return reference to institution query projector" in {
5663
probe.send(institutionQuery, GetProjectionActorRef)
@@ -61,6 +68,21 @@ class InstitutionViewSpec extends ActorSpec {
6168
probe.send(institutionQuery, GetInstitutionByRespondentId(i1.respondentId))
6269
probe.expectMsg(i1)
6370
}
71+
72+
"return a set of institutions that match a domain" in {
73+
probe.send(institutionQuery, FindInstitutionByPeriodAndDomain("test.com"))
74+
probe.expectMsg(Set(e1, e3))
75+
}
76+
77+
"return an empty set when requesting a domain that doesn't exist" in {
78+
probe.send(institutionQuery, FindInstitutionByPeriodAndDomain("notest.com"))
79+
probe.expectMsg(Set())
80+
}
81+
82+
"return an empty set when requesting a blank domain" in {
83+
probe.send(institutionQuery, FindInstitutionByPeriodAndDomain(""))
84+
probe.expectMsg(Set())
85+
}
6486
}
6587

6688
}

0 commit comments

Comments
 (0)