Repository: hmrc/customs-manage-authorities-frontend
Pull request #225: MMCA-5229-implement EUEORI guarding for getXiEori calls
Author: login: AdamCoops
Created: 2025-03-19T11:01:17Z | Merged: 2025-03-20T16:45:51Z



Diff:
diff --git a/app/connectors/CustomsDataStoreConnector.scala b/app/connectors/CustomsDataStoreConnector.scala
index 07af2d2a..168e99a5 100644
--- a/app/connectors/CustomsDataStoreConnector.scala
+++ b/app/connectors/CustomsDataStoreConnector.scala
@@ -28,6 +28,7 @@ import uk.gov.hmrc.auth.core.retrieve.Email
 import uk.gov.hmrc.http.HttpReads.Implicits._
 import uk.gov.hmrc.http.{HeaderCarrier, HttpErrorFunctions, StringContextOps, UpstreamErrorResponse}
 import uk.gov.hmrc.http.client.HttpClientV2
+import utils.Constants.NON_EU_EORI_PREFIXES
 
 import javax.inject.Inject
 import scala.concurrent.{ExecutionContext, Future}
@@ -76,11 +77,11 @@ class CustomsDataStoreConnector @Inject() (appConfig: FrontendAppConfig, httpCli
       }
   }
 
-  def getXiEori(implicit hc: HeaderCarrier): Future[Option[String]] = {
+  def getXiEori(eori: String)(implicit hc: HeaderCarrier): Future[Option[String]] = {
     val endpoint                 = s"$baseDataStoreUrl/eori/xieori-information"
     val isXiEoriEnabled: Boolean = appConfig.xiEoriEnabled
 
-    if (isXiEoriEnabled) {
+    if (isXiEoriEnabled && NON_EU_EORI_PREFIXES.exists(prefix => eori.startsWith(prefix))) {
       httpClient
         .get(url"$endpoint")
         .execute[XiEoriInformationResponse]
diff --git a/app/controllers/ManageAuthoritiesController.scala b/app/controllers/ManageAuthoritiesController.scala
index 92496964..4d0d247e 100644
--- a/app/controllers/ManageAuthoritiesController.scala
+++ b/app/controllers/ManageAuthoritiesController.scala
@@ -69,7 +69,7 @@ class ManageAuthoritiesController @Inject() (
     val returnToUrl = appConfig.manageAuthoritiesServiceUrl + routes.ManageAuthoritiesController.onPageLoad().url
 
     val response = for {
-      xiEori                 <- dataStoreConnector.getXiEori
+      xiEori                 <- dataStoreConnector.getXiEori(request.eoriNumber)
       accountsFromCache      <- accountsCacheService.retrieveAccountsForId(request.internalId)
       accounts               <- fetchAccounts(xiEori, accountsFromCache)
       authoritiesFromCache   <- service.retrieveAuthoritiesForId(request.internalId)
@@ -106,7 +106,7 @@ class ManageAuthoritiesController @Inject() (
   def fetchAuthoritiesOnMIDVAHomePageLoad(eori: EORI): Action[AnyContent] =
     (identify andThen checkEmailIsVerified).async { implicit request =>
       val fetchedAuthorities: Future[Option[AuthoritiesWithId]] = for {
-        xiEori      <- dataStoreConnector.getXiEori
+        xiEori      <- dataStoreConnector.getXiEori(request.eoriNumber)
         accounts    <- getAllAccounts(eori, xiEori)
         authorities <- getAllAuthorities(eori, xiEori, accounts)
       } yield authorities
diff --git a/app/controllers/add/AuthorisedUserController.scala b/app/controllers/add/AuthorisedUserController.scala
index 0ba706d7..e95f6f1e 100644
--- a/app/controllers/add/AuthorisedUserController.scala
+++ b/app/controllers/add/AuthorisedUserController.scala
@@ -73,7 +73,7 @@ class AuthorisedUserController @Inject() (
   def onSubmit(): Action[AnyContent] =
     (identify andThen getData andThen requireData andThen verifyAccountNumbers).async { implicit request =>
       for {
-        xiEori <- dataStore.getXiEori
+        xiEori <- dataStore.getXiEori(request.eoriNumber)
         result <- doSubmission(request.userAnswers, xiEori.getOrElse(emptyString), request.eoriNumber)
       } yield result
     }
diff --git a/app/controllers/add/EoriNumberController.scala b/app/controllers/add/EoriNumberController.scala
index 4a44e80d..467ae660 100644
--- a/app/controllers/add/EoriNumberController.scala
+++ b/app/controllers/add/EoriNumberController.scala
@@ -91,7 +91,7 @@ class EoriNumberController @Inject() (
       errorView(mode, inputEoriNumber, "eoriNumber.error.authorise-own-eori")(request, msgs, appConfig)
     } else {
       val result = for {
-        xiEori: Option[String] <- dataStore.getXiEori
+        xiEori: Option[String] <- dataStore.getXiEori(request.eoriNumber)
       } yield performXiEoriChecks(xiEori, inputEoriNumber, eori, mode, request, hc, msgs)
 
       result.flatten
diff --git a/app/controllers/edit/EditCheckYourAnswersController.scala b/app/controllers/edit/EditCheckYourAnswersController.scala
index ecea1f74..25a62ce8 100644
--- a/app/controllers/edit/EditCheckYourAnswersController.scala
+++ b/app/controllers/edit/EditCheckYourAnswersController.scala
@@ -89,7 +89,7 @@ class EditCheckYourAnswersController @Inject() (
 
         case Right(AccountAndAuthority(account, authority)) =>
           for {
-            xiEori <- dataStore.getXiEori
+            xiEori <- dataStore.getXiEori(request.eoriNumber)
             result <- doSubmission(
                         request.userAnswers,
                         accountId,
diff --git a/app/controllers/remove/RemoveCheckYourAnswers.scala b/app/controllers/remove/RemoveCheckYourAnswers.scala
index d3b7e555..1b953d92 100644
--- a/app/controllers/remove/RemoveCheckYourAnswers.scala
+++ b/app/controllers/remove/RemoveCheckYourAnswers.scala
@@ -84,7 +84,7 @@ class RemoveCheckYourAnswers @Inject() (
 
         case Right(AccountAndAuthority(account, authority)) =>
           for {
-            xiEori <- dataStore.getXiEori
+            xiEori <- dataStore.getXiEori(request.eoriNumber)
             result <- request.userAnswers
                         .get(RemoveAuthorisedUserPage(accountId, authorityId))
                         .map { authorisedUser =>
diff --git a/app/utils/Constants.scala b/app/utils/Constants.scala
index f86fe657..e26efe91 100644
--- a/app/utils/Constants.scala
+++ b/app/utils/Constants.scala
@@ -32,4 +32,6 @@ object Constants {
 
   val ENROLMENT_KEY        = "HMRC-CUS-ORG"
   val ENROLMENT_IDENTIFIER = "EORINumber"
+
+  val NON_EU_EORI_PREFIXES = Set("GB", "XI")
 }
diff --git a/test/connectors/CustomsDataStoreConnectorSpec.scala b/test/connectors/CustomsDataStoreConnectorSpec.scala
index 92c67445..6dbf55fd 100644
--- a/test/connectors/CustomsDataStoreConnectorSpec.scala
+++ b/test/connectors/CustomsDataStoreConnectorSpec.scala
@@ -20,16 +20,16 @@ import base.SpecBase
 import com.github.tomakehurst.wiremock.client.WireMock._
 import config.FrontendAppConfig
 import models.{EmailVerifiedResponse, UndeliverableEmail, UnverifiedEmail}
-import org.mockito.Mockito.when
 import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
 import org.scalatest.{EitherValues, OptionValues}
 import org.scalatestplus.mockito.MockitoSugar
+import org.mockito.Mockito._
 import play.api.inject.guice.GuiceApplicationBuilder
 import play.api.test.Helpers.running
 import play.api.{Application, inject}
+import utils.WireMockHelper
 import uk.gov.hmrc.auth.core.retrieve.Email
 import uk.gov.hmrc.http.HeaderCarrier
-import utils.WireMockHelper
 
 class CustomsDataStoreConnectorSpec
     extends SpecBase
@@ -205,11 +205,12 @@ class CustomsDataStoreConnectorSpec
         result mustBe expected
       }
     }
+  }
 
-    ".get XiEori" must {
-      "return xi eori when it is returned from data store" in new Setup {
-        val response: String =
-          """
+  ".get XiEori" must {
+    "return xi eori when it is returned from data store" in new Setup {
+      val response: String =
+        """
             |{
             |   "xiEori":"XI1234567",
             |   "consent":"1",
@@ -221,23 +222,23 @@ class CustomsDataStoreConnectorSpec
             |}
             |""".stripMargin
 
-        val expectedResult: Option[String] = Some("XI1234567")
+      val expectedResult: Option[String] = Some("XI1234567")
 
-        running(app) {
+      running(app) {
 
-          server.stubFor(
-            get(urlEqualTo("/customs-data-store/eori/xieori-information"))
-              .willReturn(ok(response))
-          )
+        server.stubFor(
+          get(urlEqualTo("/customs-data-store/eori/xieori-information"))
+            .willReturn(ok(response))
+        )
 
-          val result = connector.getXiEori.futureValue
-          result mustBe expectedResult
-        }
+        val result = connector.getXiEori("GB123456789").futureValue
+        result mustBe expectedResult
       }
+    }
 
-      "return None when empty XI EORI value is returned from data store" in new Setup {
-        val response: String =
-          """
+    "return None when empty XI EORI value is returned from data store" in new Setup {
+      val response: String =
+        """
             |{
             |   "xiEori":"",
             |   "consent":"1",
@@ -249,38 +250,38 @@ class CustomsDataStoreConnectorSpec
             |}
             |""".stripMargin
 
-        running(app) {
+      running(app) {
 
-          server.stubFor(
-            get(urlEqualTo("/customs-data-store/eori/xieori-information"))
-              .willReturn(ok(response))
-          )
-          val result = connector.getXiEori.futureValue
-          result mustBe expected
-        }
+        server.stubFor(
+          get(urlEqualTo("/customs-data-store/eori/xieori-information"))
+            .willReturn(ok(response))
+        )
+        val result = connector.getXiEori("GB123456789").futureValue
+        result mustBe expected
       }
+    }
 
-      "return None when error response is returned" in new Setup {
+    "return None when error response is returned" in new Setup {
 
-        running(app) {
+      running(app) {
 
-          server.stubFor(
-            get(urlEqualTo("/customs-data-store/eori/xieori-information"))
-              .willReturn(serverError())
-          )
-          val result = connector.getXiEori.futureValue
-          result mustBe expected
-        }
+        server.stubFor(
+          get(urlEqualTo("/customs-data-store/eori/xieori-information"))
+            .willReturn(serverError())
+        )
+        val result = connector.getXiEori("GB123456789").futureValue
+        result mustBe expected
       }
+    }
 
-      "return None when feature flag is false" in {
+    "return None when feature flag is false" in {
 
-        val mockAppConfig = mock[FrontendAppConfig]
-        when(mockAppConfig.xiEoriEnabled).thenReturn(false)
-        when(mockAppConfig.customsDataStore).thenReturn("some/string")
+      val mockAppConfig = mock[FrontendAppConfig]
+      when(mockAppConfig.xiEoriEnabled).thenReturn(false)
+      when(mockAppConfig.customsDataStore).thenReturn("some/string")
 
-        val response =
-          """
+      val response =
+        """
             |{
             |   "xiEori":"",
             |   "consent":"1",
@@ -292,139 +293,172 @@ class CustomsDataStoreConnectorSpec
             |}
             |""".stripMargin
 
-        val application: Application =
-          new GuiceApplicationBuilder()
-            .overrides(inject.bind[FrontendAppConfig].toInstance(mockAppConfig))
-            .configure("microservice.services.customs-data-store.port" -> server.port)
-            .build()
+      val application: Application =
+        new GuiceApplicationBuilder()
+          .overrides(inject.bind[FrontendAppConfig].toInstance(mockAppConfig))
+          .configure("microservice.services.customs-data-store.port" -> server.port)
+          .build()
 
-        val connector = application.injector.instanceOf[CustomsDataStoreConnector]
+      val connector = application.injector.instanceOf[CustomsDataStoreConnector]
 
-        running(application) {
+      running(application) {
 
-          server.stubFor(
-            get(urlEqualTo("/customs-data-store/eori/xieori-information"))
-              .willReturn(ok(response))
-          )
+        server.stubFor(
+          get(urlEqualTo("/customs-data-store/eori/xieori-information"))
+            .willReturn(ok(response))
+        )
 
-          val result = connector.getXiEori.futureValue
-          result mustBe None
-        }
+        val result = connector.getXiEori("GB123456789").futureValue
+        result mustBe None
       }
     }
 
-    "getEmail" should {
-      "return an email address when the request is successful and undeliverable" +
-        " is not present in the response" in new Setup {
+    "return None when an EU Eori is passed" in new Setup {
+      running(app) {
+        val result = connector.getXiEori("FR123456789").futureValue
+        result mustBe None
+      }
+    }
 
-          val emailResponse: String =
-            """{
-            |"address": "some@email.com"
-            |}""".stripMargin
+    "return an EORI when an GB Eori is passed" in new Setup {
 
-          running(app) {
+      val response: String =
+        """
+          |{
+          |   "xiEori":"GB123456789",
+          |   "consent":"1",
+          |   "address":{
+          |      "pbeAddressLine1":"86 street",
+          |      "pbeAddressLine2":"London",
+          |      "pbeAddressLine3":"GB"
+          |   }
+          |}
+          |""".stripMargin
 
-            server.stubFor(
-              get(urlEqualTo("/customs-data-store/eori/verified-email"))
-                .willReturn(ok(emailResponse))
-            )
-            val result = connector.getEmail.futureValue
-            result mustBe Right(Email("some@email.com"))
-          }
-        }
+      running(app) {
+
+        server.stubFor(
+          get(urlEqualTo("/customs-data-store/eori/xieori-information"))
+            .willReturn(ok(response))
+        )
+
+        val result = connector.getXiEori("GB123456789").futureValue
+        result mustBe Some("GB123456789")
+      }
+    }
+  }
+
+  "getEmail" should {
+    "return an email address when the request is successful and undeliverable" +
+      " is not present in the response" in new Setup {
 
-      "return no email address when the request is successful and undeliverable is present in the response" in new Setup {
         val emailResponse: String =
           """{
-            |"address": "some@email.com",
-            |"timestamp": "2022-10-10T11:22:22Z",
-            |"undeliverable": {
-            |"subject": "someSubject"
-            |}
+            |"address": "some@email.com"
             |}""".stripMargin
 
         running(app) {
+
           server.stubFor(
             get(urlEqualTo("/customs-data-store/eori/verified-email"))
               .willReturn(ok(emailResponse))
           )
-
           val result = connector.getEmail.futureValue
-          result mustBe Left(UndeliverableEmail("some@email.com"))
+          result mustBe Right(Email("some@email.com"))
         }
       }
 
-      "return unverifiedEmail when the request is successful and" +
-        " email address is not present in the response" in new Setup {
-          val emailResponse = """{}"""
+    "return no email address when the request is successful and undeliverable is present in the response" in new Setup {
+      val emailResponse: String =
+        """{
+            |"address": "some@email.com",
+            |"timestamp": "2022-10-10T11:22:22Z",
+            |"undeliverable": {
+            |"subject": "someSubject"
+            |}
+            |}""".stripMargin
 
-          running(app) {
-            server.stubFor(
-              get(urlEqualTo("/customs-data-store/eori/verified-email"))
-                .willReturn(ok(emailResponse))
-            )
+      running(app) {
+        server.stubFor(
+          get(urlEqualTo("/customs-data-store/eori/verified-email"))
+            .willReturn(ok(emailResponse))
+        )
 
-            val result = connector.getEmail.futureValue
-            result mustBe Left(UnverifiedEmail)
-          }
-        }
+        val result = connector.getEmail.futureValue
+        result mustBe Left(UndeliverableEmail("some@email.com"))
+      }
+    }
 
-      "return no email when a NOT_FOUND response is returned" in new Setup {
+    "return unverifiedEmail when the request is successful and" +
+      " email address is not present in the response" in new Setup {
+        val emailResponse = """{}"""
 
         running(app) {
-
           server.stubFor(
             get(urlEqualTo("/customs-data-store/eori/verified-email"))
-              .willReturn(notFound)
+              .willReturn(ok(emailResponse))
           )
+
           val result = connector.getEmail.futureValue
           result mustBe Left(UnverifiedEmail)
         }
       }
+
+    "return no email when a NOT_FOUND response is returned" in new Setup {
+
+      running(app) {
+
+        server.stubFor(
+          get(urlEqualTo("/customs-data-store/eori/verified-email"))
+            .willReturn(notFound)
+        )
+        val result = connector.getEmail.futureValue
+        result mustBe Left(UnverifiedEmail)
+      }
     }
+  }
 
-    "unverifiedEmail" must {
+  "unverifiedEmail" must {
 
-      "return success response" in new Setup {
+    "return success response" in new Setup {
 
-        running(app) {
-          server.stubFor(
-            get(urlEqualTo("/customs-data-store/subscriptions/unverified-email-display"))
-              .willReturn(ok("""{"unVerifiedEmail": "unverified@email.com"}"""))
-          )
+      running(app) {
+        server.stubFor(
+          get(urlEqualTo("/customs-data-store/subscriptions/unverified-email-display"))
+            .willReturn(ok("""{"unVerifiedEmail": "unverified@email.com"}"""))
+        )
 
-          val result = connector.unverifiedEmail(hc).futureValue
-          result mustBe Some("unverified@email.com")
-        }
+        val result = connector.unverifiedEmail(hc).futureValue
+        result mustBe Some("unverified@email.com")
       }
+    }
 
-      "return failure response of None" in new Setup {
+    "return failure response of None" in new Setup {
 
-        running(app) {
-          server.stubFor(
-            get(urlEqualTo("/customs-data-store/subscriptions/unverified-email-display"))
-              .willReturn(ok("""{}"""))
-          )
+      running(app) {
+        server.stubFor(
+          get(urlEqualTo("/customs-data-store/subscriptions/unverified-email-display"))
+            .willReturn(ok("""{}"""))
+        )
 
-          val result = connector.unverifiedEmail(hc).futureValue
-          result mustBe None
-        }
+        val result = connector.unverifiedEmail(hc).futureValue
+        result mustBe None
       }
     }
+  }
 
-    "verifiedEmail" must {
+  "verifiedEmail" must {
 
-      "return correct email" in new Setup {
+    "return correct email" in new Setup {
 
-        running(app) {
-          server.stubFor(
-            get(urlEqualTo("/customs-data-store/subscriptions/email-display"))
-              .willReturn(ok("""{"verifiedEmail": "test@test.com"}"""))
-          )
+      running(app) {
+        server.stubFor(
+          get(urlEqualTo("/customs-data-store/subscriptions/email-display"))
+            .willReturn(ok("""{"verifiedEmail": "test@test.com"}"""))
+        )
 
-          val result = connector.verifiedEmail(hc).futureValue
-          result mustBe emailVerifiedRes
-        }
+        val result = connector.verifiedEmail(hc).futureValue
+        result mustBe emailVerifiedRes
       }
     }
   }
diff --git a/test/controllers/ManageAuthoritiesControllerSpec.scala b/test/controllers/ManageAuthoritiesControllerSpec.scala
index 86c5b640..adf4a93e 100644
--- a/test/controllers/ManageAuthoritiesControllerSpec.scala
+++ b/test/controllers/ManageAuthoritiesControllerSpec.scala
@@ -128,7 +128,7 @@ class ManageAuthoritiesControllerSpec extends SpecBase with MockitoSugar with Da
         val mockSecureMessageConnector: SecureMessageConnector                     = mock[SecureMessageConnector]
         val mockSdesConnector: SdesConnector                                       = mock[SdesConnector]
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some(XI_EORI)))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some(XI_EORI)))
         when(mockDataStoreConnector.getEmail(any)).thenReturn(Future.successful(Right(testEmail)))
         when(mockDataStoreConnector.getCompanyName(any)).thenReturn(Future.successful(Some(COMPANY_NAME)))
 
@@ -198,7 +198,7 @@ class ManageAuthoritiesControllerSpec extends SpecBase with MockitoSugar with Da
           mock[AuthorisedEoriAndCompanyInfoService]
         val mockSdesConnector: SdesConnector                                   = mock[SdesConnector]
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some(XI_EORI)))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some(XI_EORI)))
         when(mockDataStoreConnector.getEmail(any)).thenReturn(Future.successful(Right(testEmail)))
         when(mockDataStoreConnector.getCompanyName(any)).thenReturn(Future.successful(Some(COMPANY_NAME)))
         when(mockAccountsRepository.get(any())).thenReturn(Future.successful(Some(accounts)))
@@ -408,7 +408,7 @@ class ManageAuthoritiesControllerSpec extends SpecBase with MockitoSugar with Da
         .thenReturn(Future.successful(authoritiesWithId))
 
       when(mockDataStoreConnector.getEmail(any())).thenReturn(Future.successful(Right(testEmail)))
-      when(mockDataStoreConnector.getXiEori(any())).thenReturn(Future.successful(Some(XI_EORI)))
+      when(mockDataStoreConnector.getXiEori(any)(any())).thenReturn(Future.successful(Some(XI_EORI)))
       when(mockAuthAndCompanyRepo.get(any)).thenReturn(Future.successful(None))
 
       when(mockAuthAndCompanyInfoService.retrieveAuthorisedEoriAndCompanyInfo(any, any)(any))
@@ -460,7 +460,7 @@ class ManageAuthoritiesControllerSpec extends SpecBase with MockitoSugar with Da
       when(mockAuthAndCompanyRepo.get(any)).thenReturn(Future.successful(None))
 
       when(mockDataStoreConnector.getEmail(any())).thenReturn(Future.successful(Right(testEmail)))
-      when(mockDataStoreConnector.getXiEori(any())).thenReturn(Future.successful(Some(XI_EORI)))
+      when(mockDataStoreConnector.getXiEori(any)(any())).thenReturn(Future.successful(Some(XI_EORI)))
 
       private val application: Application = applicationBuilder(userAnswers = Some(emptyUserAnswers))
         .overrides(
@@ -504,7 +504,7 @@ class ManageAuthoritiesControllerSpec extends SpecBase with MockitoSugar with Da
       when(mockAccountsCacheService.retrieveAccounts(any(), any())(any())).thenReturn(Future.successful(accounts))
 
       when(mockDataStoreConnector.getEmail(any())).thenReturn(Future.successful(Right(testEmail)))
-      when(mockDataStoreConnector.getXiEori(any())).thenReturn(Future.successful(Some(XI_EORI)))
+      when(mockDataStoreConnector.getXiEori(any)(any())).thenReturn(Future.successful(Some(XI_EORI)))
 
       private val application: Application = applicationBuilder(userAnswers = Some(emptyUserAnswers))
         .overrides(
@@ -551,7 +551,7 @@ class ManageAuthoritiesControllerSpec extends SpecBase with MockitoSugar with Da
         .thenReturn(Future.successful(authoritiesWithId02))
 
       when(mockDataStoreConnector.getEmail(any())).thenReturn(Future.successful(Right(testEmail)))
-      when(mockDataStoreConnector.getXiEori(any())).thenReturn(Future.successful(Some(XI_EORI)))
+      when(mockDataStoreConnector.getXiEori(any)(any())).thenReturn(Future.successful(Some(XI_EORI)))
 
       when(mockDataStoreConnector.getCompanyName)
         .thenReturn(Future.failed(new RuntimeException("Failed")))
diff --git a/test/controllers/actions/VerifyAccountNumbersActionSpec.scala b/test/controllers/actions/VerifyAccountNumbersActionSpec.scala
index fc6df838..bd418fd4 100644
--- a/test/controllers/actions/VerifyAccountNumbersActionSpec.scala
+++ b/test/controllers/actions/VerifyAccountNumbersActionSpec.scala
@@ -29,7 +29,7 @@ import play.api.http.Status.SEE_OTHER
 import play.api.mvc.{AnyContentAsEmpty, ResponseHeader, Result}
 import services.AuthorisedAccountsService
 import uk.gov.hmrc.auth.core.AffinityGroup.Organisation
-import uk.gov.hmrc.auth.core.retrieve.{Credentials, Name}
+import uk.gov.hmrc.auth.core.retrieve.Credentials
 import utils.StringUtils.emptyString
 
 import scala.concurrent.ExecutionContext.Implicits.global
diff --git a/test/controllers/add/AuthorisedUserControllerSpec.scala b/test/controllers/add/AuthorisedUserControllerSpec.scala
index 810baa7f..ecb34e64 100644
--- a/test/controllers/add/AuthorisedUserControllerSpec.scala
+++ b/test/controllers/add/AuthorisedUserControllerSpec.scala
@@ -126,7 +126,7 @@ class AuthorisedUserControllerSpec extends SpecBase with MockitoSugar {
 
       when(mockValidator.validate(userAnswers)).thenReturn(Some((accounts, standingAuthority, authorisedUser)))
 
-      when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some(xiEori)))
+      when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some(xiEori)))
       when(mockConnector.grantAccountAuthorities(any, any)(any)).thenReturn(Future.successful(true))
 
       running(app) {
@@ -148,7 +148,7 @@ class AuthorisedUserControllerSpec extends SpecBase with MockitoSugar {
 
         when(mockValidator.validate(userAnswers))
           .thenReturn(Some((accountsWithDDCashAndGuarantee, standingAuthority, authorisedUser)))
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some(xiEori)))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some(xiEori)))
 
         when(mockConnector.grantAccountAuthorities(any, ArgumentMatchers.eq(xiEori))(any))
           .thenReturn(Future.successful(true))
@@ -175,7 +175,7 @@ class AuthorisedUserControllerSpec extends SpecBase with MockitoSugar {
 
         when(mockValidator.validate(userAnswers))
           .thenReturn(Some((accountsWithDDCashAndGuarantee, standingAuthority, authorisedUser)))
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some(xiEori)))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some(xiEori)))
 
         when(mockConnector.grantAccountAuthorities(any, ArgumentMatchers.eq(xiEori))(any))
           .thenReturn(Future.successful(true))
@@ -200,7 +200,7 @@ class AuthorisedUserControllerSpec extends SpecBase with MockitoSugar {
 
         when(mockValidator.validate(userAnswers))
           .thenReturn(Some((accountsWithDDCashAndGuarantee, standingAuthority, authorisedUser)))
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(None))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(None))
 
         when(mockConnector.grantAccountAuthorities(any, ArgumentMatchers.eq(euEori))(any))
           .thenReturn(Future.successful(true))
@@ -225,7 +225,7 @@ class AuthorisedUserControllerSpec extends SpecBase with MockitoSugar {
 
         when(mockValidator.validate(userAnswers))
           .thenReturn(Some((accountsWithDDCashAndGuarantee, standingAuthority, authorisedUser)))
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some(xiEori)))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some(xiEori)))
 
         when(mockConnector.grantAccountAuthorities(any, ArgumentMatchers.eq(xiEori))(any))
           .thenReturn(Future.successful(false))
@@ -254,10 +254,12 @@ class AuthorisedUserControllerSpec extends SpecBase with MockitoSugar {
 
         when(mockValidator.validate(userAnswers))
           .thenReturn(Some((accountsWithDDCashAndGuarantee, standingAuthority, authorisedUser)))
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some(xiEori)))
+
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some(xiEori)))
 
         when(mockConnector.grantAccountAuthorities(any, ArgumentMatchers.eq(xiEori))(any))
           .thenReturn(Future.successful(true))
+
         when(mockConnector.grantAccountAuthorities(any, ArgumentMatchers.eq(gbEori))(any))
           .thenReturn(Future.successful(false))
 
@@ -284,7 +286,9 @@ class AuthorisedUserControllerSpec extends SpecBase with MockitoSugar {
 
         when(mockValidator.validate(userAnswers))
           .thenReturn(Some((accountsWithDDCashAndGuarantee, standingAuthority, authorisedUser)))
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some(xiEori)))
+
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some(xiEori)))
+
         when(mockConnector.grantAccountAuthorities(any, ArgumentMatchers.eq(gbEori))(any))
           .thenReturn(Future.successful(true))
 
@@ -305,7 +309,7 @@ class AuthorisedUserControllerSpec extends SpecBase with MockitoSugar {
 
       when(mockValidator.validate(userAnswers)).thenReturn(Some((accounts, standingAuthority, authorisedUser)))
 
-      when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some(xiEori)))
+      when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some(xiEori)))
       when(mockConnector.grantAccountAuthorities(any, any)(any)).thenReturn(Future.successful(false))
 
       running(app) {
diff --git a/test/controllers/add/EoriNumberControllerSpec.scala b/test/controllers/add/EoriNumberControllerSpec.scala
index c29c79f7..21b3091c 100644
--- a/test/controllers/add/EoriNumberControllerSpec.scala
+++ b/test/controllers/add/EoriNumberControllerSpec.scala
@@ -347,7 +347,8 @@ class EoriNumberControllerSpec extends SpecBase with MockitoSugar {
         val mockSessionRepository: SessionRepository = mock[SessionRepository]
 
         when(mockSessionRepository.set(any())) thenReturn Future.successful(true)
-        when(mockDataStoreConnector.getXiEori(any[HeaderCarrier])).thenReturn(Future.successful(None))
+        when(mockDataStoreConnector.getXiEori(any)(any[HeaderCarrier])).thenReturn(Future.successful(None))
+
         when(mockDataStoreConnector.retrieveCompanyInformationThirdParty(any())(any()))
           .thenReturn(Future.successful(None))
 
@@ -466,7 +467,7 @@ class EoriNumberControllerSpec extends SpecBase with MockitoSugar {
         val mockSessionRepository: SessionRepository = mock[SessionRepository]
 
         when(mockSessionRepository.set(any())) thenReturn Future.successful(true)
-        when(mockDataStoreConnector.getXiEori(any[HeaderCarrier]))
+        when(mockDataStoreConnector.getXiEori(any)(any[HeaderCarrier]))
           .thenReturn(Future.successful(Some("XI123456789012")))
 
         val application: Application =
diff --git a/test/controllers/edit/EditAuthorisedUserControllerSpec.scala b/test/controllers/edit/EditAuthorisedUserControllerSpec.scala
index 8f7adc53..b3170952 100644
--- a/test/controllers/edit/EditAuthorisedUserControllerSpec.scala
+++ b/test/controllers/edit/EditAuthorisedUserControllerSpec.scala
@@ -40,7 +40,8 @@ class EditAuthorisedUserControllerSpec extends SpecBase with MockitoSugar {
       val app: Application = applicationBuilder(
         emptyUserAnswers.set(EditAuthorisedUserPage("a", "b"), AuthorisedUser("test", "test2")).toOption
       ).build()
-      val appConfig        = app.injector.instanceOf[FrontendAppConfig]
+
+      val appConfig = app.injector.instanceOf[FrontendAppConfig]
 
       val form: AuthorisedUserFormProvider = app.injector.instanceOf[AuthorisedUserFormProvider]
       val view: EditAuthorisedUserView     = app.injector.instanceOf[EditAuthorisedUserView]
diff --git a/test/controllers/edit/EditCheckYourAnswersControllerSpec.scala b/test/controllers/edit/EditCheckYourAnswersControllerSpec.scala
index 17fb2726..857d1bfc 100644
--- a/test/controllers/edit/EditCheckYourAnswersControllerSpec.scala
+++ b/test/controllers/edit/EditCheckYourAnswersControllerSpec.scala
@@ -218,7 +218,7 @@ class EditCheckYourAnswersControllerSpec extends SpecBase with MockitoSugar {
       when(mockAuthCacheService.getAccountAndAuthority(any(), any(), any())(any()))
         .thenReturn(Future.successful(Right(AccountAndAuthority(accountsWithAuthoritiesWithId, standingAuthority))))
 
-      when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some("XI123456789012")))
+      when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some("XI123456789012")))
 
       val accounts: Accounts = Accounts(
         Some(AccountWithAuthorities(CdsCashAccount, "12345", Some(AccountStatusOpen), Seq.empty)),
@@ -272,7 +272,7 @@ class EditCheckYourAnswersControllerSpec extends SpecBase with MockitoSugar {
             Future.successful(Right(AccountAndAuthority(accountsWithAuthoritiesWithId, standingAuthorityForXI)))
           )
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some("XI123456789012")))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some("XI123456789012")))
 
         val accounts: Accounts = Accounts(
           Some(AccountWithAuthorities(CdsCashAccount, "12345", Some(AccountStatusOpen), Seq.empty)),
@@ -331,7 +331,7 @@ class EditCheckYourAnswersControllerSpec extends SpecBase with MockitoSugar {
             Future.successful(Right(AccountAndAuthority(accountsWithAuthoritiesWithId, standingAuthorityForXI)))
           )
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some("XI123456789012")))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some("XI123456789012")))
 
         val accounts: Accounts = Accounts(
           Some(AccountWithAuthorities(CdsCashAccount, "12345", Some(AccountStatusOpen), Seq.empty)),
@@ -391,7 +391,8 @@ class EditCheckYourAnswersControllerSpec extends SpecBase with MockitoSugar {
             Future.successful(Right(AccountAndAuthority(accountsWithAuthoritiesWithId, standingAuthorityForXI)))
           )
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some("XI123456789012")))
+        when(mockDataStoreConnector.getXiEori(any)(any))
+          .thenReturn(Future.successful(Some("XI123456789012")))
 
         val accounts: Accounts = Accounts(
           Some(AccountWithAuthorities(CdsCashAccount, "12345", Some(AccountStatusOpen), Seq.empty)),
@@ -449,7 +450,7 @@ class EditCheckYourAnswersControllerSpec extends SpecBase with MockitoSugar {
         when(mockAuthCacheService.getAccountAndAuthority(any(), any(), any())(any()))
           .thenReturn(Future.successful(Right(AccountAndAuthority(accountsWithAuthoritiesWithId, standingAuthority))))
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some("XI123456789012")))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some("XI123456789012")))
 
         val accounts: Accounts = Accounts(
           Some(AccountWithAuthorities(CdsCashAccount, "12345", Some(AccountStatusOpen), Seq.empty)),
@@ -504,7 +505,7 @@ class EditCheckYourAnswersControllerSpec extends SpecBase with MockitoSugar {
         when(mockAuthCacheService.getAccountAndAuthority(any(), any(), any())(any()))
           .thenReturn(Future.successful(Right(AccountAndAuthority(accountsWithAuthoritiesWithId, standingAuthority))))
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(None))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(None))
 
         val accounts: Accounts = Accounts(
           Some(AccountWithAuthorities(CdsCashAccount, "12345", Some(AccountStatusOpen), Seq.empty)),
@@ -568,7 +569,7 @@ class EditCheckYourAnswersControllerSpec extends SpecBase with MockitoSugar {
             )
           )
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some("XI123456789012")))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some("XI123456789012")))
 
         when(mockEditAuthorityValidationService.validate(any, any, any, any, any)).thenReturn(
           Right(
@@ -614,7 +615,7 @@ class EditCheckYourAnswersControllerSpec extends SpecBase with MockitoSugar {
         when(mockAuthCacheService.getAccountAndAuthority(any(), any(), any())(any()))
           .thenReturn(Future.successful(Right(AccountAndAuthority(accountsWithAuthoritiesWithId, standingAuthority))))
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some("XI123456789012")))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some("XI123456789012")))
 
         val accounts: Accounts = Accounts(
           Some(AccountWithAuthorities(CdsCashAccount, "12345", Some(AccountStatusOpen), Seq.empty)),
@@ -666,7 +667,7 @@ class EditCheckYourAnswersControllerSpec extends SpecBase with MockitoSugar {
         when(mockAuthCacheService.getAccountAndAuthority(any(), any(), any())(any()))
           .thenReturn(Future.successful(Right(AccountAndAuthority(accountsWithAuthoritiesWithId, standingAuthority))))
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future.successful(Some("XI123456789012")))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future.successful(Some("XI123456789012")))
         when(mockEditAuthorityValidationService.validate(any, any, any, any, any)).thenReturn(Left(UnknownAccountType))
 
         running(application) {
diff --git a/test/controllers/remove/RemoveCheckYourAnswersControllerSpec.scala b/test/controllers/remove/RemoveCheckYourAnswersControllerSpec.scala
index e0537b43..481dcaf4 100644
--- a/test/controllers/remove/RemoveCheckYourAnswersControllerSpec.scala
+++ b/test/controllers/remove/RemoveCheckYourAnswersControllerSpec.scala
@@ -232,7 +232,7 @@ class RemoveCheckYourAnswersControllerSpec extends SpecBase with MockitoSugar {
         when(mockCustomsFinancialsConnector.revokeAccountAuthorities(any(), ArgumentMatchers.eq(gbEori))(any()))
           .thenReturn(Future.successful(true))
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future(Option(xiEori)))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future(Option(xiEori)))
 
         running(app) {
           val result = route(app, postRequest).value
@@ -267,7 +267,7 @@ class RemoveCheckYourAnswersControllerSpec extends SpecBase with MockitoSugar {
         when(mockCustomsFinancialsConnector.revokeAccountAuthorities(any(), ArgumentMatchers.eq(gbEori))(any()))
           .thenReturn(Future.successful(true))
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future(Option(xiEori)))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future(Option(xiEori)))
 
         running(app) {
           val result = route(app, postRequest).value
@@ -303,7 +303,7 @@ class RemoveCheckYourAnswersControllerSpec extends SpecBase with MockitoSugar {
         when(mockCustomsFinancialsConnector.revokeAccountAuthorities(any(), ArgumentMatchers.eq(xiEori))(any()))
           .thenReturn(Future.successful(true))
 
-        when(mockDataStoreConnector.getXiEori(any)).thenReturn(Future(Option(xiEori)))
+        when(mockDataStoreConnector.getXiEori(any)(any)).thenReturn(Future(Option(xiEori)))
 
         running(app) {
           val result = route(app, postRequest).value
diff --git a/test/utils/ConstantsSpec.scala b/test/utils/ConstantsSpec.scala
index 370983b8..c514b6ab 100644
--- a/test/utils/ConstantsSpec.scala
+++ b/test/utils/ConstantsSpec.scala
@@ -105,4 +105,11 @@ class ConstantsSpec extends SpecBase {
     }
   }
 
+  "NON_EU_EORI_PREFIXES" should {
+
+    "contain correct values in" in {
+      NON_EU_EORI_PREFIXES mustBe Set("GB", "XI")
+    }
+  }
+
 }


Reviews:
user: login: magicaljellybeans
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-20T10:39:22Z
user: login: magicaljellybeans
body: One minor comment, otherwise looks fine to me
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-03-20T11:07:17Z
user: login: tyagikumarvineet
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-20T12:41:53Z
user: login: magicaljellybeans
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-20T14:36:36Z
user: login: tyagikumarvineet
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-20T15:43:58Z

Review comments:
diff_hunk: @@ -32,4 +32,6 @@ object Constants {
 
   val ENROLMENT_KEY        = "HMRC-CUS-ORG"
   val ENROLMENT_IDENTIFIER = "EORINumber"
+
+  val NON_EU_EORI_PREFIXES = Set("GB", "GBN", "XI")
path: app/utils/Constants.scala
user: login: magicaljellybeans
body: "GBN" is redundant here because you have "GB"
created_at: 2025-03-20T10:39:22Z
author_association: CONTRIBUTOR
diff_hunk: @@ -427,6 +433,24 @@ class CustomsDataStoreConnectorSpec
         }
       }
     }
+
+    "getXiEori" should {
path: test/connectors/CustomsDataStoreConnectorSpec.scala
user: login: tyagikumarvineet
body: Could you please either move this test case into existing `".get XiEori" must { `(at line no 215) or keep this out from `".getCompanyName" must { ` clause . You could also refactor (if you wish as refactoring is not part of this change) by creating `"getXiEori" must {` clause parallel to `"retrieveCompanyInformationThirdParty" must {` and move all the relevant test cases inside that ?
created_at: 2025-03-20T12:21:24Z
author_association: CONTRIBUTOR
diff_hunk: @@ -427,6 +433,24 @@ class CustomsDataStoreConnectorSpec
         }
       }
     }
+
+    "getXiEori" should {
+      "return None when an invalid prefix is passed" in new Setup {
path: test/connectors/CustomsDataStoreConnectorSpec.scala
user: login: tyagikumarvineet
body: Better to rephrase by saying EU Eori instead of saying invalid prefix.  Also better to add one more test case by saying "when EORI is Non EU Eori" or "when EORI is GB Eori" etc
created_at: 2025-03-20T12:25:23Z
author_association: CONTRIBUTOR

PR comments:
user: login: platops-pr-bot
created_at: 2025-03-19T11:09:17Z
body: - `uk.gov.hmrc.mongo:hmrc-mongo-play-30` can be updated to `2.6.0` in [project/AppDependencies.scala](https://github.com/hmrc/customs-manage-authorities-frontend/blob/MMCA-5229/project/AppDependencies.scala#L1).
- `uk.gov.hmrc.http-verbs-play-30` can be removed - it is already provided by `uk.gov.hmrc.bootstrap-test-play-30`
- There is a bobby warning (builds will be prevented after 30 Jun 2025) - see the pr builder for details
author_association: NONE
user: login: platops-pr-bot
created_at: 2025-03-19T13:38:42Z
body: - `SBT` can be updated to `1.10.10` in [project/build.properties](https://github.com/hmrc/customs-manage-authorities-frontend/blob/MMCA-5229/project/build.properties#L1)
- `uk.gov.hmrc.mongo:hmrc-mongo-play-30` can be updated to `2.6.0` in [project/AppDependencies.scala](https://github.com/hmrc/customs-manage-authorities-frontend/blob/MMCA-5229/project/AppDependencies.scala#L1).
- `uk.gov.hmrc.http-verbs-play-30` can be removed - it is already provided by `uk.gov.hmrc.bootstrap-test-play-30`
- There is a bobby warning (builds will be prevented after 30 Jun 2025) - see the pr builder for details
author_association: NONE