Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ This should start this service and any dependent services.

Once the script has finished, the service will be available on http://localhost:9618/api-test-user

For CTC users, the service will be available on http://localhost:9618/api-test-user/ctc


## Running tests

Expand Down
1 change: 1 addition & 0 deletions app/uk/gov/hmrc/testuser/config/ApplicationConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ class ApplicationConfig @Inject() (config: Configuration) {
lazy val govukHelp: String = urlFooterConfig.getString("govukHelp")
lazy val accessibility: String = urlFooterConfig.getString("accessibility")
lazy val feedbackSurveyUrl = feedbackSurveyConfig.getString("surveyUrl")
lazy val ctcLoginUrl = config.getOptional[String]("ctc-login-url")
}
24 changes: 22 additions & 2 deletions app/uk/gov/hmrc/testuser/controllers/TestUserController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import uk.gov.hmrc.testuser.config.ApplicationConfig
import uk.gov.hmrc.testuser.connectors.ApiPlatformTestUserConnector
import uk.gov.hmrc.testuser.models.{NavLink, UserTypes}
import uk.gov.hmrc.testuser.services.{NavigationService, TestUserService}
import uk.gov.hmrc.testuser.views.html.{CreateTestUserView, TestUserView}
import uk.gov.hmrc.testuser.views.html.{CreateTestUserView, CreateTestUserViewCtc, TestUserView, TestUserViewCtc}

