Skip to content

Commit

Permalink
Fix II url
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Stacey authored and CEPoole committed May 2, 2017
1 parent 0667bfd commit 2ad65c3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
8 changes: 5 additions & 3 deletions app/connectors/IncorporationInformationConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@ class IncorporationInformationResponseException(msg: String) extends NoStackTrac
@Singleton
class IncorporationInformationConnector @Inject()() extends IncorporationInformationConnect with ServicesConfig {
val http = WSHttp
val incorporationInformationUri: String = baseUrl("incorporation-information")
lazy val incorporationInformationUri: String = baseUrl("incorporation-information")
lazy val payeRegUri: String = baseUrl("paye-registration")
}

trait IncorporationInformationConnect {
val http: WSPost
val incorporationInformationUri: String
val payeRegUri: String

private[connectors] def constructIncorporationInfoUri(transactionId: String, regime: String, subscriber: String): String = {
s"/incorporation-information/subscribe/$transactionId/regime/$regime/subscriber/$subscriber"
}

def getIncorporationUpdate(transactionId: String, regime: String, subscriber: String, callbackUrl: String)(implicit hc: HeaderCarrier): Future[Option[IncorpStatusUpdate]] = {
val postJson = Json.obj("SCRSIncorpSubscription" -> Json.obj("callbackUrl" -> callbackUrl))
def getIncorporationUpdate(transactionId: String, regime: String, subscriber: String)(implicit hc: HeaderCarrier): Future[Option[IncorpStatusUpdate]] = {
val postJson = Json.obj("SCRSIncorpSubscription" -> Json.obj("callbackUrl" -> s"$payeRegUri/incorporation-data"))
http.POST[JsObject, HttpResponse](s"$incorporationInformationUri${constructIncorporationInfoUri(transactionId, regime, subscriber)}", postJson) map { resp =>
resp.status match {
case OK => Some(resp.json.as[IncorpStatusUpdate])
Expand Down
3 changes: 1 addition & 2 deletions app/services/SubmissionService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ trait SubmissionSrv {

private val REGIME = "paye"
private val SUBSCRIBER = "SCRS"
private val CALLBACK_URL = controllers.routes.RegistrationController.processIncorporationData().url
private val rejected = "rejected"

def submitToDes(regId: String)(implicit hc: HeaderCarrier, req: Request[AnyContent]): Future[String] = {
Expand Down Expand Up @@ -104,7 +103,7 @@ trait SubmissionSrv {
def getIncorporationUpdate(regId: String)(implicit hc: HeaderCarrier): Future[Option[IncorpStatusUpdate]] = {
for {
txId <- registrationRepository.retrieveTransactionId(regId)
incStatus <- incorporationInformationConnector.getIncorporationUpdate(txId, REGIME, SUBSCRIBER, CALLBACK_URL) map {
incStatus <- incorporationInformationConnector.getIncorporationUpdate(txId, REGIME, SUBSCRIBER) map {
case Some(update) if update.status == rejected => throw new RejectedIncorporationException(s"incorporation for regId $regId has been rejected")
case response => response
}
Expand Down
5 changes: 5 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ microservice {
host = localhost
port = 9660
}

paye-registration {
host = localhost
port = 9873
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions test/connectors/IncorporationInformationConnectorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class IncorporationInformationConnectorSpec extends PAYERegSpec {
class Setup {
val testConnector = new IncorporationInformationConnect {
override val incorporationInformationUri: String = "/test/uri"
override val payeRegUri: String = "/test-reg/"
override val http: WSHttp = mockHttp
}
}
Expand All @@ -84,7 +85,7 @@ class IncorporationInformationConnectorSpec extends PAYERegSpec {
when(mockHttp.POST[JsObject, HttpResponse](ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any())(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any()))
.thenReturn(Future.successful(testResponse))

val result = await(testConnector.getIncorporationUpdate("testTxId", "paye", "SCRS", "/test/call-back"))
val result = await(testConnector.getIncorporationUpdate("testTxId", "paye", "SCRS"))
result shouldBe Some(Json.fromJson[IncorpStatusUpdate](testJson).get)
}
}
Expand All @@ -98,7 +99,7 @@ class IncorporationInformationConnectorSpec extends PAYERegSpec {
when(mockHttp.POST[JsObject, HttpResponse](ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any())(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any()))
.thenReturn(Future.successful(testResponse))

val result = await(testConnector.getIncorporationUpdate("testTxId", "paye", "SCRS", "/test/call-back"))
val result = await(testConnector.getIncorporationUpdate("testTxId", "paye", "SCRS"))
result shouldBe None
}
}
Expand All @@ -112,7 +113,7 @@ class IncorporationInformationConnectorSpec extends PAYERegSpec {
when(mockHttp.POST[JsObject, HttpResponse](ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any())(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any()))
.thenReturn(Future.successful(testResponse))

val result = intercept[IncorporationInformationResponseException](await(testConnector.getIncorporationUpdate("testTxId", "paye", "SCRS", "/test/call-back")))
val result = intercept[IncorporationInformationResponseException](await(testConnector.getIncorporationUpdate("testTxId", "paye", "SCRS")))
result.getMessage shouldBe s"Calling II on /incorporation-information/subscribe/testTxId/regime/paye/subscriber/SCRS returned a 500"
}
}
Expand Down

0 comments on commit 2ad65c3

Please sign in to comment.