Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/main/scala/uk/gov/hmrc/domain/Itsa.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2021 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.domain

import play.api.libs.json.{Reads, Writes}

case class Itsa(itsa: String) extends TaxIdentifier with SimpleName {
require(Itsa.isValid(itsa), s"$itsa is not a valid itsa.")
override def toString = itsa

private val LengthWithoutSuffix: Int = 8

def value = itsa

val name = "itsa"

def formatted = value.grouped(2).mkString(" ")

def withoutSuffix = value.take(LengthWithoutSuffix)
}

object Itsa extends (String => Itsa) {
implicit val itsaWrite: Writes[Itsa] = new SimpleObjectWrites[Itsa](_.value)
implicit val itsaRead: Reads[Itsa] = new SimpleObjectReads[Itsa]("itsa", Itsa.apply)

// TODO Review the regular expression pattern for ITSA
private val validItsaFormat = "^[a-zA-Z0-9_]*$"

def isValid(itsa: String) = itsa != null && itsa.matches(validItsaFormat)
}
4 changes: 3 additions & 1 deletion src/main/scala/uk/gov/hmrc/domain/taxIds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ case class TaxIds(values: Set[TaxIds.TaxIdWithName]) {
lazy val org = as[Org]
lazy val agentBusinessUtr = as[AgentBusinessUtr]
lazy val psaId = as[PsaId]
lazy val itsa = as[Itsa]
}

object TaxIds {
Expand Down Expand Up @@ -89,7 +90,8 @@ object TaxIds {
SerialisableTaxId("agentbusinessutr", AgentBusinessUtr.apply),
SerialisableTaxId("psaid", PsaId.apply),
SerialisableTaxId("HMRC-OBTDS-ORG", HmrcObtdsOrg.apply),
SerialisableTaxId("HMRC-MTD-VAT", HmrcMtdVat.apply)
SerialisableTaxId("HMRC-MTD-VAT", HmrcMtdVat.apply),
SerialisableTaxId("itsa", Itsa.apply),
)
}

Expand Down
30 changes: 30 additions & 0 deletions src/test/scala/uk/gov/hmrc/domain/ItsaSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2021 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.domain

import org.scalatest.{Matchers, WordSpec}

class ItsaSpec extends WordSpec with Matchers {
import Itsa.isValid

"The validation of an itsa" should {
"pass with valid alphanumerics" in {
isValid("AB123456C") shouldBe true
}
// TODO add more test cases here ...
}
}