Skip to content

Commit 907be1f

Browse files
committed
Bug fix: Only persist one filing per period per institution
Update FilingPersistence spec to use more realistic test data
1 parent 8e1d1fd commit 907be1f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

persistence/src/main/scala/hmda/persistence/institutions/FilingPersistence.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package hmda.persistence.institutions
22

33
import akka.actor.{ ActorRef, ActorSystem, Props }
4-
import hmda.model.fi.{ Completed, Filing, InProgress, NotStarted }
4+
import hmda.model.fi._
55
import hmda.persistence.messages.CommonMessages._
66
import hmda.persistence.institutions.FilingPersistence._
77
import hmda.persistence.model.HmdaPersistentActor
@@ -48,15 +48,15 @@ class FilingPersistence(institutionId: String) extends HmdaPersistentActor {
4848

4949
override def receiveCommand: Receive = super.receiveCommand orElse {
5050
case CreateFiling(f) =>
51-
if (!state.filings.contains(f)) {
51+
if (!state.filings.map(_.period).contains(f.period)) {
5252
persist(FilingCreated(f)) { e =>
5353
log.debug(s"Persisted: $f")
5454
updateState(e)
5555
sender() ! Some(f)
5656
}
5757
} else {
5858
sender() ! None
59-
log.warning(s"Filing already exists. Could not create $f")
59+
log.warning(s"Could not create Filing. Filing period ${f.period} already exists for institution $institutionId.")
6060
}
6161

6262
case UpdateFilingStatus(modified) =>

persistence/src/test/scala/hmda/persistence/institutions/FilingPersistenceSpec.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ class FilingPersistenceSpec extends ActorSpec {
1111

1212
val filingsActor = createFilings("12345", system)
1313

14+
val sample1 = Filing("2016", "12345", Completed, filingRequired = true, 1483287071000L, 1514736671000L)
15+
val sample2 = Filing("2017", "12345", NotStarted, filingRequired = true, 0L, 0L)
16+
1417
val probe = TestProbe()
1518

16-
"Filings" must {
17-
"be created and read back" in {
18-
val filings = DemoData.testFilings
19+
"CreateFiling" must {
20+
"create a filing" in {
21+
val filings = Seq(sample1, sample2)
1922
for (filing <- filings) {
2023
probe.send(filingsActor, CreateFiling(filing))
2124
probe.expectMsg(Some(filing))
@@ -32,12 +35,12 @@ class FilingPersistenceSpec extends ActorSpec {
3235
probe.expectMsg(modified)
3336
}
3437

35-
"return None when persisting a filing that already exists" in {
36-
val f1 = Filing("2016", "12345", Completed, true, 1483287071000L, 1514736671000L)
38+
"return None when persisting a filing period that already exists" in {
39+
val f1 = Filing("2018", "12345", Completed, true, 1483287071000L, 1514736671000L)
3740
probe.send(filingsActor, CreateFiling(f1))
3841
probe.expectMsg(Some(f1))
3942

40-
val f2 = Filing("2016", "12345", Completed, true, 1483287071000L, 1514736671000L)
43+
val f2 = Filing("2016", "12345", InProgress, true, 1483287071000L, 0L)
4144
probe.send(filingsActor, CreateFiling(f2))
4245
probe.expectMsg(None)
4346
}

0 commit comments

Comments
 (0)