Skip to content

Commit

Permalink
[MIBM-27][PH] review comments/tidy for MIBM-27 (#2)
Browse files Browse the repository at this point in the history
* [MIBM-27][PH] review comments/tidy for MIBM-27

* [MIBM-27][PH] set play default port
  • Loading branch information
PaulHodgson authored Aug 21, 2020
1 parent 3b526e7 commit e81aef7
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.config

import javax.inject.Singleton
import pureconfig.ConfigSource
import pureconfig.generic.auto._
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.URL // Do not remove this
import pureconfig.generic.auto._ // Do not remove this
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.URL

@Singleton
class AppConfig() extends PaymentServiceConf {
private val configSource: String => ConfigSource = ConfigSource.default.at _
private val configSource: String => ConfigSource = ConfigSource.default.at

lazy val footerLinkItems: Seq[String] = configSource("footerLinkItems").loadOrThrow[Seq[String]]
}
Expand Down

This file was deleted.

This file was deleted.

2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import play.sbt.PlayImport.PlayKeys.playDefaultPort
import uk.gov.hmrc.DefaultBuildSettings.integrationTestSettings
import uk.gov.hmrc.SbtArtifactory
import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin.publishingSettings
Expand All @@ -11,6 +12,7 @@ lazy val microservice = Project(appName, file("."))
.settings(
majorVersion := 0,
scalaVersion := "2.12.11",
playDefaultPort := 8281,
libraryDependencies ++= AppDependencies.compile ++ AppDependencies.test,
TwirlKeys.templateImports ++= Seq(
"uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig",
Expand Down
3 changes: 0 additions & 3 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@

GET /assets/*file controllers.Assets.versioned(path = "/public", file: Asset)


GET /hello-world uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.HelloWorldController.helloWorld

GET /payment uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.PaymentController.onPageLoad
GET /process-payment uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.PaymentController.onSubmit()
20 changes: 3 additions & 17 deletions test/uk/gov/hmrc/merchandiseinbaggagefrontend/BaseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,16 @@ import org.scalatest.BeforeAndAfterEach
import org.scalatest.matchers.must.Matchers
import org.scalatest.wordspec.AnyWordSpec
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.i18n.{Messages, MessagesApi}
import play.api.inject.Injector
import play.api.mvc.{AnyContentAsEmpty, MessagesControllerComponents}
import play.api.mvc.AnyContentAsEmpty
import play.api.test.CSRFTokenHelper._
import play.api.test.FakeRequest
import play.api.test.Helpers.GET
import uk.gov.hmrc.merchandiseinbaggagefrontend.config.{AppConfig, ErrorHandler}
import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.ErrorTemplate


trait BaseSpec extends AnyWordSpec with Matchers with BeforeAndAfterEach

trait BaseSpecWithApplication extends BaseSpec with GuiceOneAppPerSuite {
lazy val injector: Injector = app.injector
lazy val messagesApi = app.injector.instanceOf[MessagesApi]
lazy val component = app.injector.instanceOf[MessagesControllerComponents]
lazy val errorHandlerTemplate = app.injector.instanceOf[ErrorTemplate]
implicit lazy val appConfig = new AppConfig()
implicit def messages[A](fakeRequest: FakeRequest[A]): Messages = messagesApi.preferred(fakeRequest)
implicit val errorHandler: ErrorHandler = app.injector.instanceOf[ErrorHandler]

def buildGet(url: String): FakeRequest[AnyContentAsEmpty.type] =
FakeRequest(GET, url).withCSRFToken.asInstanceOf[FakeRequest[AnyContentAsEmpty.type]]
Expand All @@ -40,11 +30,7 @@ trait BaseSpecWithWireMock extends BaseSpecWithApplication {

val paymentMockServer = new WireMockServer(9057)

override def beforeEach: Unit = {
paymentMockServer.start()
}
override def beforeEach: Unit = paymentMockServer.start()

override def afterEach: Unit = {
paymentMockServer.stop()
}
override def afterEach: Unit = paymentMockServer.stop()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import uk.gov.hmrc.merchandiseinbaggagefrontend.model.api.{AmountInPence, Mercha

trait CoreTestData {

val payApiRequest = PayApitRequest(
val payApiRequest: PayApitRequest = PayApitRequest(
MibReference("MIBI1234567890"),
AmountInPence(1),
AmountInPence(2),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@

package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers

import play.api.i18n.{Messages, MessagesApi}
import play.api.mvc.MessagesControllerComponents
import play.api.test.FakeRequest
import play.api.test.Helpers._
import uk.gov.hmrc.http.{HeaderCarrier, HttpClient, HttpResponse}
import uk.gov.hmrc.merchandiseinbaggagefrontend.BaseSpecWithApplication
import uk.gov.hmrc.merchandiseinbaggagefrontend.config.{AppConfig, ErrorHandler}
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.api.PayApitRequest
import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.PaymentPage
import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.{ErrorTemplate, PaymentPage}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{ExecutionContext, Future}

class PaymentControllerSpec extends BaseSpecWithApplication {

val view = app.injector.instanceOf[PaymentPage]
val httpClient = app.injector.instanceOf[HttpClient]
val controller = new PaymentController(component, view, httpClient)
private lazy val view = app.injector.instanceOf[PaymentPage]
private lazy val httpClient = app.injector.instanceOf[HttpClient]
private lazy val component = app.injector.instanceOf[MessagesControllerComponents]
private lazy val errorHandlerTemplate = app.injector.instanceOf[ErrorTemplate]
private lazy val messagesApi = app.injector.instanceOf[MessagesApi]

private implicit lazy val errorHandler: ErrorHandler = app.injector.instanceOf[ErrorHandler]
private implicit lazy val appConfig: AppConfig = new AppConfig()

private def messages[A](fakeRequest: FakeRequest[A]): Messages = messagesApi.preferred(fakeRequest)

"on page load will render PaymentPage template" in {
val controller = new PaymentController(component, view, httpClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
*/

package uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.service
package uk.gov.hmrc.merchandiseinbaggagefrontend.service

import com.github.tomakehurst.wiremock.client.WireMock.{post, urlPathEqualTo, _}
import org.scalatest.concurrent.Eventually
Expand All @@ -12,7 +12,6 @@ import play.api.libs.json.Json
import uk.gov.hmrc.http.{HeaderCarrier, HeaderNames, HttpClient, HttpResponse}
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.api._
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.URL
import uk.gov.hmrc.merchandiseinbaggagefrontend.service.PaymentService
import uk.gov.hmrc.merchandiseinbaggagefrontend.{BaseSpec, BaseSpecWithWireMock, CoreTestData}

import scala.concurrent.Await
Expand All @@ -21,24 +20,24 @@ import scala.concurrent.duration._

class PaymentServiceSpec extends BaseSpec with BaseSpecWithWireMock with Eventually with CoreTestData {

implicit val hc = HeaderCarrier()
private implicit val hc: HeaderCarrier = HeaderCarrier()
override implicit val patienceConfig: PatienceConfig = PatienceConfig(scaled(Span(5L, Seconds)), scaled(Span(1L, Second)))

"send a payment request to payment service adding a generated session id to the header" in new PaymentService {
val stubbedSessionId = generateSessionId
private val sessionId = generateSessionId
override def addSessionId(headerCarrier: HeaderCarrier): HeaderCarrier =
hc.withExtraHeaders(HeaderNames.xSessionId -> stubbedSessionId)
hc.withExtraHeaders(HeaderNames.xSessionId -> sessionId)

val stubbedResponse = s"""{"journeyId":"5f3bc55","nextUrl":"http://localhost:9056/pay/initiate-journey"}"""

paymentMockServer
.stubFor(post(urlPathEqualTo(s"/${paymentServiceConf.url.value}"))
.withRequestBody(equalToJson(Json.toJson(payApiRequest).toString, true, false))
.withHeader(HeaderNames.xSessionId, containing(stubbedSessionId))
.withHeader(HeaderNames.xSessionId, containing(sessionId))
.willReturn(okJson(stubbedResponse).withStatus(201))
)

val httpClient = app.injector.instanceOf[HttpClient]
private val httpClient = app.injector.instanceOf[HttpClient]

eventually {
val response: HttpResponse = Await.result(makePayment(httpClient, payApiRequest), 5.seconds)
Expand Down

0 comments on commit e81aef7

Please sign in to comment.