Skip to content

Commit

Permalink
DDCE-5386 - Add more html content tests (#547)
Browse files Browse the repository at this point in the history
* DDCE-5386 - Add more html content tests

* DDCE-5386 - cleanup unused messagesApi object

* DDCE-5386 - added new messagesSpec
  • Loading branch information
frikit authored Dec 23, 2024
1 parent 852482f commit 8fa7d6d
Show file tree
Hide file tree
Showing 41 changed files with 325 additions and 156 deletions.
2 changes: 0 additions & 2 deletions app/uk/gov/hmrc/merchandiseinbaggage/service/Auditor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package uk.gov.hmrc.merchandiseinbaggage.service

import play.api.Logging
import play.api.i18n.MessagesApi
import play.api.libs.json.Json.toJson
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.merchandiseinbaggage.model.api.Declaration
Expand All @@ -30,7 +29,6 @@ import scala.util.control.NonFatal

trait Auditor extends Logging {
val auditConnector: AuditConnector
val messagesApi: MessagesApi

def auditDeclaration(declaration: Declaration)(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[Unit] = {
val eventType = "DeclarationPaymentAttempted"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,23 @@
package uk.gov.hmrc.merchandiseinbaggage.service

import com.google.inject.Singleton
import play.api.i18n.MessagesApi
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.merchandiseinbaggage.config.AppConfig
import uk.gov.hmrc.merchandiseinbaggage.connectors.PaymentConnector
import uk.gov.hmrc.merchandiseinbaggage.controllers.routes
import uk.gov.hmrc.merchandiseinbaggage.model.api.Declaration

import javax.inject.Inject
import uk.gov.hmrc.merchandiseinbaggage.model.api.calculation.CalculationResults
import uk.gov.hmrc.merchandiseinbaggage.model.api.payapi.PayApiRequest

import scala.concurrent.{ExecutionContext, Future}
import uk.gov.hmrc.merchandiseinbaggage.utils.DataModelEnriched._
import uk.gov.hmrc.play.audit.http.connector.AuditConnector

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}

@Singleton
class PaymentService @Inject() (
connector: PaymentConnector,
val auditConnector: AuditConnector,
val messagesApi: MessagesApi
val auditConnector: AuditConnector
)(implicit ec: ExecutionContext, appConfig: AppConfig)
extends Auditor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,23 @@

package uk.gov.hmrc.merchandiseinbaggage.service

import javax.inject.{Inject, Singleton}
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.merchandiseinbaggage.config.AppConfig
import uk.gov.hmrc.merchandiseinbaggage.connectors.TpsPaymentsBackendConnector
import uk.gov.hmrc.merchandiseinbaggage.model.api.Declaration
import uk.gov.hmrc.merchandiseinbaggage.model.api.calculation.CalculationResults
import uk.gov.hmrc.merchandiseinbaggage.model.api.payapi.PayApiResponse
import uk.gov.hmrc.merchandiseinbaggage.model.api.tpspayments.TpsPaymentsRequest
import uk.gov.hmrc.merchandiseinbaggage.utils.DataModelEnriched._
import uk.gov.hmrc.play.audit.http.connector.AuditConnector

import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
import play.api.i18n.MessagesApi
import uk.gov.hmrc.merchandiseinbaggage.model.api.payapi.PayApiResponse
import uk.gov.hmrc.play.audit.http.connector.AuditConnector

@Singleton
class TpsPaymentsService @Inject() (
connector: TpsPaymentsBackendConnector,
val auditConnector: AuditConnector,
val messagesApi: MessagesApi
val auditConnector: AuditConnector
)(implicit ec: ExecutionContext, appConfig: AppConfig)
extends Auditor {

Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions conf/messages.cy
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,11 @@ declarationConfirmation.ul.1.1 = (dim byd i’w ddatgan) wrth y tollau
declarationConfirmation.ul.2 = mynd â’r datganiad a anfonwyd at y cyfeiriad a roddwyd
declarationConfirmation.ul.3 = mynd â’r derbynebau neu’r anfonebau ar gyfer yr holl nwyddau a ddatganwyd
declarationConfirmation.ul.4 = ewch â thystiolaeth sy’n dangos ble y cafodd y nwyddau o’r UE eu cynhyrchu
declarationConfirmation.date = Dyddiad y datganiad
declarationConfirmation.email = Rydym wedi anfon e-bost cadarnhau i’r cyfeiriad a roddwyd.
declarationConfirmation.makeAnotherDeclaration = Gwneud datganiad newydd
declarationConfirmation.changeDeclaration.label = Ychwanegu nwyddau i ddatganiad sy’n bodoli eisoes
declarationConfirmation.feedbackSurvey = Beth oedd eich barn am y gwasanaeth hwn?
declarationConfirmation.feedbackSurvey.info = (mae'n cymryd 30 eiliad)
declarationConfirmation.feedbackSurvey.info = (maen cymryd 30 eiliad)
declarationConfirmation.printOrSave.label = Argraffu neu gadw copi o’r dudalen hon
declarationConfirmation.declaration.label = Datganiad
declarationConfirmation.declaration.text = Nwyddau masnachol sy’n cael eu cario mewn bagiau neu gerbydau bach
Expand Down Expand Up @@ -1106,4 +1105,4 @@ title.august = Awst
title.september = Medi
title.october = Hydref
title.november = Tachwedd
title.december = Rhagfyr
title.december = Rhagfyr
4 changes: 2 additions & 2 deletions project/AppDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ object AppDependencies {

private val compile: Seq[ModuleID] = Seq(
"uk.gov.hmrc" %% "bootstrap-frontend-play-30" % bootstrapVersion,
"uk.gov.hmrc" %% "play-frontend-hmrc-play-30" % "11.7.0",
"uk.gov.hmrc" %% "play-frontend-hmrc-play-30" % "11.8.0",
"uk.gov.hmrc.mongo" %% "hmrc-mongo-play-30" % "2.3.0",
"com.beachape" %% "enumeratum-play" % "1.8.2",
"org.webjars.npm" % "accessible-autocomplete" % "3.0.0",
"com.softwaremill.quicklens" %% "quicklens" % "1.9.10",
"com.softwaremill.quicklens" %% "quicklens" % "1.9.11",
"org.typelevel" %% "cats-core" % "2.12.0",
"io.github.samueleresca" %% "pekko-quartz-scheduler" % "1.2.2-pekko-1.0.x"
)
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefact
Resolver.ivyStylePatterns
)

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.22.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.24.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.5.0")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.5")
addSbtPlugin("io.github.irundaia" % "sbt-sassify" % "1.5.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.2")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
11 changes: 10 additions & 1 deletion test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<root level="OFF">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>
%date{ISO8601} level=[%level] logger=[%logger] thread=[%thread] message=[%message] %replace(exception=[%xException]){'^exception=\[\]$',''}%n
</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
8 changes: 5 additions & 3 deletions test/uk/gov/hmrc/merchandiseinbaggage/BaseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.scalatest.matchers.must.Matchers
import org.scalatest.time.{Milliseconds, Seconds, Span}
import org.scalatest.wordspec.AnyWordSpec
import org.scalatestplus.play.guice.GuiceOneServerPerSuite
import play.api.i18n.{Messages, MessagesApi}
import play.api.i18n.{Lang, Messages, MessagesApi}
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.inject.{ApplicationLifecycle, Injector}
import play.api.mvc.{AnyContentAsEmpty, DefaultActionBuilder}
Expand Down Expand Up @@ -56,10 +56,12 @@ trait BaseSpecWithApplication extends BaseSpec with GuiceOneServerPerSuite with

lazy val defaultBuilder: DefaultActionBuilder = injector.instanceOf[DefaultActionBuilder]
implicit lazy val appConfig: AppConfig = injector.instanceOf[AppConfig]
def messagesApi: MessagesApi = injector.instanceOf[MessagesApi]
lazy val fakeRequest: FakeRequest[AnyContentAsEmpty.type] =
FakeRequest("", "").withCSRFToken.asInstanceOf[FakeRequest[AnyContentAsEmpty.type]]
implicit val messages: Messages = messagesApi.preferred(fakeRequest)
lazy val messagesApi: MessagesApi = injector.instanceOf[MessagesApi]
private val lang: Lang = Lang("en")
private val cyLang: Lang = Lang("cy")
implicit val messages: Messages = injector.instanceOf[MessagesApi].preferred(Seq(lang, cyLang))
implicit val headerCarrier: HeaderCarrier = HeaderCarrier()

lazy val injector: Injector = app.injector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class AgentDetailsControllerSpec extends DeclarationJourneyControllerSpec {
val result = contentAsString(eventualResult)

status(eventualResult) mustBe OK
result must include(messageApi("agentDetails.title"))
result must include(messageApi("agentDetails.heading"))
result must include(messages("agentDetails.title"))
result must include(messages("agentDetails.heading"))
}
}

Expand Down Expand Up @@ -93,8 +93,8 @@ class AgentDetailsControllerSpec extends DeclarationJourneyControllerSpec {
val result = contentAsString(eventualResult)

status(eventualResult) mustBe BAD_REQUEST
result must include(messageApi("error.summary.title"))
result must include(messageApi(s"agentDetails.title"))
result must include(messageApi(s"agentDetails.heading"))
result must include(messages("error.summary.title"))
result must include(messages(s"agentDetails.title"))
result must include(messages(s"agentDetails.heading"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class CannotAccessPageControllerSpec extends DeclarationJourneyControllerSpec wi
val result = contentAsString(eventualResult)

status(eventualResult) mustBe OK
result must include(messageApi(s"invalidRequest.li1"))
result must include(messageApi(s"invalidRequest.li2"))
result must include(messageApi(s"invalidRequest.$importOrExport.restart"))
result must include(messages(s"invalidRequest.li1"))
result must include(messages(s"invalidRequest.li2"))
result must include(messages(s"invalidRequest.$importOrExport.restart"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class CannotUseServiceControllerSpec extends DeclarationJourneyControllerSpec {
val result = contentAsString(eventualResult)

status(eventualResult) mustBe OK
result must include(messageApi(s"cannotUseService.$importOrExport.title"))
result must include(messageApi(s"cannotUseService.$importOrExport.heading"))
result must include(messageApi(s"cannotUseService.$importOrExport.p1"))
result must include(messages(s"cannotUseService.$importOrExport.title"))
result must include(messages(s"cannotUseService.$importOrExport.heading"))
result must include(messages(s"cannotUseService.$importOrExport.p1"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class CannotUseServiceIrelandControllerSpec extends DeclarationJourneyController
val result = contentAsString(eventualResult)

status(eventualResult) mustBe OK
result must include(messageApi(s"cannotUseServiceIreland.title"))
result must include(messageApi(s"cannotUseServiceIreland.heading"))
result must include(messageApi(s"cannotUseServiceIreland.p1"))
result must include(messageApi(s"cannotUseServiceIreland.p1.$importOrExport.a.text"))
result must include(messages(s"cannotUseServiceIreland.title"))
result must include(messages(s"cannotUseServiceIreland.heading"))
result must include(messages(s"cannotUseServiceIreland.p1"))
result must include(messages(s"cannotUseServiceIreland.p1.$importOrExport.a.text"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CheckYourAnswersAmendHandlerSpec extends DeclarationJourneyControllerSpec
val eventualResult = amendHandler().onPageLoad(journey, amendment, YesNo.No)

status(eventualResult) mustBe OK
contentAsString(eventualResult) must include(messageApi("checkYourAnswers.amend.title"))
contentAsString(eventualResult) must include(messages("checkYourAnswers.amend.title"))
}

s"will calculate tax and send payment request to TPS for $importOrExport" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CheckYourAnswersControllerSpec extends DeclarationJourneyControllerSpec {
new CheckYourAnswersNewHandler(
mockMibService,
mockTpsService,
new PaymentService(testPaymentConnector, auditConnector, messagesApi),
new PaymentService(testPaymentConnector, auditConnector),
mibConnector,
importView,
exportView
Expand All @@ -77,7 +77,7 @@ class CheckYourAnswersControllerSpec extends DeclarationJourneyControllerSpec {
actionBuilder,
mockMibService,
mockTpsService,
new PaymentService(testPaymentConnector, auditConnector, messagesApi),
new PaymentService(testPaymentConnector, auditConnector),
amendImportView,
amendExportView
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CheckYourAnswersNewHandlerSpec extends DeclarationJourneyControllerSpec {
new CheckYourAnswersNewHandler(
stubbedCalculation(paymentCalcs),
mockTpsPaymentsService,
new PaymentService(testPaymentConnector, auditConnector, messagesApi),
new PaymentService(testPaymentConnector, auditConnector),
testMibConnector,
importView,
exportView
Expand All @@ -95,7 +95,7 @@ class CheckYourAnswersNewHandlerSpec extends DeclarationJourneyControllerSpec {
val result = newHandler().onPageLoad(declaration, YesNo.Yes)

status(result) mustBe OK
contentAsString(result) must include(messageApi("checkYourAnswers.title"))
contentAsString(result) must include(messages("checkYourAnswers.title"))
}

s"return 303 for goods over threshold for $importOrExport" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class CustomsAgentControllerSpec extends DeclarationJourneyControllerSpec {
val result = contentAsString(eventualResult)

status(eventualResult) mustBe OK
result must include(messageApi("customsAgent.title"))
result must include(messageApi("customsAgent.heading"))
result must include(messageApi("customsAgent.hint"))
result must include(messages("customsAgent.title"))
result must include(messages("customsAgent.heading"))
result must include(messages("customsAgent.hint"))
}
}

Expand Down Expand Up @@ -93,9 +93,9 @@ class CustomsAgentControllerSpec extends DeclarationJourneyControllerSpec {
val result = contentAsString(eventualResult)

status(eventualResult) mustBe BAD_REQUEST
result must include(messageApi("error.summary.title"))
result must include(messageApi("customsAgent.title"))
result must include(messageApi("customsAgent.heading"))
result must include(messages("error.summary.title"))
result must include(messages("customsAgent.title"))
result must include(messages("customsAgent.heading"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ class DeclarationConfirmationControllerSpec extends DeclarationJourneyController
givenPersistedDeclarationIsFound(exportJourney.declarationIfRequiredAndComplete.get, id)

val eventualResult = controller.onPageLoad()(request)
val result = contentAsString(eventualResult)

status(eventualResult) mustBe OK
result must include(messages("declarationConfirmation.title"))
result must include(messages("declarationConfirmation.banner.title"))

import exportJourney._
val resetJourney = DeclarationJourney(sessionId, declarationType, isAssistedDigital = false)
Expand Down Expand Up @@ -86,7 +90,11 @@ class DeclarationConfirmationControllerSpec extends DeclarationJourneyController
givenPersistedDeclarationIsFound(declarationWithNoPaymentRequired, id)

val eventualResult = controller.onPageLoad()(request)
val result = contentAsString(eventualResult)

status(eventualResult) mustBe OK
result must include(messages("declarationConfirmation.title"))
result must include(messages("declarationConfirmation.banner.title"))

import importJourney._
val resetJourney = DeclarationJourney(sessionId, declarationType, isAssistedDigital = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class ExciseAndRestrictedGoodsControllerSpec extends DeclarationJourneyControlle
val result = contentAsString(eventualResult)

status(eventualResult) mustBe OK
result must include(messageApi(s"exciseAndRestrictedGoods.$importOrExport.title"))
result must include(messageApi(s"exciseAndRestrictedGoods.$importOrExport.heading"))
result must include(messageApi("exciseAndRestrictedGoods.details"))
result must include(messages(s"exciseAndRestrictedGoods.$importOrExport.title"))
result must include(messages(s"exciseAndRestrictedGoods.$importOrExport.heading"))
result must include(messages("exciseAndRestrictedGoods.details"))
}
}

Expand Down Expand Up @@ -92,9 +92,9 @@ class ExciseAndRestrictedGoodsControllerSpec extends DeclarationJourneyControlle
val result = contentAsString(eventualResult)

status(eventualResult) mustBe BAD_REQUEST
result must include(messageApi("error.summary.title"))
result must include(messageApi(s"exciseAndRestrictedGoods.$importOrExport.title"))
result must include(messageApi(s"exciseAndRestrictedGoods.$importOrExport.heading"))
result must include(messages("error.summary.title"))
result must include(messages(s"exciseAndRestrictedGoods.$importOrExport.title"))
result must include(messages(s"exciseAndRestrictedGoods.$importOrExport.heading"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class GoodsDestinationControllerSpec extends DeclarationJourneyControllerSpec wi
val result = contentAsString(eventualResult)

status(eventualResult) mustBe OK
result must include(messageApi(s"goodsDestination.$importOrExport.title"))
result must include(messageApi(s"goodsDestination.$importOrExport.heading"))
result must include(messageApi("goodsDestination.NorthernIreland"))
result must include(messageApi("goodsDestination.GreatBritain"))
result must include(messages(s"goodsDestination.$importOrExport.title"))
result must include(messages(s"goodsDestination.$importOrExport.heading"))
result must include(messages("goodsDestination.NorthernIreland"))
result must include(messages("goodsDestination.GreatBritain"))

result must include(messageApi(s"service.name.${importOrExport.entryName}.a.href"))
result must include(messages(s"service.name.${importOrExport.entryName}.a.href"))
}
}

Expand Down Expand Up @@ -97,7 +97,7 @@ class GoodsDestinationControllerSpec extends DeclarationJourneyControllerSpec wi
val result = contentAsString(eventualResult)

status(eventualResult) mustBe BAD_REQUEST
result must include(messageApi("error.summary.title"))
result must include(messages("error.summary.title"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class GoodsInVehicleControllerSpec extends DeclarationJourneyControllerSpec {
val result = contentAsString(eventualResult)

status(eventualResult) mustBe BAD_REQUEST
result must include(messageApi("error.summary.title"))
result must include(messages("error.summary.title"))
result must include(messages(s"goodsInVehicle.$importOrExport.title"))
result must include(messages(s"goodsInVehicle.$importOrExport.heading"))
}
Expand Down
Loading

0 comments on commit 8fa7d6d

Please sign in to comment.