Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyford committed Jul 29, 2024
1 parent 24d0bf9 commit 4e5d197
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
44 changes: 43 additions & 1 deletion apps/rule-manager/test/db/RuleManagerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.gu.typerighter.model.{
TextSuggestion
}
import com.gu.typerighter.rules.BucketRuleResource
import db.{DBTest, DbRuleDraft, DbRuleLive}
import db.{DBTest, DbRuleDraft, DbRuleLive, Tags}
import org.scalatest.flatspec.FixtureAnyFlatSpec
import org.scalatest.matchers.should.Matchers
import scalikejdbc.scalatest.AutoRollback
Expand All @@ -20,6 +20,8 @@ import com.softwaremill.diffx.scalatest.DiffShouldMatcher._
import fixtures.RuleFixtures
import play.api.data.FormError
import utils.LocalStack

import java.io.File
import java.time.OffsetDateTime

class RuleManagerSpec extends FixtureAnyFlatSpec with Matchers with AutoRollback with DBTest {
Expand Down Expand Up @@ -558,4 +560,44 @@ class RuleManagerSpec extends FixtureAnyFlatSpec with Matchers with AutoRollback
.copy(updatedAt = mockUpdatedAt)
}
}

"csvImport" should "create draft and live rules based on the contents of the csv file passed in, ensuring the appropriate tag and category are set" in {
() =>
val tagToApply = Tags.create(name = "testTag")

val file = new File(getClass.getResource("/csv/mps.csv").toURI)

RuleManager.csvImport(
file,
Some("testTag"),
Some("Style guide and names"),
bucketRuleResource
)

val draftRules = DbRuleDraft.findAll()

draftRules.length shouldBe 3

val draftRule1 = draftRules(0)
draftRule1.pattern shouldBe Some("Dami(e|a)n Egan")
draftRule1.replacement shouldBe Some("Damien Egan")
draftRule1.description shouldBe Some("MP last elected in 2024: Labour, Bristol North East")
draftRule1.category shouldBe Some("Style guide and names")

draftRule1.tags.length shouldBe 1
draftRule1.tags(0) shouldBe tagToApply.get.id.get

val liveRules = DbRuleLive.findAll()

liveRules.length shouldBe 3

val liveRule1 = liveRules(0)
liveRule1.pattern shouldBe Some("Dami(e|a)n Egan")
liveRule1.replacement shouldBe Some("Damien Egan")
liveRule1.description shouldBe Some("MP last elected in 2024: Labour, Bristol North East")
liveRule1.category shouldBe Some("Style guide and names")

liveRule1.tags.length shouldBe 1
liveRule1.tags(0) shouldBe tagToApply.get.id.get
}
}
3 changes: 3 additions & 0 deletions apps/rule-manager/test/resources/csv/mps.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dami(e|a)n Egan,Damien Egan,"MP last elected in 2024: Labour, Bristol North East"
Clive Efford,Clive Efford,"MP last elected in 2024: Labour, Eltham and Chislehurst"
Maya Ellis,Maya Ellis,"MP last elected in 2024: Labour, Ribble Valley"

0 comments on commit 4e5d197

Please sign in to comment.