From b29fc83a8c5549271c0d9f0f7c500b089e0fe0d8 Mon Sep 17 00:00:00 2001 From: jaredb96 Date: Wed, 26 Jun 2024 14:09:32 -0400 Subject: [PATCH] Add tag to more tests. --- .../SubmissionHistoryComponentSpec.scala | 49 +-- .../publisher/checks/TSLinesCheckTest.scala | 278 +++++++++--------- .../InstitutionEmailComponentSpec.scala | 158 +++++----- .../api/http/InstitutionComponentSpec.scala | 94 +++--- project/Dependencies.scala | 2 +- 5 files changed, 294 insertions(+), 287 deletions(-) diff --git a/hmda-analytics/src/test/scala/hmda/analytics/query/SubmissionHistoryComponentSpec.scala b/hmda-analytics/src/test/scala/hmda/analytics/query/SubmissionHistoryComponentSpec.scala index 77fac0c904..57db45a5a2 100644 --- a/hmda-analytics/src/test/scala/hmda/analytics/query/SubmissionHistoryComponentSpec.scala +++ b/hmda-analytics/src/test/scala/hmda/analytics/query/SubmissionHistoryComponentSpec.scala @@ -1,24 +1,25 @@ -//package hmda.analytics.query -// -//import java.time.{ LocalDateTime, ZoneOffset } -// -//import hmda.model.filing.submission.SubmissionId -//import hmda.utils.EmbeddedPostgres -//import hmda.utils.YearUtils.Period -//import org.scalatest.{ AsyncWordSpec, MustMatchers } -// -//class SubmissionHistoryComponentSpec extends AsyncWordSpec with SubmissionHistoryComponent with EmbeddedPostgres with MustMatchers { -// "SubmissionHistoryRepository" must { -// "be able to persist data" in { -// val repo = new SubmissionHistoryRepository(dbConfig, "submission_history") // as per hmda.sql -// val lei = "EXAMPLE-LEI" -// val timeNow = LocalDateTime.now() -// -// repo -// .insert(lei, SubmissionId(lei, Period(2018, None), 1), Some(timeNow.toEpochSecond(ZoneOffset.UTC))) -// .map(res => res mustBe 1) -// } -// } -// -// override def bootstrapSqlFile: String = "hmda.sql" -//} \ No newline at end of file +package hmda.analytics.query + +import java.time.{LocalDateTime, ZoneOffset} +import hmda.model.filing.submission.SubmissionId +import hmda.utils.EmbeddedPostgres +import hmda.utils.YearUtils.Period +import org.scalatest.{AsyncWordSpec, MustMatchers, Tag} + +object CustomTag extends Tag("actions-ignore") + +class SubmissionHistoryComponentSpec extends AsyncWordSpec with SubmissionHistoryComponent with EmbeddedPostgres with MustMatchers { + "SubmissionHistoryRepository" must { + "be able to persist data" taggedAs CustomTag in { + val repo = new SubmissionHistoryRepository(dbConfig, "submission_history") // as per hmda.sql + val lei = "EXAMPLE-LEI" + val timeNow = LocalDateTime.now() + + repo + .insert(lei, SubmissionId(lei, Period(2018, None), 1), Some(timeNow.toEpochSecond(ZoneOffset.UTC))) + .map(res => res mustBe 1) + } + } + + override def bootstrapSqlFile: String = "hmda.sql" +} \ No newline at end of file diff --git a/hmda-data-publisher/src/test/scala/hmda/publisher/checks/TSLinesCheckTest.scala b/hmda-data-publisher/src/test/scala/hmda/publisher/checks/TSLinesCheckTest.scala index 63dae119c9..5f37d0811f 100644 --- a/hmda-data-publisher/src/test/scala/hmda/publisher/checks/TSLinesCheckTest.scala +++ b/hmda-data-publisher/src/test/scala/hmda/publisher/checks/TSLinesCheckTest.scala @@ -1,138 +1,140 @@ -//package hmda.publisher.validation -// -//import akka.actor.ActorSystem -//import akka.testkit.TestKit -//import hmda.publisher.query.component.{ PublisherComponent2018, TransmittalSheetTable, TsRepository } -//import hmda.publisher.query.lar.{ LarEntityImpl2018, LarPartFive2018, LarPartFour2018, LarPartOne2018, LarPartSix2018, LarPartThree2018, LarPartTwo2018 } -//import hmda.query.ts.TransmittalSheetEntity -//import hmda.utils.EmbeddedPostgres -//import org.scalatest.concurrent.{ PatienceConfiguration, ScalaFutures } -//import org.scalatest.time.{ Millis, Minutes, Span } -//import org.scalatest.{ BeforeAndAfterAll, BeforeAndAfterEach, FreeSpecLike, Matchers } -// -//import scala.concurrent.duration.DurationInt -//import scala.concurrent.{ Await, Future } -// -//class TSLinesCheckTest -// extends TestKit(ActorSystem("PublisherComponent2018Spec")) -// with FreeSpecLike -// with Matchers -// with ScalaFutures -// with EmbeddedPostgres -// with BeforeAndAfterAll -// with BeforeAndAfterEach -// with PublisherComponent2018 -// with PatienceConfiguration { -// -// import scala.concurrent.ExecutionContext.Implicits.global -// -// override implicit def patienceConfig: PatienceConfig = PatienceConfig(timeout = Span(2, Minutes), interval = Span(100, Millis)) -// -// val tsRepo2018 = new TsRepository[TransmittalSheetTable](dbConfig, transmittalSheetTable2018) -// val larRepo2018 = new LarRepository2018(dbConfig) -// -// override def beforeAll(): Unit = { -// super.beforeAll() -// Await.ready( -// Future.sequence( -// List( -// tsRepo2018.createSchema(), -// larRepo2018.createSchema() -// ) -// ), -// 30.seconds -// ) -// } -// -// "no data in lar" in { -// -// val lei1 = "EXAMPLE-LEI" -// val ts1 = TransmittalSheetEntity(lei = lei1, totalLines = 10, submissionId = Some("sub1")) -// -// val check = new TSLinesCheck(dbConfig, validationTSData2018, validationLarData2018) -// -// val test = for { -// _ <- tsRepo2018.insert(ts1) -// result <- check.check() -// _ = assert( -// result == Left( -// """Some of the LEIs has different counts of records in Transmittal Sheet table and in LAR table. -// |LEI: EXAMPLE-LEI, submissionId: sub1, countFromTs: 10, countFromLar: null""".stripMargin -// ) -// ) -// } yield () -// -// test.futureValue -// -// } -// -// "different data in lar" in { -// -// val lei1 = "EXAMPLE-LEI" -// val ts1 = TransmittalSheetEntity(lei = lei1, totalLines = 10, submissionId = Some("sub1")) -// val check = new TSLinesCheck(dbConfig, validationTSData2018, validationLarData2018) -// val test = for { -// _ <- tsRepo2018.insert(ts1) -// _ <- larRepo2018.insert(dummyLar2018) -// _ <- larRepo2018.insert(dummyLar2018) -// result <- check.check() -// _ = assert( -// result == Left( -// """Some of the LEIs has different counts of records in Transmittal Sheet table and in LAR table. -// |LEI: EXAMPLE-LEI, submissionId: sub1, countFromTs: 10, countFromLar: 2""".stripMargin -// ) -// ) -// } yield () -// -// test.futureValue -// -// } -// -// "matching data in lar - 0" in { -// -// val lei1 = "EXAMPLE-LEI" -// val ts1 = TransmittalSheetEntity(lei = lei1, totalLines = 0, submissionId = Some("sub1")) -// -// val check = new TSLinesCheck(dbConfig, validationTSData2018, validationLarData2018) -// -// val test = for { -// _ <- tsRepo2018.insert(ts1) -// result <- check.check() -// _ = assert( -// result == Right(()) -// ) -// } yield () -// -// test.futureValue -// -// } -// -// "matching data in lar - non 0" in { -// -// val lei1 = "EXAMPLE-LEI" -// val ts1 = TransmittalSheetEntity(lei = lei1, totalLines = 1, submissionId = Some("sub1")) -// val check = new TSLinesCheck(dbConfig, validationTSData2018, validationLarData2018) -// val test = for { -// _ <- tsRepo2018.insert(ts1) -// _ <- larRepo2018.insert(dummyLar2018) -// result <- check.check() -// _ = assert( -// result == Right(()) -// ) -// } yield () -// -// test.futureValue -// -// } -// -// def dummyLar2018 = LarEntityImpl2018( -// LarPartOne2018(lei = "EXAMPLE-LEI"), -// LarPartTwo2018(), -// LarPartThree2018(), -// LarPartFour2018(), -// LarPartFive2018(), -// LarPartSix2018() -// ) -// -// override def bootstrapSqlFile: String = "" -//} \ No newline at end of file +package hmda.publisher.validation + +import akka.actor.ActorSystem +import akka.testkit.TestKit +import hmda.publisher.query.component.{PublisherComponent2018, TransmittalSheetTable, TsRepository} +import hmda.publisher.query.lar.{LarEntityImpl2018, LarPartFive2018, LarPartFour2018, LarPartOne2018, LarPartSix2018, LarPartThree2018, LarPartTwo2018} +import hmda.query.ts.TransmittalSheetEntity +import hmda.utils.EmbeddedPostgres +import org.scalatest.concurrent.{PatienceConfiguration, ScalaFutures} +import org.scalatest.time.{Millis, Minutes, Span} +import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, FreeSpecLike, Matchers, Tag} + +import scala.concurrent.duration.DurationInt +import scala.concurrent.{Await, Future} + +object CustomTag extends Tag("actions-ignore") + +class TSLinesCheckTest + extends TestKit(ActorSystem("PublisherComponent2018Spec")) + with FreeSpecLike + with Matchers + with ScalaFutures + with EmbeddedPostgres + with BeforeAndAfterAll + with BeforeAndAfterEach + with PublisherComponent2018 + with PatienceConfiguration { + + import scala.concurrent.ExecutionContext.Implicits.global + + override implicit def patienceConfig: PatienceConfig = PatienceConfig(timeout = Span(2, Minutes), interval = Span(100, Millis)) + + val tsRepo2018 = new TsRepository[TransmittalSheetTable](dbConfig, transmittalSheetTable2018) + val larRepo2018 = new LarRepository2018(dbConfig) + + override def beforeAll(): Unit = { + super.beforeAll() + Await.ready( + Future.sequence( + List( + tsRepo2018.createSchema(), + larRepo2018.createSchema() + ) + ), + 30.seconds + ) + } + + "no data in lar" taggedAs CustomTag in { + + val lei1 = "EXAMPLE-LEI" + val ts1 = TransmittalSheetEntity(lei = lei1, totalLines = 10, submissionId = Some("sub1")) + + val check = new TSLinesCheck(dbConfig, validationTSData2018, validationLarData2018) + + val test = for { + _ <- tsRepo2018.insert(ts1) + result <- check.check() + _ = assert( + result == Left( + """Some of the LEIs has different counts of records in Transmittal Sheet table and in LAR table. + |LEI: EXAMPLE-LEI, submissionId: sub1, countFromTs: 10, countFromLar: null""".stripMargin + ) + ) + } yield () + + test.futureValue + + } + + "different data in lar" taggedAs CustomTag in { + + val lei1 = "EXAMPLE-LEI" + val ts1 = TransmittalSheetEntity(lei = lei1, totalLines = 10, submissionId = Some("sub1")) + val check = new TSLinesCheck(dbConfig, validationTSData2018, validationLarData2018) + val test = for { + _ <- tsRepo2018.insert(ts1) + _ <- larRepo2018.insert(dummyLar2018) + _ <- larRepo2018.insert(dummyLar2018) + result <- check.check() + _ = assert( + result == Left( + """Some of the LEIs has different counts of records in Transmittal Sheet table and in LAR table. + |LEI: EXAMPLE-LEI, submissionId: sub1, countFromTs: 10, countFromLar: 2""".stripMargin + ) + ) + } yield () + + test.futureValue + + } + + "matching data in lar - 0" taggedAs CustomTag in { + + val lei1 = "EXAMPLE-LEI" + val ts1 = TransmittalSheetEntity(lei = lei1, totalLines = 0, submissionId = Some("sub1")) + + val check = new TSLinesCheck(dbConfig, validationTSData2018, validationLarData2018) + + val test = for { + _ <- tsRepo2018.insert(ts1) + result <- check.check() + _ = assert( + result == Right(()) + ) + } yield () + + test.futureValue + + } + + "matching data in lar - non 0" taggedAs CustomTag in { + + val lei1 = "EXAMPLE-LEI" + val ts1 = TransmittalSheetEntity(lei = lei1, totalLines = 1, submissionId = Some("sub1")) + val check = new TSLinesCheck(dbConfig, validationTSData2018, validationLarData2018) + val test = for { + _ <- tsRepo2018.insert(ts1) + _ <- larRepo2018.insert(dummyLar2018) + result <- check.check() + _ = assert( + result == Right(()) + ) + } yield () + + test.futureValue + + } + + def dummyLar2018 = LarEntityImpl2018( + LarPartOne2018(lei = "EXAMPLE-LEI"), + LarPartTwo2018(), + LarPartThree2018(), + LarPartFour2018(), + LarPartFive2018(), + LarPartSix2018() + ) + + override def bootstrapSqlFile: String = "" +} \ No newline at end of file diff --git a/hmda-data-publisher/src/test/scala/hmda/publisher/query/component/InstitutionEmailComponentSpec.scala b/hmda-data-publisher/src/test/scala/hmda/publisher/query/component/InstitutionEmailComponentSpec.scala index 7e97bc1c41..811e940cb3 100644 --- a/hmda-data-publisher/src/test/scala/hmda/publisher/query/component/InstitutionEmailComponentSpec.scala +++ b/hmda-data-publisher/src/test/scala/hmda/publisher/query/component/InstitutionEmailComponentSpec.scala @@ -1,78 +1,80 @@ -//package hmda.publisher.query.component -// -//import hmda.publisher.query.panel.InstitutionEmailEntity -//import hmda.utils.EmbeddedPostgres -//import org.scalatest.{ BeforeAndAfterAll, BeforeAndAfterEach, FreeSpec, Matchers } -//import org.scalatest.concurrent.{ PatienceConfiguration, ScalaFutures } -//import org.scalatest.time.{ Millis, Minutes, Span } -// -//import scala.concurrent.Await -//import scala.concurrent.duration._ -//import scala.concurrent.ExecutionContext.Implicits._ -// -//class InstitutionEmailComponentSpec -// extends FreeSpec -// with InstitutionEmailComponent -// with EmbeddedPostgres -// with ScalaFutures -// with Matchers -// with BeforeAndAfterAll -// with BeforeAndAfterEach -// with PatienceConfiguration { -// -// override implicit def patienceConfig: PatienceConfig = PatienceConfig(timeout = Span(2, Minutes), interval = Span(100, Millis)) -// -// import dbConfig.profile.api._ -// val repo = new InstitutionEmailsRepository2018(dbConfig) -// -// override def beforeAll(): Unit = { -// super.beforeAll() -// Await.ready(repo.createSchema(), 30.seconds) -// } -// -// override def afterEach(): Unit = -// Await.ready(dbConfig.db.run(repo.table.delete), 30.seconds) -// -// override def afterAll(): Unit = { -// Await.ready(repo.dropSchema(), 30.seconds) -// super.afterAll() -// } -// -// override def bootstrapSqlFile: String = "" -// -// "getId returns the Rep[Int]" in { -// repo.getId(_) -// } -// -// "deleteById deletes ids" in { -// val test = for { -// id <- dbConfig.db.run(repo.table += InstitutionEmailEntity(lei = "EXAMPLE", emailDomain = "example@domain.com")) -// deletedId <- repo.deleteById(id) -// } yield id shouldBe deletedId -// whenReady(test)(_ => ()) -// } -// -// "findByLei finds LEIs" in { -// val data = InstitutionEmailEntity(lei = "EXAMPLE", emailDomain = "example@domain.com") -// val test = for { -// _ <- dbConfig.db.run(repo.table += data) -// result <- repo.findByLei(data.lei) -// } yield { -// result should have length 1 -// result.map(_.lei) should contain theSameElementsAs List(data.lei) -// } -// whenReady(test)(_ => ()) -// } -// -// "getAllDomains finds records by domain" in { -// val data = InstitutionEmailEntity(lei = "EXAMPLE2", emailDomain = "example@domain1.com") -// val test = for { -// _ <- dbConfig.db.run(repo.table += data) -// result <- repo.getAllDomains() -// } yield { -// result should have length 1 -// result.map(_.lei) should contain theSameElementsAs List(data.lei) -// } -// whenReady(test)(_ => ()) -// } -//} \ No newline at end of file +package hmda.publisher.query.component + +import hmda.publisher.query.panel.InstitutionEmailEntity +import hmda.utils.EmbeddedPostgres +import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, FreeSpec, Matchers, Tag} +import org.scalatest.concurrent.{PatienceConfiguration, ScalaFutures} +import org.scalatest.time.{Millis, Minutes, Span} + +import scala.concurrent.Await +import scala.concurrent.duration._ +import scala.concurrent.ExecutionContext.Implicits._ + +object CustomTag extends Tag("actions-ignore") + +class InstitutionEmailComponentSpec + extends FreeSpec + with InstitutionEmailComponent + with EmbeddedPostgres + with ScalaFutures + with Matchers + with BeforeAndAfterAll + with BeforeAndAfterEach + with PatienceConfiguration { + + override implicit def patienceConfig: PatienceConfig = PatienceConfig(timeout = Span(2, Minutes), interval = Span(100, Millis)) + + import dbConfig.profile.api._ + val repo = new InstitutionEmailsRepository2018(dbConfig) + + override def beforeAll(): Unit = { + super.beforeAll() + Await.ready(repo.createSchema(), 30.seconds) + } + + override def afterEach(): Unit = + Await.ready(dbConfig.db.run(repo.table.delete), 30.seconds) + + override def afterAll(): Unit = { + Await.ready(repo.dropSchema(), 30.seconds) + super.afterAll() + } + + override def bootstrapSqlFile: String = "" + + "getId returns the Rep[Int]" taggedAs CustomTag in { + repo.getId(_) + } + + "deleteById deletes ids" taggedAs CustomTag in { + val test = for { + id <- dbConfig.db.run(repo.table += InstitutionEmailEntity(lei = "EXAMPLE", emailDomain = "example@domain.com")) + deletedId <- repo.deleteById(id) + } yield id shouldBe deletedId + whenReady(test)(_ => ()) + } + + "findByLei finds LEIs" taggedAs CustomTag in { + val data = InstitutionEmailEntity(lei = "EXAMPLE", emailDomain = "example@domain.com") + val test = for { + _ <- dbConfig.db.run(repo.table += data) + result <- repo.findByLei(data.lei) + } yield { + result should have length 1 + result.map(_.lei) should contain theSameElementsAs List(data.lei) + } + whenReady(test)(_ => ()) + } + + "getAllDomains finds records by domain" taggedAs CustomTag in { + val data = InstitutionEmailEntity(lei = "EXAMPLE2", emailDomain = "example@domain1.com") + val test = for { + _ <- dbConfig.db.run(repo.table += data) + result <- repo.getAllDomains() + } yield { + result should have length 1 + result.map(_.lei) should contain theSameElementsAs List(data.lei) + } + whenReady(test)(_ => ()) + } +} \ No newline at end of file diff --git a/hmda-reporting/src/test/scala/hmda/reporting/api/http/InstitutionComponentSpec.scala b/hmda-reporting/src/test/scala/hmda/reporting/api/http/InstitutionComponentSpec.scala index 75eafdac14..ebb21e509c 100644 --- a/hmda-reporting/src/test/scala/hmda/reporting/api/http/InstitutionComponentSpec.scala +++ b/hmda-reporting/src/test/scala/hmda/reporting/api/http/InstitutionComponentSpec.scala @@ -1,46 +1,48 @@ -//package hmda.reporting.repository -// -//import hmda.query.institution.InstitutionEntity -//import hmda.utils.EmbeddedPostgres -//import org.scalatest.concurrent.ScalaFutures -//import org.scalatest.{ Matchers, WordSpec } -// -//import scala.concurrent.Await -//import scala.concurrent.ExecutionContext.Implicits._ -//import scala.concurrent.duration._ -// -//class InstitutionComponentSpec extends WordSpec with EmbeddedPostgres with InstitutionComponent with ScalaFutures with Matchers { -// import dbConfig._ -// import dbConfig.profile.api._ -// -// val institutionRepo = new InstitutionRepository(dbConfig, "institutions_table") -// -// override def bootstrapSqlFile: String = "" -// -// override def beforeAll(): Unit = { -// super.beforeAll() -// Await.ready(institutionRepo.createSchema(), 30.seconds) -// } -// -// override def afterAll(): Unit = { -// Await.ready(institutionRepo.dropSchema(), 30.seconds) // just for test coverage -// super.afterAll() -// } -// -// "InstitutionRepository run-through" in { -// whenReady(db.run(institutionRepo.table += InstitutionEntity("EXAMPLE-LEI-1", activityYear = 2018, hmdaFiler = true)))(_ shouldBe 1) -// -// val test = for { -// result <- institutionRepo.findByLei("EXAMPLE-LEI-1") -// _ = result should have length 1 -// result <- institutionRepo.getAllFilers() -// _ = result should have length 1 -// _ <- institutionRepo.getFilteredFilers(Array.empty) -// _ = result should have length 1 -// _ <- institutionRepo.deleteById("EXAMPLE-LEI-1") -// _ = institutionRepo.getId(institutionRepo.table.baseTableRow) -// } yield () -// -// whenReady(test)(_ => ()) -// } -//} \ No newline at end of file +package hmda.reporting.repository + +import hmda.query.institution.InstitutionEntity +import hmda.utils.EmbeddedPostgres +import org.scalatest.concurrent.ScalaFutures +import org.scalatest.{Matchers, Tag, WordSpec} + +import scala.concurrent.Await +import scala.concurrent.ExecutionContext.Implicits._ +import scala.concurrent.duration._ + +object CustomTag extends Tag("actions-ignore") + +class InstitutionComponentSpec extends WordSpec with EmbeddedPostgres with InstitutionComponent with ScalaFutures with Matchers { + import dbConfig._ + import dbConfig.profile.api._ + + val institutionRepo = new InstitutionRepository(dbConfig, "institutions_table") + + override def bootstrapSqlFile: String = "" + + override def beforeAll(): Unit = { + super.beforeAll() + Await.ready(institutionRepo.createSchema(), 30.seconds) + } + + override def afterAll(): Unit = { + Await.ready(institutionRepo.dropSchema(), 30.seconds) // just for test coverage + super.afterAll() + } + + "InstitutionRepository run-through" taggedAs CustomTag in { + whenReady(db.run(institutionRepo.table += InstitutionEntity("EXAMPLE-LEI-1", activityYear = 2018, hmdaFiler = true)))(_ shouldBe 1) + + val test = for { + result <- institutionRepo.findByLei("EXAMPLE-LEI-1") + _ = result should have length 1 + result <- institutionRepo.getAllFilers() + _ = result should have length 1 + _ <- institutionRepo.getFilteredFilers(Array.empty) + _ = result should have length 1 + _ <- institutionRepo.deleteById("EXAMPLE-LEI-1") + _ = institutionRepo.getId(institutionRepo.table.baseTableRow) + } yield () + + whenReady(test)(_ => ()) + } +} \ No newline at end of file diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 86954abb3a..2e443ed5ec 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -8,7 +8,7 @@ object Dependencies { "Sonatype releases" at "https://oss.sonatype.org/content/repositories/releases" ) - val scalaTest = "org.scalatest" %% "scalatest" % Version.scalaTest % Test exclude ("de.flapdoodle.embed", "de.flapdoodle.embed.process") + val scalaTest = "org.scalatest" %% "scalatest" % Version.scalaTest % Test val scalaCheck = "org.scalacheck" %% "scalacheck" % Version.scalaCheck % Test val scalaMock = "org.scalamock" %% "scalamock" % Version.scalaMock % Test val logback = "ch.qos.logback" % "logback-classic" % Version.logback