Skip to content

Commit

Permalink
[MIBM-145] remove redundent specs (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHodgson authored Nov 3, 2020
1 parent ae625b7 commit 0ba6e35
Show file tree
Hide file tree
Showing 26 changed files with 157 additions and 1,731 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,91 +16,27 @@

package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers

import play.api.mvc.Result
import play.api.test.Helpers._
import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.AgentDetailsView

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

class AgentDetailsControllerSpec extends DeclarationJourneyControllerSpec {

private lazy val controller =
new AgentDetailsController(
controllerComponents, actionBuilder, declarationJourneyRepository, injector.instanceOf[AgentDetailsView])

private def ensureContent(result: Future[Result]) = {
val content = contentAsString(result)

content must include("Enter the business name of the customs agent")
content must include("Continue")

content
}

"onPageLoad" must {
val url = routes.AgentDetailsController.onPageLoad().url
val getRequest = buildGet(url, sessionId)

behave like anEndpointRequiringASessionIdAndLinkedDeclarationJourneyToLoad(controller, url)

"return OK and render the view" when {
"a declaration has been started" in {
givenADeclarationJourneyIsPersisted(startedImportJourney)

val result = controller.onPageLoad()(getRequest)

status(result) mustEqual OK
ensureContent(result)
}
}

"return OK and render the view" when {
"a declaration has been started and a value saved" in {
givenADeclarationJourneyIsPersisted(startedImportJourney.copy(maybeCustomsAgentName = Some("test agent")))

val result = controller.onPageLoad()(getRequest)

status(result) mustEqual OK
ensureContent(result) must include("test agent")
}
}
}

"onSubmit" must {
val url = routes.AgentDetailsController.onSubmit().url
val postRequest = buildPost(url, sessionId)

behave like anEndpointRequiringASessionIdAndLinkedDeclarationJourneyToUpdate(controller, url)

"redirect to /enter-agent-address" when {
"a declaration is started and a valid selection submitted" in {
givenADeclarationJourneyIsPersisted(startedImportJourney)

val request = postRequest.withFormUrlEncodedBody(("value", "test agent"))

val result = controller.onSubmit()(request)

status(result) mustEqual SEE_OTHER
redirectLocation(result).get mustEqual routes.EnterAgentAddressController.onPageLoad().toString

startedImportJourney.maybeCustomsAgentName mustBe None
declarationJourneyRepository
.findBySessionId(sessionId)
.futureValue
.get
.maybeCustomsAgentName mustBe Some("test agent")
}
}

"return BAD_REQUEST and errors" when {
"no selection is made" in {
val controller =
new AgentDetailsController(
controllerComponents, actionBuilder, declarationJourneyRepository, injector.instanceOf[AgentDetailsView])

givenADeclarationJourneyIsPersisted(startedImportJourney)

val result = controller.onSubmit()(postRequest)
val result = controller.onSubmit()(buildPost(routes.AgentDetailsController.onSubmit().url, sessionId))
val content = contentAsString(result)

status(result) mustEqual BAD_REQUEST
ensureContent(result) must include("Enter a value")
content must include("Enter the business name of the customs agent")
content must include("Continue")
}
}
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,104 +16,30 @@

package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers

import play.api.mvc.Result
import play.api.test.Helpers._
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.YesNo._
import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.CustomsAgentView

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

class CustomsAgentControllerSpec extends DeclarationJourneyControllerSpec {

private lazy val controller =
new CustomsAgentController(
controllerComponents, actionBuilder, declarationJourneyRepository, injector.instanceOf[CustomsAgentView])

private def ensureContent(result: Future[Result]) = {
val content = contentAsString(result)

content must include("Are you a customs agent?")
content must include("Yes")
content must include("No")
content must include("Continue")

content
}

"onPageLoad" must {
val url = routes.CustomsAgentController.onPageLoad().url
val request = buildGet(url, sessionId)

behave like anEndpointRequiringASessionIdAndLinkedDeclarationJourneyToLoad(controller, url)

"return OK and render the view" when {

"a declaration has been started" in {
givenADeclarationJourneyIsPersisted(startedImportJourney)

val result = controller.onPageLoad()(request)

status(result) mustEqual OK
ensureContent(result)
}

"a declaration has been started and a value saved" in {
givenADeclarationJourneyIsPersisted(startedImportJourney
.copy(maybeIsACustomsAgent = Some(Yes)))

val result = controller.onPageLoad()(request)

status(result) mustEqual OK
ensureContent(result)
}
}
}

"onSubmit" must {
val url = routes.CustomsAgentController.onSubmit().url
val postRequest = buildPost(url, sessionId)

behave like anEndpointRequiringASessionIdAndLinkedDeclarationJourneyToUpdate(controller, url)

"Redirect to /enter-eori-number" when {
"a declaration is started and No is submitted" in {
givenADeclarationJourneyIsPersisted(startedImportJourney)

val request = postRequest.withFormUrlEncodedBody(("value", "No"))
val result = controller.onSubmit()(request)

status(result) mustEqual SEE_OTHER
redirectLocation(result).get mustEqual routes.EoriNumberController.onPageLoad().toString

startedImportJourney.maybeIsACustomsAgent mustBe None
declarationJourneyRepository.findBySessionId(sessionId).futureValue.get.maybeIsACustomsAgent mustBe Some(No)
}
}

"Redirect to /agent-details" when {
"a declaration is started and Yes is submitted" in {
givenADeclarationJourneyIsPersisted(startedImportJourney)

val request = postRequest.withFormUrlEncodedBody(("value", "Yes"))
val result = controller.onSubmit()(request)

status(result) mustEqual SEE_OTHER
redirectLocation(result).get mustEqual routes.AgentDetailsController.onPageLoad().toString

startedImportJourney.maybeIsACustomsAgent mustBe None
declarationJourneyRepository.findBySessionId(sessionId).futureValue.get.maybeIsACustomsAgent mustBe Some(Yes)
}
}

"return BAD_REQUEST and errors" when {
"no selection is made" in {
val controller =
new CustomsAgentController(
controllerComponents, actionBuilder, declarationJourneyRepository, injector.instanceOf[CustomsAgentView])

givenADeclarationJourneyIsPersisted(startedImportJourney)

val result = controller.onSubmit()(postRequest)
val result = controller.onSubmit()(buildPost(routes.CustomsAgentController.onSubmit().url, sessionId))
val content = contentAsString(result)

status(result) mustEqual BAD_REQUEST
ensureContent(result) must include("Select one of the options below")

content must include("Are you a customs agent?")
content must include("Yes")
content must include("No")
content must include("Continue")
}
}
}
Expand Down
Loading

0 comments on commit 0ba6e35

Please sign in to comment.