-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from hmrc/TGP-449/create-category-guidance-page
TGP 449 Create Category Guidance Page
- Loading branch information
Showing
22 changed files
with
360 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2024 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. | ||
*/ | ||
|
||
package controllers | ||
|
||
import controllers.actions.AuthoriseAction | ||
import play.api.i18n.I18nSupport | ||
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} | ||
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController | ||
import views.html.CategoryGuidanceView | ||
|
||
import javax.inject.Inject | ||
|
||
class CategoryGuidanceController @Inject() ( | ||
val controllerComponents: MessagesControllerComponents, | ||
authorise: AuthoriseAction, | ||
view: CategoryGuidanceView | ||
) extends FrontendBaseController | ||
with I18nSupport { | ||
|
||
def onPageLoad: Action[AnyContent] = authorise { implicit request => | ||
Ok(view()) | ||
} | ||
|
||
def onSubmit: Action[AnyContent] = authorise { implicit request => | ||
Redirect(routes.DummyController.onPageLoad.url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
@* | ||
* Copyright 2024 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. | ||
*@ | ||
|
||
@this( | ||
layout: templates.Layout, | ||
govukButton: GovukButton, | ||
formHelper: FormWithCSRF, | ||
paragraph: components.Paragraph, | ||
heading1: components.Heading1 | ||
) | ||
|
||
@()(implicit request: Request[_], messages: Messages) | ||
|
||
@layout( | ||
pageTitle = titleNoForm(messages("categoryGuidance.title")), | ||
showBackLink = true | ||
) { | ||
@heading1(messages("categoryGuidance.h1")) | ||
@paragraph(Html(messages("categoryGuidance.p1"))) | ||
@paragraph(Html(messages("categoryGuidance.p2"))) | ||
@paragraph(Html(messages("categoryGuidance.p3"))) | ||
@paragraph(Html(messages("categoryGuidance.p4"))) | ||
@paragraph(Html(messages("categoryGuidance.p5"))) | ||
|
||
@formHelper(action = CategoryGuidanceController.onSubmit) { | ||
@govukButton( | ||
ButtonViewModel(messages("site.continue")) | ||
) | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2024 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. | ||
*/ | ||
|
||
package controllers | ||
|
||
import helpers.ItTestBase | ||
import play.api.http.Status.{OK, SEE_OTHER} | ||
import play.api.libs.ws.{WSClient, WSRequest} | ||
import play.api.test.Helpers.{await, defaultAwaitTimeout} | ||
|
||
class CategoryGuidanceControllerISpec extends ItTestBase { | ||
|
||
lazy val client: WSClient = app.injector.instanceOf[WSClient] | ||
|
||
private val url = s"http://localhost:$port$appRouteContext/category-guidance" | ||
|
||
"Category Guidance controller" should { | ||
|
||
"redirects you to unauthorised page when auth fails" in { | ||
noEnrolment | ||
|
||
val request: WSRequest = client.url(url).withFollowRedirects(false) | ||
|
||
val response = await(request.get()) | ||
|
||
response.status mustBe SEE_OTHER | ||
|
||
redirectUrl(response) mustBe Some(routes.UnauthorisedController.onPageLoad.url) | ||
} | ||
|
||
"loads page" in { | ||
authorisedUser | ||
|
||
val request: WSRequest = client.url(url).withFollowRedirects(false) | ||
|
||
val response = await(request.get()) | ||
|
||
response.status mustBe OK | ||
} | ||
|
||
"returns redirect when submitting" in { | ||
authorisedUser | ||
|
||
val request: WSRequest = client.url(url).withFollowRedirects(false) | ||
|
||
val response = await(request.post("")) | ||
|
||
response.status mustBe SEE_OTHER | ||
|
||
redirectUrl(response) mustBe Some(routes.DummyController.onPageLoad.url) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2024 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. | ||
*/ | ||
|
||
package helpers | ||
|
||
import config.FrontendAppConfig | ||
import org.mockito.ArgumentMatchers.any | ||
import org.mockito.ArgumentMatchersSugar.eqTo | ||
import org.mockito.Mockito.when | ||
import org.mockito.stubbing.OngoingStubbing | ||
import org.scalacheck.Gen | ||
import org.scalatestplus.mockito.MockitoSugar.mock | ||
import org.scalatestplus.play.PlaySpec | ||
import org.scalatestplus.play.guice.GuiceOneServerPerSuite | ||
import play.api.Application | ||
import play.api.http.HeaderNames | ||
import play.api.inject.guice.GuiceApplicationBuilder | ||
import uk.gov.hmrc.auth.core.{AuthConnector, Enrolment, Enrolments} | ||
import play.api.inject.bind | ||
import play.api.libs.ws.WSResponse | ||
import uk.gov.hmrc.auth.core.retrieve.v2.Retrievals | ||
import uk.gov.hmrc.auth.core.retrieve.~ | ||
import uk.gov.hmrc.auth.core.syntax.retrieved.authSyntaxForRetrieved | ||
|
||
import scala.concurrent.Future | ||
|
||
trait ItTestBase extends PlaySpec with GuiceOneServerPerSuite { | ||
|
||
val appRouteContext: String = "/trader-goods-profiles" | ||
private val mockAppConfig = mock[FrontendAppConfig] | ||
|
||
lazy val authConnector: AuthConnector = mock[AuthConnector] | ||
|
||
def appBuilder: GuiceApplicationBuilder = | ||
GuiceApplicationBuilder() | ||
.overrides( | ||
bind[AuthConnector].to(authConnector) | ||
) | ||
|
||
override implicit lazy val app: Application = appBuilder.build() | ||
private val appConfig = app.injector.instanceOf[FrontendAppConfig] | ||
private val eori = Gen.alphaNumStr.sample.get | ||
private val authFetch = Retrievals.internalId and Retrievals.authorisedEnrolments | ||
private val ourEnrolment: Enrolment = | ||
Enrolment(appConfig.tgpEnrolmentIdentifier.key).withIdentifier(appConfig.tgpEnrolmentIdentifier.identifier, eori) | ||
private val authResult = Some("internalId") and Enrolments(Set(ourEnrolment)) | ||
|
||
def authorisedUser: OngoingStubbing[Future[Option[String] ~ Enrolments]] = | ||
when(authConnector.authorise(any, eqTo(authFetch))(any, any)).thenReturn( | ||
Future.successful(authResult) | ||
) | ||
|
||
def noEnrolment: OngoingStubbing[Future[Option[String] ~ Enrolments]] = { | ||
val authResult = Some("internalId") and Enrolments(Set.empty) | ||
when(authConnector.authorise(any, eqTo(authFetch))(any, any)).thenReturn( | ||
Future.successful(authResult) | ||
) | ||
} | ||
|
||
def redirectUrl(response: WSResponse): Option[String] = | ||
response.header(HeaderNames.LOCATION) | ||
} |
Oops, something went wrong.