Skip to content

Commit

Permalink
DDCE-5495 Remove welsh toggle and use request to handle language swit…
Browse files Browse the repository at this point in the history
…ch in different modes, update README and dependencies (#530)

DDCE-5495 Remove welsh toggle and use request to handle language switch in different modes, update README and dependencies

DDCE-5495 add fullstop

DDCE-5495 Remove welsh toggle and use request to handle language switch in different modes, update README and dependencies

DDCE-5495 Remove welsh toggle and use request to handle language switch in different modes, update README and dependencies
  • Loading branch information
Taiwo-AB authored Jun 3, 2024
1 parent bf4cede commit c8c147d
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 129 deletions.
79 changes: 50 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,93 @@
# merchandise-in-baggage-frontend

## Who uses the repo/service
This service is for business travellers carrying commercial goods for both import or export.
It has two modes; Public Facing and Assisted Digital i.e. Admin which requires stride login.

Business travellers carrying commercial goods for both import or export.
## Starting services

## How to start the service locally
To start the required services via [service manager](https://github.com/hmrc/sm2), run the command:

`sbt run` This will only start the service as standalone but unable to interact with any other services including Backend and Database

To load all related services:

```bash
sm2 --start MERCHANDISE_IN_BAGGAGE_ALL
```shell
sm2 --start MERCHANDISE_IN_BAGGAGE_ALL --appendArgs '{"PAYMENTS_PROCESSOR":["-Dmicroservice.services.merchandise-in-baggage.port=8280"]}'
```

This will start all the required services to complete a journey
To start the journey in public facing mode, browse the urls below for import and export journeys respectively:

`local url` http://localhost:8281/declare-commercial-goods/start-import
`local url` http://localhost:8281/declare-commercial-goods/start-export
* `Import local url`: http://localhost:8281/declare-commercial-goods/start-import
* `Export local url`: http://localhost:8281/declare-commercial-goods/start-export

## How to run tests
To start the journey in admin mode, browse the url:

`./run_all_tests` will run all the tests, including unit, UI and integration tests.
* `Import or Export Choice local url`: http://localhost:8281/declare-commercial-goods/import-export-choice

## UI Tests Repo
The stride roles for the admin mode are `tps_payment_taker_call_handler,digital_mib_call_handler`.

See the companion Repository https://github.com/hmrc/merchandise-in-baggage-ui-tests for UI tests using this repo.
## Running Tests

1: To run all mods services and stop the frontend.
To run unit tests, integration tests, a11y tests, scalastyle, scalafmt, coverage and check dependencies, execute the script:

```bash
sm2 --start MERCHANDISE_IN_BAGGAGE_ALL -wait 30 && sm2 --stop MERCHANDISE_IN_BAGGAGE_FRONTEND
./run_all_tests.sh
```

2: Start this service locally with the correct flags.
### Running UI Tests

To run the UI tests against a branch with changes made in this repo, follow the steps below:

* Start all required services and stop this service by running the commands:

```shell
sm2 --start MERCHANDISE_IN_BAGGAGE_ALL --appendArgs '{"PAYMENTS_PROCESSOR":["-Dmicroservice.services.merchandise-in-baggage.port=8280"]}'
sm2 --stop MERCHANDISE_IN_BAGGAGE_FRONTEND
```

* Start this service locally with the correct flags by executing the script:

```bash
./run-locally.sh
```

3: Run the UI tests
* Run the UI tests which can be found [here](https://github.com/hmrc/merchandise-in-baggage-ui-tests).

OR

Perform: `sm2 --start MERCHANDISE_IN_BAGGAGE_ALL` to run all mods services, and then separately run the UI tests.
(won't test the branch)
To run the UI tests without any changes made in this repo, follow the steps below:

* Start all required services via [service manager](https://github.com/hmrc/sm2) by running the command:

```shell
sm2 --start MERCHANDISE_IN_BAGGAGE_ALL --appendArgs '{"PAYMENTS_PROCESSOR":["-Dmicroservice.services.merchandise-in-baggage.port=8280"]}'
```

* Start this service locally with the correct flags by executing the script:

```bash
./run-locally.sh
```

* Run the UI tests which can be found [here](https://github.com/hmrc/merchandise-in-baggage-ui-tests).

## Accessibility Tests
### Running Accessibility Tests

### Prerequisites
Have node installed on your machine
#### Prerequisites
Have node installed on your machine.

### Execute tests
#### Execute tests
To run the tests locally, simply run:
```bash
sbt clean A11y/test
```

## How to enable 'Admin Mode'
## Enabling 'Admin Mode'

This service is built to accept traffic from the `admin.tax.service.gov.uk` domain as well for assisted digital journeys.
The service can detect where the traffic has come from by inspecting the `x-forwarded-host` header, this is done in
`auth/StrideAuthAction.scala` - this will change some content on some of the pages and also alters the payment journey.

When testing locally, you can enable a filter which will add a header to each request to simulate it coming from the admin domain.

This can be done by updating the `adminJourneyFilter.enabled` flag in application.conf to be `true` or alternatively passing it in as
a system property e.g. `sbt run -DadminJourneyFilter.enabled=true`
This can be done by updating the `adminJourneyFilter.enabled` flag in `application.conf` or `./run-locally.sh` to be `true`
or alternatively passing it in as a system property e.g. `sbt run -DadminJourneyFilter.enabled=true`.

## License

Expand Down
2 changes: 0 additions & 2 deletions app/uk/gov/hmrc/merchandiseinbaggage/config/AppConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class AppConfig @Inject() (
s"$url/$serviceIdentifier"
}

lazy val languageTranslationEnabled: Boolean = config.get[Boolean]("features.welsh-translation")

private lazy val mibBaseUrl: String = "/declare-commercial-goods"
lazy val mibDeclarationsUrl: String = s"$mibBaseUrl/declarations"
lazy val mibCalculationsUrl: String = s"$mibBaseUrl/calculations"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,25 @@
package uk.gov.hmrc.merchandiseinbaggage.controllers

import com.google.inject.Inject
import play.api.i18n.{I18nSupport, Lang, MessagesApi}
import play.api.i18n.{I18nSupport, Lang}
import play.api.mvc._
import uk.gov.hmrc.merchandiseinbaggage.config.AppConfig
import uk.gov.hmrc.merchandiseinbaggage.auth.StrideAuthAction
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController

import scala.concurrent.Future

class LanguageSwitchController @Inject() (
appConfig: AppConfig,
override implicit val messagesApi: MessagesApi,
val controllerComponents: MessagesControllerComponents
val controllerComponents: MessagesControllerComponents,
strideAction: StrideAuthAction
) extends FrontendBaseController
with I18nSupport {

private def fallbackURL: String = routes.GoodsDestinationController.onPageLoad.url

def switchToLanguage(language: String): Action[AnyContent] = Action { implicit request =>
val languageToUse =
if (appConfig.languageTranslationEnabled) {
Lang(language)
} else {
Lang("en")
}
def switchToLanguage(language: String): Action[AnyContent] = strideAction.async { implicit request =>
val languageToUse = Lang(language)

val redirectURL = request.headers.get(REFERER).getOrElse(fallbackURL)
Redirect(redirectURL).withLang(languageToUse)
Future.successful(Redirect(redirectURL).withLang(languageToUse))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
languageSelection: components.languageSelection,
hmrcReportTechnicalIssueHelper: HmrcReportTechnicalIssueHelper,
hmrcTrackingConsentSnippet: HmrcTrackingConsentSnippet,
appConfig: AppConfig,
hmrcStandardFooter: HmrcStandardFooter,
govukSkipLink: GovukSkipLink,
siteHeader: components.siteHeader,
Expand All @@ -47,7 +46,7 @@
maybeBackButtonUrl: Option[play.api.mvc.Call],
declarationType: Option[DeclarationType],
isAssistedDigital: Boolean
)(contentBlock: Html)(implicit messages: Messages, appConfig: AppConfig, request: Request[_])
)(contentBlock: Html)(implicit messages: Messages, request: Request[_])

@headDefault = {
@headBlock
Expand Down Expand Up @@ -87,7 +86,7 @@
}
}

@if(!isAssistedDigital && appConfig.languageTranslationEnabled) {
@if(!isAssistedDigital) {
@languageSelection()
}

Expand Down
18 changes: 1 addition & 17 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import uk.gov.hmrc.DefaultBuildSettings.itSettings

val appName = "merchandise-in-baggage-frontend"

ThisBuild / scalaVersion := "2.13.13"
ThisBuild / scalaVersion := "2.13.14"
ThisBuild / majorVersion := 0

lazy val microservice = Project(appName, file("."))
Expand All @@ -25,22 +25,6 @@ lazy val it = project
.dependsOn(microservice % "test->test") // the "test->test" allows reusing test code and test dependencies
.settings(itSettings())
.settings(libraryDependencies ++= AppDependencies.itDependencies)
.settings(scalacOptionsSettings)

lazy val scalacOptionsSettings: Seq[Setting[?]] = Seq(
scalacOptions ++= Seq(
"-Wconf:src=routes/.*:s",
"-Wconf:cat=unused-imports&src=views/.*:s"
),
scalacOptions ~= { opts =>
opts.filterNot(
Set(
"-Xfatal-warnings",
"-Ywarn-value-discard"
)
)
}
)

addCommandAlias("scalafmtAll", "all scalafmtSbt scalafmt Test/scalafmt A11y/scalafmt it/Test/scalafmt")
addCommandAlias("scalastyleAll", "all scalastyle Test/scalastyle A11y/scalastyle it/Test/scalastyle")
18 changes: 0 additions & 18 deletions conf/application-json-logger.xml

This file was deleted.

13 changes: 0 additions & 13 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ adminJourneyFilter.enabled = false
# Additional play modules can be added here
play.modules.enabled += "uk.gov.hmrc.merchandiseinbaggage.config.ModuleBindings"

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
# Not set here so that MDTP frontends share the same secret key in the local environment
# (see common.conf in frontend-bootstrap).
# In server environments the secret comes from app-config-common
# play.http.secret.key="EQdp1FhTyjA5jSMiALAVwLPI0HCPWL8QjbHhI1KiLjZaGcTV8tHl7t40Ewpam3tW"

microservice {
services {
address-lookup-frontend {
Expand Down Expand Up @@ -125,10 +116,6 @@ stride {

play.i18n.langs = ["en", "cy"]

features {
welsh-translation: true
}

tps-navigation {
back = "http://localhost:8281/declare-commercial-goods/check-your-answers"
reset = "http://localhost:8281/declare-commercial-goods/import-export-choice"
Expand Down
10 changes: 0 additions & 10 deletions conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
</encoder>
</appender>

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

<appender name="ACCESS_LOG_FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/access.log</file>
<encoder>
Expand All @@ -39,10 +33,6 @@
<appender-ref ref="ACCESS_LOG_FILE" />
</logger>

<logger name="com.ning.http.client.providers.netty" additivity="false">
<appender-ref ref="STDOUT_IGNORE_NETTY" />
</logger>

<logger name="com.google.inject" level="INFO"/>

<logger name="uk.gov" level="INFO"/>
Expand Down
6 changes: 3 additions & 3 deletions project/AppDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ object AppDependencies {

private val bootstrapVersion = "8.6.0"

val compile: Seq[ModuleID] = Seq(
private val compile: Seq[ModuleID] = Seq(
"uk.gov.hmrc" %% "bootstrap-frontend-play-30" % bootstrapVersion,
"uk.gov.hmrc" %% "play-frontend-hmrc-play-30" % "8.5.0",
"uk.gov.hmrc.mongo" %% "hmrc-mongo-play-30" % "1.9.0",
"com.beachape" %% "enumeratum-play" % "1.8.0",
"org.webjars.npm" % "accessible-autocomplete" % "2.0.4",
"com.softwaremill.quicklens" %% "quicklens" % "1.9.7",
"org.typelevel" %% "cats-core" % "2.10.0",
"org.typelevel" %% "cats-core" % "2.12.0",
"io.github.samueleresca" %% "pekko-quartz-scheduler" % "1.2.0-pekko-1.0.x"
)

val test: Seq[ModuleID] = Seq(
private val test: Seq[ModuleID] = Seq(
"uk.gov.hmrc" %% "bootstrap-test-play-30" % bootstrapVersion,
"org.scalatestplus" %% "scalacheck-1-17" % "3.2.18.0",
"org.mockito" %% "mockito-scala-scalatest" % "1.17.31"
Expand Down
2 changes: 1 addition & 1 deletion project/CodeCoverageSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object CodeCoverageSettings {

val settings: Seq[Setting[?]] = Seq(
coverageExcludedFiles := excludedPackages.mkString(";"),
coverageMinimumStmtTotal := 90,
coverageMinimumStmtTotal := 91,
coverageFailOnMinimum := true,
coverageHighlighting := true
)
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.7
sbt.version=1.9.9
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefact
Resolver.ivyStylePatterns
)

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.21.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.22.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.5.0")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.3")
addSbtPlugin("io.github.irundaia" % "sbt-sassify" % "1.5.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "1.0.0" exclude ("org.scala-lang.modules", "scala-xml_2.12"))
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.12")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
addSbtPlugin("uk.gov.hmrc" % "sbt-accessibility-linter" % "0.39.0")
2 changes: 1 addition & 1 deletion run_all_tests.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

sbt clean compile scalafmtAll scalastyleAll coverage Test/test coverageOff coverageReport dependencyUpdates
sbt clean compile scalafmtAll scalastyleAll coverage test it/test coverageOff coverageReport A11y/test dependencyUpdates
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ class AppConfigSpec extends BaseSpecWithApplication {

appConfig.feedbackUrl mustBe "http://localhost:9514/feedback/mib"

appConfig.languageTranslationEnabled mustBe true

appConfig.mibDeclarationsUrl mustBe "/declare-commercial-goods/declarations"
appConfig.mibCalculationsUrl mustBe "/declare-commercial-goods/calculations"
appConfig.mibAmendsPlusExistingCalculationsUrl mustBe "/declare-commercial-goods/amend-calculations"
Expand Down
Loading

0 comments on commit c8c147d

Please sign in to comment.