Skip to content

Commit

Permalink
Merge pull request #8 from hmrc/API-1888
Browse files Browse the repository at this point in the history
API-1888 - DES support on nino without suffix and remove POST endpoint
  • Loading branch information
edinhodzic authored Sep 12, 2016
2 parents 4452e8d + bc8cd70 commit 06c8d80
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import scala.concurrent.ExecutionContext.Implicits.global

trait DesConnector {

val NINO_LENGTH = 8

val http: HttpGet
val serviceUrl: String
val desEnvironment: String
Expand All @@ -37,10 +39,12 @@ trait DesConnector {
"Authorization" -> ("Bearer " + desBearerToken),
"Environment" -> desEnvironment)

http.GET[DesUserInfo](s"$serviceUrl/pay-as-you-earn/individuals/$nino")(implicitly[HttpReads[DesUserInfo]], newHc) map (Some(_)) recover {
http.GET[DesUserInfo](s"$serviceUrl/pay-as-you-earn/individuals/${withoutSuffix(nino)}")(implicitly[HttpReads[DesUserInfo]], newHc) map (Some(_)) recover {
case _: NotFoundException | _: BadRequestException => None
}
}

private def withoutSuffix(nino: String) = nino.take(NINO_LENGTH)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ object DocumentationController extends DocumentationController
object Documentation {
val version1_0 = "1.0"
val getUserInfo = "Get user info"
val getUserInfoPost = "Get user info POST"

def findDocumentation(endpointName: String, version: String) = applyTemplate(endpointName, version)(userInfo)

def applyTemplate(apiName: String, version: String)(info: UserInfo): Option[Xml] = {
(apiName, version) match {
case (`getUserInfo`, `version1_0`) => Some(xml.getUserInfo(info))
case (`getUserInfoPost`, `version1_0`) => Some(xml.getUserInfoPost(info))
case _ => None
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@
"authType":"USER",
"throttlingTier":"UNLIMITED",
"scope":"openid"
},
{
"uriPattern":"",
"endpointName":"Get user info POST",
"method":"POST",
"authType":"USER",
"throttlingTier":"UNLIMITED",
"scope":"openid"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<description>Retrieves OpenID Connect compliant information about the signed-in user</description>
<section id="resource">
<title>Resource</title>
<resource>GET /userinfo</resource>
<resource>GET /userinfo/</resource>
</section>
<section id="authorisation">
<title>Authorisation</title>
Expand Down
108 changes: 0 additions & 108 deletions app/uk/gov/hmrc/openidconnect/userinfo/views/getUserInfoPost.scala.xml

This file was deleted.

3 changes: 2 additions & 1 deletion test/it/stubs/DesStub.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ object DesStub extends Stub {
override val stub: MockHost = new MockHost(22222)

def willReturnUserInformation(desUserInfo: DesUserInfo, nino: String) = {
stub.mock.register(get(urlPathEqualTo(s"/pay-as-you-earn/individuals/$nino"))
val ninoWithoutSuffix = nino.take(8)
stub.mock.register(get(urlPathEqualTo(s"/pay-as-you-earn/individuals/$ninoWithoutSuffix"))
.withHeader("Authorization", equalTo("Bearer local"))
.withHeader("Environment", equalTo("local"))
.willReturn(aResponse().withBody(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ class DesConnectorSpec extends UnitSpec with BeforeAndAfterEach with WithFakeApp
}

"fetch user info" should {
val nino = "AB123456"
val nino = "AA111111A"
val ninoWithoutSuffix = "AA111111"

"return the user info" in new Setup {

stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$nino"))
stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$ninoWithoutSuffix"))
.withHeader("Authorization", equalTo(s"Bearer $desToken"))
.withHeader("Environment", equalTo(desEnv)).willReturn(
aResponse()
Expand All @@ -72,7 +73,7 @@ class DesConnectorSpec extends UnitSpec with BeforeAndAfterEach with WithFakeApp
.withBody(
s"""
|{
| "nino": "$nino",
| "nino": "$ninoWithoutSuffix",
| "names": {
| "1": {
| "firstForenameOrInitial": "Andrew",
Expand Down Expand Up @@ -106,7 +107,7 @@ class DesConnectorSpec extends UnitSpec with BeforeAndAfterEach with WithFakeApp

"return None when DES does not have an entry for the NINO" in new Setup {

stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$nino")).willReturn(
stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$ninoWithoutSuffix")).willReturn(
aResponse().withStatus(404)))

val result = await(connector.fetchUserInfo(nino))
Expand All @@ -116,7 +117,7 @@ class DesConnectorSpec extends UnitSpec with BeforeAndAfterEach with WithFakeApp

"return None when DES does not have validated data" in new Setup {

stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$nino")).willReturn(
stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$ninoWithoutSuffix")).willReturn(
aResponse().withStatus(400)))

val result = await(connector.fetchUserInfo(nino))
Expand All @@ -126,7 +127,7 @@ class DesConnectorSpec extends UnitSpec with BeforeAndAfterEach with WithFakeApp

"fail when DES returns a 500 response" in new Setup {

stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$nino")).willReturn(
stubFor(get(urlPathMatching(s"/pay-as-you-earn/individuals/$ninoWithoutSuffix")).willReturn(
aResponse().withStatus(500)))

intercept[Upstream5xxResponse]{await(connector.fetchUserInfo(nino))}
Expand Down

0 comments on commit 06c8d80

Please sign in to comment.