Skip to content

Commit

Permalink
Merge pull request #488 from hmrc/TGP-2641/update-profile-unchanged-a…
Browse files Browse the repository at this point in the history
…nswer-bugs

TGP 2641 update profile unchanged answer bugs
  • Loading branch information
Ewan-James-Donovan authored Oct 4, 2024
2 parents 94a2c08 + ed20a0d commit f92a873
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/models/TraderProfile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import cats.data.{EitherNec, NonEmptyChain}
import cats.implicits._
import pages._
import play.api.libs.json.{Json, OFormat}
import queries.TraderProfileQuery

final case class TraderProfile(
actorId: String,
Expand Down Expand Up @@ -61,7 +62,14 @@ object TraderProfile {
answers.getPageValue(removePage) match {
case Right(true) => Right(None)
case Right(false) => answers.unexpectedValueDefined(answers, removePage)
case Left(errors) => Left(errors)
case Left(errors) =>
removePage match {
case RemoveNirmsPage if answers.getPageValue(TraderProfileQuery).exists(_.nirmsNumber.isEmpty) =>
Right(None)
case RemoveNiphlPage if answers.getPageValue(TraderProfileQuery).exists(_.niphlNumber.isEmpty) =>
Right(None)
case _ => Left(errors)
}
}
}
case Left(errors) => Left(errors)
Expand Down
35 changes: 35 additions & 0 deletions test/models/TraderProfileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ import org.scalatest.{OptionValues, TryValues}
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.must.Matchers
import pages._
import queries.TraderProfileQuery

class TraderProfileSpec extends AnyFreeSpec with Matchers with TryValues with OptionValues {

val traderProfile = TraderProfile("actorId", "ukims", Some("nirmsNumber"), Some("niphlNumber"))

".build" - {

"must return a TraderProfile when all mandatory questions are answered" - {
Expand Down Expand Up @@ -184,6 +187,22 @@ class TraderProfileSpec extends AnyFreeSpec with Matchers with TryValues with Op

result mustEqual Right(None)
}

"except RemoveNirms and TraderProfileQuery has no nirms number" in {

val answers =
UserAnswers(userAnswersId)
.set(HasNirmsUpdatePage, false)
.success
.value
.set(TraderProfileQuery, traderProfile.copy(nirmsNumber = None))
.success
.value

val result = TraderProfile.validateHasNirms(answers)

result mustEqual Right(None)
}
}

"must return errors" - {
Expand Down Expand Up @@ -354,6 +373,22 @@ class TraderProfileSpec extends AnyFreeSpec with Matchers with TryValues with Op

result mustEqual Right(None)
}

"except RemoveNiphl and TraderProfileQuery has no niphl number" in {

val answers =
UserAnswers(userAnswersId)
.set(HasNiphlUpdatePage, false)
.success
.value
.set(TraderProfileQuery, traderProfile.copy(niphlNumber = None))
.success
.value

val result = TraderProfile.validateHasNiphl(answers)

result mustEqual Right(None)
}
}

"must return errors" - {
Expand Down

0 comments on commit f92a873

Please sign in to comment.