Skip to content

Commit

Permalink
Force fail tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KapStorm committed Sep 5, 2024
1 parent ea72077 commit f9c8d65
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import controllers.common.PlayPostgresSpec
import net.wiringbits.config.ReCaptchaConfig
import org.scalatest.BeforeAndAfterAll

class EnvironmentConfigControllerSpec extends PlayPostgresSpec {
class EnvironmentConfigControllerSpec extends PlayPostgresSpec with BeforeAndAfterAll {
override def beforeAll(): Unit = {
throw new RuntimeException("Forcing an exception")
}

def reCaptchaConfig: ReCaptchaConfig = app.injector.instanceOf(classOf[ReCaptchaConfig])

"GET /environment-config" should {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package controllers.common
import com.dimafeng.testcontainers.PostgreSQLContainer
import com.dimafeng.testcontainers.scalatest.TestContainerForEach
import net.wiringbits.api.ApiClient
import org.scalatest.TestData
import org.scalatest.{BeforeAndAfterAll, TestData}
import org.scalatest.time.SpanSugar.convertIntToGrainOfTime
import org.scalatestplus.play.guice.GuiceOneServerPerTest
import org.testcontainers.utility.DockerImageName
Expand All @@ -15,13 +15,17 @@ import java.sql.DriverManager
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal

trait PlayPostgresSpec extends PlayAPISpec with TestContainerForEach with GuiceOneServerPerTest {
trait PlayPostgresSpec extends PlayAPISpec with TestContainerForEach with GuiceOneServerPerTest with BeforeAndAfterAll {
implicit val executionContext: ExecutionContext = ExecutionContext.Implicits.global
override implicit val patienceConfig: PatienceConfig = PatienceConfig(30.seconds, 1.second)

private val postgresImage = DockerImageName.parse("postgres:13")
override val containerDef: PostgreSQLContainer.Def = PostgreSQLContainer.Def(dockerImageName = postgresImage)

override protected def afterAll(): Unit = {
throw new RuntimeException("Forcing an exception")
}

/** Loads configuration disabling evolutions on default database.
*
* This allows to not write a custom application.conf for testing and ensure play evolutions are disabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import net.wiringbits.config.ReCaptchaConfig
import net.wiringbits.models.{ReCaptchaSecret, ReCaptchaSiteKey}
import org.mockito.ArgumentMatchers
import org.mockito.Mockito.*
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures.*
import org.scalatest.matchers.must.Matchers.*
import org.scalatest.wordspec.AnyWordSpec
Expand All @@ -16,13 +17,17 @@ import play.api.libs.ws.{BodyWritable, WSClient, WSRequest, WSResponse}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

class ReCaptchaApiSpec extends AnyWordSpec with MockitoSugar {
class ReCaptchaApiSpec extends AnyWordSpec with MockitoSugar with BeforeAndAfterAll {
private val ws = mock[WSClient]
private val request = mock[WSRequest]
private val response = mock[WSResponse]
private val config = ReCaptchaConfig(ReCaptchaSecret("test"), ReCaptchaSiteKey("test"))
private val api = new ReCaptchaApi(config, ws)

override protected def beforeAll(): Unit = {
throw new RuntimeException("Forcing an exception")
}

"verify" should {
"detect successful responses" in {
mockRequest(request, response)(Json.obj("success" -> true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.wiringbits.core

import net.wiringbits.config.UserTokensConfig
import net.wiringbits.repositories.*
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures.*
import org.scalatest.wordspec.AnyWordSpec
import utils.Executors
Expand All @@ -10,10 +11,14 @@ import java.time.Clock
import scala.concurrent.ExecutionContext
import scala.concurrent.duration.DurationInt

trait RepositorySpec extends AnyWordSpec with PostgresSpec {
trait RepositorySpec extends AnyWordSpec with PostgresSpec with BeforeAndAfterAll {
implicit val patienceConfig: PatienceConfig = PatienceConfig(30.seconds, 1.second)
implicit val executionContext: ExecutionContext = Executors.globalEC

override protected def beforeAll(): Unit = {
throw new RuntimeException("Forcing an exception")
}

def withRepositories[T](clock: Clock = Clock.systemUTC)(runTest: RepositoryComponents => T): T = withDatabase { db =>
val users = new UsersRepository(db, UserTokensConfig(1.hour, 1.hour, "secret"))(Executors.databaseEC, clock)
val userTokens = new UserTokensRepository(db)(Executors.databaseEC)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package net.wiringbits.forms

import net.wiringbits.common.models.{Captcha, Email}
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.must.Matchers.*
import org.scalatest.wordspec.AnyWordSpec

class ResendVerifyEmailFormDataSpec extends AnyWordSpec {
class ResendVerifyEmailFormDataSpec extends AnyWordSpec with BeforeAndAfterAll {
override protected def afterAll(): Unit = {
throw new RuntimeException("Forcing an exception")
}

private val initialForm = ResendVerifyEmailFormData.initial(
texts = ResendVerifyEmailFormData.Texts("Captcha message"),
emailLabel = "Email"
Expand Down

0 comments on commit f9c8d65

Please sign in to comment.