Skip to content

Commit

Permalink
Merge pull request #8 from hmrc/TGP-548/create-unauthorised-access-page
Browse files Browse the repository at this point in the history
TGP-548 Create Unauthorised Access Page
  • Loading branch information
Nidhi1shah authored Apr 26, 2024
2 parents 33d9562 + 75fc805 commit 194c860
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 20 deletions.
15 changes: 9 additions & 6 deletions app/views/UnauthorisedView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@
*@

@this(
layout: templates.Layout
layout: templates.Layout,
paragraph: components.Paragraph,
heading1: components.Heading1,
link: components.Link
)

@()(implicit request: Request[_], messages: Messages)

@layout(
pageTitle = titleNoForm(messages("unauthorised.title")),
timeout = false
timeout = false,
showBackLink = false
) {

<h1 class="govuk-heading-xl">@messages("unauthorised.heading")</h1>

<p class="govuk-body">@messages("unauthorised.guidance")</p>
@heading1(messages("unauthorised.heading"))
@paragraph(Html(messages("unauthorised.p1")))
@paragraph(Html(messages("unauthorised.p2", link(messages("unauthorised.p2.linkText"), controllers.auth.routes.AuthController.signOut.url))))
}
2 changes: 1 addition & 1 deletion app/views/components/Link.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

@(linkText: String, link: String, target: String = "_self", classes: String = "govuk-link")

<a target="@target" href="@link" class="govuk-link" >@linkText</a>
<a target="@target" href="@link" class="@classes" >@linkText</a>
7 changes: 5 additions & 2 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,8 @@ signedOut.title = For your security, we signed you out
signedOut.heading = For your security, we signed you out
signedOut.guidance = We did not save your answers.

unauthorised.title = You can’t access this service with this account
unauthorised.heading = You can’t access this service with this account
unauthorised.title = There is a problem
unauthorised.heading = There is a problem
unauthorised.p1 = The details signed in to GOV.UK do not have a Trader Goods Profile.
unauthorised.p2 = If you have a Trader Goods Profile, {0} and sign in with the correct details.
unauthorised.p2.linkText = sign out
41 changes: 41 additions & 0 deletions it/test/controllers/UnauthorisedControllerISpec.scala
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 helpers.ItTestBase
import play.api.http.Status.OK
import play.api.libs.ws.{WSClient, WSRequest}
import play.api.test.Helpers.{await, defaultAwaitTimeout}

class UnauthorisedControllerISpec extends ItTestBase {

lazy val client: WSClient = app.injector.instanceOf[WSClient]

private val url = s"http://localhost:$port$appRouteContext/unauthorised"

"Unauthorised controller" should {

"loads page" in {

val request: WSRequest = client.url(url).withFollowRedirects(false)

val response = await(request.get())

response.status mustBe OK
}
}
}
21 changes: 10 additions & 11 deletions test/controllers/UnauthorisedControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,27 @@
package controllers

import base.SpecBase
import play.api.test.FakeRequest
import play.api.test.Helpers._
import views.html.UnauthorisedView

class UnauthorisedControllerSpec extends SpecBase {

"Unauthorised Controller" - {
private val unauthorisedView = app.injector.instanceOf[UnauthorisedView]

"must return OK and the correct view for a GET" in {
private val unauthorisedController = new UnauthorisedController(
stubMessagesControllerComponents(),
unauthorisedView
)

val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build()
"Unauthorised Controller" - {

running(application) {
val request = FakeRequest(GET, routes.UnauthorisedController.onPageLoad.url)
"must return OK and the correct view for a GET" in {

val result = route(application, request).value
val result = unauthorisedController.onPageLoad(fakeRequest)

val view = application.injector.instanceOf[UnauthorisedView]
status(result) mustEqual OK

status(result) mustEqual OK
contentAsString(result) mustEqual view()(request, messages(application)).toString
}
contentAsString(result) mustEqual unauthorisedView()(fakeRequest, stubMessages()).toString
}
}
}

0 comments on commit 194c860

Please sign in to comment.