class TestUserController @Inject() (
override val messagesApi: MessagesApi,
Expand All @@ -41,7 +41,9 @@ class TestUserController @Inject() (
apiPlatformTestUserConnector: ApiPlatformTestUserConnector,
messagesControllerComponents: MessagesControllerComponents,
createTestUser: CreateTestUserView,
testUser: TestUserView
createTestUserCtc: CreateTestUserViewCtc,
testUser: TestUserView,
testUserCtc: TestUserViewCtc
)(implicit val ec: ExecutionContext, config: ApplicationConfig)
extends FrontendController(messagesControllerComponents)
with I18nSupport
Expand All @@ -52,6 +54,10 @@ class TestUserController @Inject() (
Future.successful(Ok(createTestUser(navLinks, CreateUserForm.form)))
}

def showCreateUserPageCtc() = headerNavigation { implicit request => navLinks =>
Future.successful(Ok(createTestUserCtc(navLinks, CreateUserForm.form)))
}

def createUser() = headerNavigation { implicit request => navLinks =>
def validForm(form: CreateUserForm) = {
UserTypes.from(form.userType.getOrElse("")) match {
Expand All @@ -66,6 +72,20 @@ class TestUserController @Inject() (

CreateUserForm.form.bindFromRequest().fold(invalidForm, validForm)
}
def createUserCtc() = headerNavigation { implicit request => navLinks =>
def validForm(form: CreateUserForm) = {
UserTypes.from(form.userType.getOrElse("")) match {
case Some(uType) => testUserService.createUserCtc(uType) map (user => Ok(testUserCtc(navLinks, user)))
case _ => Future.failed(new BadRequestException("Invalid request"))
}
}

def invalidForm(invalidForm: Form[CreateUserForm]) = {
Future.successful(BadRequest(createTestUserCtc(navLinks, invalidForm)))
}

CreateUserForm.form.bindFromRequest().fold(invalidForm, validForm)
}

private def headerNavigation(f: Request[AnyContent] => Seq[NavLink] => Future[Result]): Action[AnyContent] = {
Action.async { implicit request =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ object FieldDefinitions {
FieldDefinition("individualDetails", "Individual Details", Seq()),
FieldDefinition("groupIdentifier", "Group Identifier", Seq(INDIVIDUAL, ORGANISATION))
)

def getCtc(): Seq[FieldDefinition] = Seq(
FieldDefinition("eoriNumber", "Economic Operator Registration and Identification (EORI) number", Seq(INDIVIDUAL, ORGANISATION)),
FieldDefinition("userFullName", "Full Name", Seq(INDIVIDUAL, ORGANISATION)),
FieldDefinition("emailAddress", "Email Address", Seq(INDIVIDUAL, ORGANISATION)),
FieldDefinition("organisationDetails", "Organisation Details", Seq(ORGANISATION)),
FieldDefinition("individualDetails", "Individual Details", Seq(INDIVIDUAL)),
FieldDefinition("groupIdentifier", "Group Identifier", Seq(INDIVIDUAL, ORGANISATION))
)
}
7 changes: 7 additions & 0 deletions app/uk/gov/hmrc/testuser/services/TestUserService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class TestUserService @Inject() (apiPlatformTestUserConnector: ApiPlatformTestUs
testUser <- createUserWithServices(userType, services)
} yield testUser

}
def createUserCtc(userType: UserType)(implicit hc: HeaderCarrier): Future[TestUser] = {
for {
services <- apiPlatformTestUserConnector.getServices()
testUser <- createUserWithServices(userType, services.filter(x => x.key == "common-transit-convention-traders"))
} yield testUser

}

private def createUserWithServices(userType: UserType, services: Seq[Service])(implicit hc: HeaderCarrier) = {
Expand Down
115 changes: 115 additions & 0 deletions app/uk/gov/hmrc/testuser/views/CreateTestUserViewCtc.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
@*
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*@

@import uk.gov.hmrc.testuser.models.NavLink
@import uk.gov.hmrc.testuser.controllers.CreateUserForm
@import uk.gov.hmrc.testuser.views.html.includes._
@import uk.gov.hmrc.testuser.models.FieldDefinitions
@import uk.gov.hmrc.testuser.models.UserTypes.{INDIVIDUAL, ORGANISATION}
@import uk.gov.hmrc.testuser.views.html.govuk_wrapper
@import uk.gov.hmrc.testuser.models.views.FeedbackBanner
@import uk.gov.hmrc.testuser.models.views.GenericFeedbackBanner
@import uk.gov.hmrc.testuser.config.ApplicationConfig


@this(govUkWrapper: govuk_wrapper, feedbackBannerView: FeedbackBannerView)

@(navLinks: Seq[NavLink], form: Form[CreateUserForm], feedbackBanner: Option[FeedbackBanner] = Some(GenericFeedbackBanner))(implicit request: Request[_], messages: Messages, config: ApplicationConfig)

@govUkWrapper(pageTitle = Some("Create test user - HMRC Developer Hub - GOV.UK"), navLinks = navLinks, feedbackBanner = feedbackBanner) {
<h1 class="govuk-heading-xl">Create a CTC test user</h1>
@errorSummary(form)
<p class="govuk-body">
A CTC test user is a dummy Government Gateway user ID used for testing NCTS in the sandbox with the CTC enrolment.
</p>
<p class="govuk-body">
A test CTC user ID has:
</p>
<ul class="govuk-list govuk-list--bullet">
<li>a type - individual, organisation or agent</li>
<li>a password</li>
<li>a service enrolment for CTC</li>
</ul>
<p class="govuk-body">
Test users and other test data are no longer cleared down every two weeks.
</p>

@helper.form(action = uk.gov.hmrc.testuser.controllers.routes.TestUserController.createUserCtc()) {
@helper.CSRF.formField
<div class="govuk-form-group @if(form.errors("userType").nonEmpty) {govuk-form-group--error}">
<fieldset id="userType" class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h2 class="govuk-fieldset__heading">
Choose a type of CTC test user
</h2>
</legend>
@fieldError(form.errors, "userType")
<div class="govuk-radios">
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="Individual" value="INDIVIDUAL" name="userType" type="radio" aria-describedby="individual-type-hint">
<label class="govuk-label govuk-radios__label" for="Individual" data-type="individual">
<b>Individual</b>
</label>
<details id="individual-type-hint">
<summary class="govuk-summary-text">What dummy data is generated?</summary>
<div class="govuk-inset-text">
<p class="govuk-body">Creates a test user with a:</p>
<ul class="govuk-list govuk-list--bullet">
<li>User ID</li>
<li>Password</li>
@FieldDefinitions.getCtc().filter(field => field.allowedUserTypes.contains(INDIVIDUAL)).map { field =>
<li>@field.name</li>
}
</ul>
<p class="govuk-body">
Enrols them for CTC
<a class="govuk-link" href="/api-documentation/docs/api/service/api-platform-test-user/1.0#_create-a-test-user-which-is-an-organisation_post_accordion">
Create Test User API endpoint</a>.
</p>
</div>
</details>
</div>
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="Organisation" value="ORGANISATION" name="userType" type="radio" aria-describedby="organisation-type-hint">
<label class="govuk-label govuk-radios__label" for="Organisation" data-type="organisation">
<b>Organisation</b>
</label>
<details id="organisation-type-hint">
<summary class="govuk-summary-text">What dummy data is generated?</summary>
<div class="govuk-inset-text">
<p class="govuk-body">Creates a test user with a:</p>
<ul class="govuk-list govuk-list--bullet">
<li>User ID</li>
<li>Password</li>
@FieldDefinitions.getCtc().filter(field => field.allowedUserTypes.contains(ORGANISATION)).map { field =>
<li>@field.name</li>
}
</ul>
<p class="govuk-body">
Enrols them for CTC
<a class="govuk-link" href="/api-documentation/docs/api/service/api-platform-test-user/1.0#_create-a-test-user-which-is-an-organisation_post_accordion">
Create Test User API endpoint</a>.
</p>
</div>
</details>
</div>
</div>
</fieldset>
</div>

<button id="submit" class="govuk-button" data-module="govuk-button" type="submit">Create</button>
}
}
52 changes: 52 additions & 0 deletions app/uk/gov/hmrc/testuser/views/TestUserViewCtc.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@*
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*@

@import uk.gov.hmrc.testuser.models.TestUser
@import uk.gov.hmrc.testuser.models.NavLink
@import uk.gov.hmrc.testuser.models.Field

@import uk.gov.hmrc.testuser.views.html.field
@import uk.gov.hmrc.testuser.views.html.govuk_wrapper
@import uk.gov.hmrc.testuser.views.html.includes.FeedbackBannerView
@import uk.gov.hmrc.testuser.models.views.FeedbackBanner
@import uk.gov.hmrc.testuser.models.views.GenericFeedbackBanner
@import uk.gov.hmrc.testuser.config.ApplicationConfig

@this(govUkWrapper: govuk_wrapper, feedbackBannerView: FeedbackBannerView)

@(navLinks: Seq[NavLink], user: TestUser, feedbackBanner: Option[FeedbackBanner] = Some(GenericFeedbackBanner))(implicit request: Request[_], messages: Messages, config: ApplicationConfig)

@title = {Generated @user.label.toLowerCase}

@govUkWrapper(Some(s"$title - HMRC Developer Hub - GOV.UK"), navLinks = navLinks, feedbackBanner = feedbackBanner) {
<h1 class="govuk-heading-xl">@title</h1>

<ul class="govuk-list govuk-list--bullet govuk-list--no-style">
@field(Field("userid", "User ID", user.userId))
@field(Field("password", "Password", user.password))
@user.fields.map(f => field(f))
</ul>

<p class="govuk-body govuk-!-padding-bottom-4">
<a class="govuk-link" href="@uk.gov.hmrc.testuser.controllers.routes.TestUserController.showCreateUserPage()">
Add a new user
</a>
</p>

<p class="govuk-body">
<a class="govuk-link" target="_blank" href="@config.ctcLoginUrl">Login to NCTS</a> to manage your movements.
</p>
}
5 changes: 1 addition & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import play.core.PlayVersion
import play.sbt.PlayImport._
import bloop.integrations.sbt.BloopDefaults
import sbt.Tests.{Group, SubProcess}
import uk.gov.hmrc.DefaultBuildSettings
import uk.gov.hmrc.DefaultBuildSettings._
import uk.gov.hmrc.SbtAutoBuildPlugin
import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin
import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin._
import uk.gov.hmrc.versioning.SbtGitVersioning
import uk.gov.hmrc.versioning.SbtGitVersioning.autoImport.majorVersion

import scala.util.Properties
import bloop.integrations.sbt.BloopDefaults

lazy val playSettings: Seq[Setting[_]] = Seq.empty
lazy val appName = "api-platform-test-user-frontend"
Expand Down
2 changes: 2 additions & 0 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
-> /hmrc-frontend hmrcfrontend.Routes

GET / uk.gov.hmrc.testuser.controllers.TestUserController.showCreateUserPage()
GET /ctc uk.gov.hmrc.testuser.controllers.TestUserController.showCreateUserPageCtc()

POST /user uk.gov.hmrc.testuser.controllers.TestUserController.createUser()
POST /user/ctc uk.gov.hmrc.testuser.controllers.TestUserController.createUserCtc()

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
Expand Down
2 changes: 2 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ play.http.router=prod.Routes
play.filters.enabled += play.filters.csp.CSPFilter
play.filters.csp.directives.script-src = ${play.filters.csp.nonce.pattern} "'strict-dynamic' 'unsafe-inline' https: http:"

ctc-login-url = "http://localhost:9619/api-test-login/sign-in?continue=http://localhost:9485/manage-transit-movements"

play.i18n.langs = [ "en" ]

tracking-consent-frontend {
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.9.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.2.0")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.19")
addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.5.1")
addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.11")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import play.api.test.FakeRequest
import play.api.test.Helpers._
import uk.gov.hmrc.http.UpstreamErrorResponse
import uk.gov.hmrc.test.utils.AsyncHmrcSpec
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import akka.stream.Materializer
import org.jsoup.nodes.Document
import uk.gov.hmrc.testuser.views.html.{CreateTestUserView, CreateTestUserViewCtc, TestUserView, TestUserViewCtc}

import uk.gov.hmrc.testuser.ApplicationLogger
import uk.gov.hmrc.testuser.common.LogSuppressing
Expand Down Expand Up @@ -66,7 +70,10 @@ class TestUserControllerSpec extends AsyncHmrcSpec with GuiceOneAppPerSuite with

val mcc = app.injector.instanceOf[MessagesControllerComponents]
val createTestUserView = app.injector.instanceOf[CreateTestUserView]
val createTestUserViewCtc = app.injector.instanceOf[CreateTestUserViewCtc]

val testUserView = app.injector.instanceOf[TestUserView]
val testUserViewCtc = app.injector.instanceOf[TestUserViewCtc]

val mockTestUserService = mock[TestUserService]
val mockNavigationService = mock[NavigationService]
Expand All @@ -81,7 +88,9 @@ class TestUserControllerSpec extends AsyncHmrcSpec with GuiceOneAppPerSuite with
mockApiPlatformTestUserConnector,
mcc,
createTestUserView,
testUserView
createTestUserViewCtc,
testUserView,
testUserViewCtc
)

when(mockTestUserService.createUser(eqTo(INDIVIDUAL))(*)).thenReturn(successful(individual))
Expand Down