diff --git a/app/uk/gov/hmrc/agentclientrelationships/model/identifiers/NinoWithoutSuffix.scala b/app/uk/gov/hmrc/agentclientrelationships/model/identifiers/NinoWithoutSuffix.scala index d82bd888..7893901b 100644 --- a/app/uk/gov/hmrc/agentclientrelationships/model/identifiers/NinoWithoutSuffix.scala +++ b/app/uk/gov/hmrc/agentclientrelationships/model/identifiers/NinoWithoutSuffix.scala @@ -54,8 +54,6 @@ with SimpleName { case _ => false } - def variations: Seq[String] = value +: Nino.validSuffixes.map(value + _) - } object NinoWithoutSuffix diff --git a/app/uk/gov/hmrc/agentclientrelationships/repository/InvitationsRepository.scala b/app/uk/gov/hmrc/agentclientrelationships/repository/InvitationsRepository.scala index b0eed4fd..4abd074b 100644 --- a/app/uk/gov/hmrc/agentclientrelationships/repository/InvitationsRepository.scala +++ b/app/uk/gov/hmrc/agentclientrelationships/repository/InvitationsRepository.scala @@ -220,7 +220,7 @@ with RequestAwareLogging { suppliedClientIdKey else clientIdKey - Some(in(key, clientIds.flatMap(expandNinoSuffixes).map(encryptedString): _*)) + Some(in(key, clientIds.map(getValidNinoWithoutSuffixOrClientId).map(encryptedString): _*)) } else None, @@ -265,7 +265,7 @@ with RequestAwareLogging { suppliedClientIdKey else clientIdKey, - clientIds.map(_.replaceAll(" ", "")).flatMap(expandNinoSuffixes).map(encryptedString): _* + clientIds.map(_.replaceAll(" ", "")).map(getValidNinoWithoutSuffixOrClientId).map(encryptedString): _* ) ) ) @@ -306,8 +306,8 @@ with RequestAwareLogging { )), Some(equal(serviceKey, service)), Some(or( - in(suppliedClientIdKey, expandNinoSuffixes(clientId).map(encryptedString): _*), - in(clientIdKey, expandNinoSuffixes(clientId).map(encryptedString): _*) // Some deauth requests target the MTDITID for ITSA + equal(suppliedClientIdKey, encryptedString(getValidNinoWithoutSuffixOrClientId(clientId))), + equal(clientIdKey, encryptedString(getValidNinoWithoutSuffixOrClientId(clientId))) // Some deauth requests target the MTDITID for ITSA )), optArn.map(a => equal(arnKey, a)), invitationIdToIgnore @@ -335,7 +335,7 @@ with RequestAwareLogging { .updateOne( and( equal(arnKey, arn.value), - in(clientIdKey, expandNinoSuffixes(nino.value).map(encryptedString): _*), + equal(clientIdKey, encryptedString(nino.value)), equal(serviceKey, service), equal(statusKey, Codecs.toBson[InvitationStatus](PartialAuth)) ), @@ -484,10 +484,10 @@ with RequestAwareLogging { .map(_.getModifiedCount == 1L) } - private def expandNinoSuffixes(clientId: String): Seq[String] = { + private def getValidNinoWithoutSuffixOrClientId(clientId: String): String = { clientId match { - case nino if NinoWithoutSuffix.isValid(nino) => NinoWithoutSuffix(nino).variations - case clientId => Seq(clientId) + case nino if NinoWithoutSuffix.isValid(nino) => NinoWithoutSuffix(nino).value + case clientId => clientId } } diff --git a/app/uk/gov/hmrc/agentclientrelationships/repository/PartialAuthRepository.scala b/app/uk/gov/hmrc/agentclientrelationships/repository/PartialAuthRepository.scala index 57851cf5..aaf221a9 100644 --- a/app/uk/gov/hmrc/agentclientrelationships/repository/PartialAuthRepository.scala +++ b/app/uk/gov/hmrc/agentclientrelationships/repository/PartialAuthRepository.scala @@ -126,7 +126,7 @@ with RequestAwareLogging { HMRCMTDIT, HMRCMTDITSUPP ), - in("nino", nino.variations.map(encryptedString): _*), + equal("nino", encryptedString(nino.value)), equal("arn", arn.value), equal("active", true) ) @@ -136,7 +136,7 @@ with RequestAwareLogging { def findActiveForClient(nino: NinoWithoutSuffix): Future[Seq[PartialAuthRelationship]] = Mdc.preservingMdc { collection - .find(and(in("nino", nino.variations.map(encryptedString): _*), equal("active", true))) + .find(and(equal("nino", encryptedString(nino.value)), equal("active", true))) .toFuture() } @@ -149,7 +149,7 @@ with RequestAwareLogging { .find( and( equal("service", serviceId), - in("nino", nino.variations.map(encryptedString): _*), + equal("nino", encryptedString(nino.value)), equal("arn", arn.value), equal("active", true) ) @@ -159,7 +159,7 @@ with RequestAwareLogging { def findAllForClient(nino: NinoWithoutSuffix): Future[Seq[PartialAuthRelationship]] = Mdc.preservingMdc { collection - .find(in("nino", nino.variations.map(encryptedString): _*)) + .find(equal("nino", encryptedString(nino.value))) .toFuture() } @@ -169,7 +169,7 @@ with RequestAwareLogging { .find( and( equal("service", HMRCMTDIT), - in("nino", NinoWithoutSuffix(nino).variations.map(encryptedString): _*), + equal("nino", encryptedString(NinoWithoutSuffix(nino).value)), equal("active", true) ) ) @@ -186,7 +186,7 @@ with RequestAwareLogging { .updateOne( and( equal("service", serviceId), - in("nino", nino.variations.map(encryptedString): _*), + equal("nino", encryptedString(nino.value)), equal("arn", arn.value), equal("active", true) ), @@ -206,7 +206,7 @@ with RequestAwareLogging { .deleteOne( and( equal("service", serviceId), - in("nino", nino.variations.map(encryptedString): _*), + equal("nino", encryptedString(nino.value)), equal("arn", arn.value), equal("active", true) ) diff --git a/it/test/uk/gov/hmrc/agentclientrelationships/repository/PartialAuthRepositoryISpec.scala b/it/test/uk/gov/hmrc/agentclientrelationships/repository/PartialAuthRepositoryISpec.scala index 2248f5e3..075ad6db 100644 --- a/it/test/uk/gov/hmrc/agentclientrelationships/repository/PartialAuthRepositoryISpec.scala +++ b/it/test/uk/gov/hmrc/agentclientrelationships/repository/PartialAuthRepositoryISpec.scala @@ -52,7 +52,7 @@ with RepositoryCleanupSupport { Instant.parse("2020-02-02T00:00:00.000Z"), "XARN1234567", "HMRC-MTD-IT", - "SX579189D", + "SX579189", active = true, Instant.parse("2020-02-02T00:00:00.000Z") ) @@ -118,7 +118,7 @@ with RepositoryCleanupSupport { Instant.parse("2020-01-01T00:00:00.000Z"), Arn("XARN1234567"), "HMRC-MTD-IT", - NinoWithoutSuffix("SX579189D") + NinoWithoutSuffix("SX579189") ).futureValue intercept[RuntimeException]( @@ -127,7 +127,7 @@ with RepositoryCleanupSupport { Instant.parse("2020-01-01T00:00:00.000Z"), Arn("XARN1234567"), "HMRC-MTD-IT", - NinoWithoutSuffix("SX579189D") + NinoWithoutSuffix("SX579189") )) ) } @@ -140,7 +140,7 @@ with RepositoryCleanupSupport { Instant.parse("2020-01-01T00:00:00.000Z"), Arn("XARN1234567"), "HMRC-MTD-IT", - NinoWithoutSuffix("SX579189D") + NinoWithoutSuffix("SX579189") )) ) } @@ -160,7 +160,7 @@ with RepositoryCleanupSupport { await( repository.findActive( "HMRC-MTD-IT", - NinoWithoutSuffix("SX579189D"), + NinoWithoutSuffix("SX579189"), Arn("XARN1234567") ) ) shouldBe Some(partialAuth) @@ -172,7 +172,7 @@ with RepositoryCleanupSupport { await( repository.findActive( "HMRC-MTD-IT", - NinoWithoutSuffix("SX579189D"), + NinoWithoutSuffix("SX579189"), Arn("XARN1234567") ) ) shouldBe None @@ -184,7 +184,7 @@ with RepositoryCleanupSupport { await( repository.findActive( "HMRC-MTD-IT", - NinoWithoutSuffix("SX579189D"), + NinoWithoutSuffix("SX579189"), Arn("XARN1234567") ) ) shouldBe None @@ -196,7 +196,7 @@ with RepositoryCleanupSupport { await( repository.findActive( "HMRC-MTD-IT", - NinoWithoutSuffix("SX579189D"), + NinoWithoutSuffix("SX579189"), Arn("XARN1234567") ) ) shouldBe None @@ -207,7 +207,7 @@ with RepositoryCleanupSupport { "retrieves records for a given nino" in { await(repository.collection.insertOne(partialAuth).toFuture()) - await(repository.findAllForClient(NinoWithoutSuffix("SX579189D"))) shouldBe Seq(partialAuth) + await(repository.findAllForClient(NinoWithoutSuffix("SX579189"))) shouldBe Seq(partialAuth) } "fail to retrieve records when none are found for the given nino" in { @@ -223,7 +223,7 @@ with RepositoryCleanupSupport { Instant.parse("2020-01-01T00:00:00.000Z"), Arn("XARN1234567"), "HMRC-MTD-IT", - NinoWithoutSuffix("SX579189D") + NinoWithoutSuffix("SX579189") ) ) await(repository.collection.countDocuments().toFuture()) shouldBe 1 @@ -231,7 +231,7 @@ with RepositoryCleanupSupport { repository .deauthorise( "HMRC-MTD-IT", - NinoWithoutSuffix("SX579189D"), + NinoWithoutSuffix("SX579189"), Arn("XARN1234567"), Instant.parse("2020-01-01T00:00:00.000Z") ) @@ -239,7 +239,7 @@ with RepositoryCleanupSupport { val result = await( repository.findActive( "HMRC-MTD-IT", - NinoWithoutSuffix("SX579189D"), + NinoWithoutSuffix("SX579189"), Arn("XARN1234567") ) ) @@ -253,7 +253,7 @@ with RepositoryCleanupSupport { repository .deauthorise( "HMRC-MTD-VAT", - NinoWithoutSuffix("SX579189D"), + NinoWithoutSuffix("SX579189"), Arn("XARN1234567"), Instant.parse("2020-01-01T00:00:00.000Z") ) @@ -263,13 +263,14 @@ with RepositoryCleanupSupport { } "deleteActivePartialAuth" should { + "delete when active record exists" in { await(repository.collection.insertOne(partialAuth).toFuture()) val result = await( repository.deleteActivePartialAuth( "HMRC-MTD-IT", - NinoWithoutSuffix("SX579189D"), + NinoWithoutSuffix("SX579189"), Arn("XARN1234567") ) ) diff --git a/project/AppDependencies.scala b/project/AppDependencies.scala index 9c094fae..7c1e0306 100644 --- a/project/AppDependencies.scala +++ b/project/AppDependencies.scala @@ -1,24 +1,26 @@ import sbt.* object AppDependencies { - private val mongoVer = "2.10.0" + private val bootstrapVer = "10.3.0" - private val pekkoVersion = "1.0.3" + private val mongoVer = "2.10.0" + private val playVer = "play-30" + private val pekkoVer = "1.0.3" + val compile: Seq[ModuleID] = Seq( - "uk.gov.hmrc" %% "bootstrap-backend-play-30" % bootstrapVer, - "uk.gov.hmrc.mongo" %% "hmrc-mongo-play-30" % mongoVer, - "org.typelevel" %% "cats-core" % "2.13.0", - "uk.gov.hmrc" %% "crypto-json-play-30" % "8.4.0", - "io.github.samueleresca" %% "pekko-quartz-scheduler" % "1.2.0-pekko-1.0.x", - "uk.gov.hmrc" %% "domain-play-30" % "11.0.0" + "uk.gov.hmrc" %% s"bootstrap-backend-$playVer" % bootstrapVer, + "uk.gov.hmrc.mongo" %% s"hmrc-mongo-$playVer" % mongoVer, + "uk.gov.hmrc" %% s"domain-$playVer" % "11.0.0", + "uk.gov.hmrc" %% s"crypto-json-$playVer" % "8.4.0", + "org.typelevel" %% "cats-core" % "2.13.0", + "io.github.samueleresca" %% "pekko-quartz-scheduler" % "1.2.0-pekko-1.0.x" ) val test: Seq[ModuleID] = Seq( - "uk.gov.hmrc" %% "bootstrap-test-play-30" % bootstrapVer % Test, - "org.scalatestplus.play" %% "scalatestplus-play" % "7.0.2" % Test, - "uk.gov.hmrc.mongo" %% "hmrc-mongo-test-play-30" % mongoVer % Test, - "org.apache.pekko" %% "pekko-testkit" % pekkoVersion % Test, - "org.apache.pekko" %% "pekko-actor-testkit-typed" % pekkoVersion % Test, - "org.scalacheck" %% "scalacheck" % "1.19.0" % Test - ) + "uk.gov.hmrc" %% s"bootstrap-test-$playVer" % bootstrapVer, + "uk.gov.hmrc.mongo" %% s"hmrc-mongo-test-$playVer" % mongoVer, + "org.apache.pekko" %% "pekko-testkit" % pekkoVer, + "org.apache.pekko" %% "pekko-actor-testkit-typed" % pekkoVer, + "org.scalacheck" %% "scalacheck" % "1.19.0" + ).map(_ % Test) } diff --git a/project/plugins.sbt b/project/plugins.sbt index bc65aec6..966656b2 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -3,11 +3,11 @@ resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always -addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.9") -addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.24.0") -addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.6.0") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4") -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.3.1") +addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.9") +addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.24.0") +addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.6.0") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4") +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.3.1") addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.3.3") addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")