Skip to content

Commit

Permalink
Merge pull request #41 from hmrc/SASS-3442
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Raffe authored Jun 6, 2023
2 parents e8c56b9 + c79c31e commit 3576049
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/controllers/ClaimDataController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ClaimDataController @Inject()(authorisedAction: AuthorisedAction,

private def handleSaveUserData(nino: String, sessionDataId: Option[UUID], userData: StateBenefitsUserData)
(implicit hc: HeaderCarrier): Future[Result] = {
if (userData.nino != nino || !userData.sessionDataId.exists(sId => sId == sessionDataId.getOrElse(sId))) {
if (userData.nino != nino || !userData.sessionDataId.equals(sessionDataId)) {
logger.warn(invalidRequestLogMessage)
Future.successful(BadRequest)
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/services/IntegrationFrameworkService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class IntegrationFrameworkService @Inject()(connector: IntegrationFrameworkConne

private def createOrUpdateStateBenefit(userData: StateBenefitsUserData)
(implicit hc: HeaderCarrier): EitherT[Future, ApiServiceError, UUID] = userData match {
case _ if userData.isHmrcData => createCustomerOverride(userData)
case _ if userData.isNewClaim => addCustomerStateBenefit(userData)
case _ if userData.isHmrcData => createCustomerOverride(userData)
case _ => updateCustomerStateBenefit(userData)
}

Expand Down
28 changes: 15 additions & 13 deletions test/controllers/ClaimDataControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,46 +44,48 @@ class ClaimDataControllerSpec extends ControllerUnitTest

".save" should {
for (saveType <- Seq("save by sessionId", "save by userData")) {


val userData = if (saveType.contains("save by sessionId")) aStateBenefitsUserData else aStateBenefitsUserData.copy(sessionDataId = None)

s"$saveType" should {

"return BadRequest" when {
s"when data received is in invalid format" in {
mockAuthorisation()

val request = fakePutRequest.withJsonBody(Json.parse("""{"wrongFormat": "wrong-value"}"""))
val result =
if (saveType.contains("save by sessionId")) underTest.save(nino, sessionDataId)(request) else underTest.saveByData(nino)(request)

status(result) shouldBe BAD_REQUEST
}

s"when nino is different" in {
mockAuthorisation()
val request = fakePostRequest.withJsonBody(Json.toJson(aStateBenefitsUserData))

val request = fakePostRequest.withJsonBody(Json.toJson(userData))
val result =
if (saveType.contains("save by sessionId")) underTest.save("some-nino", sessionDataId)(request) else underTest.saveByData("some-nino")(request)

status(result) shouldBe BAD_REQUEST
}

if (saveType.contains("save by sessionId")) {
"when sessionDataId is different" in {
mockAuthorisation()
val result = underTest.save(nino, UUID.randomUUID())(fakePostRequest.withJsonBody(Json.toJson(aStateBenefitsUserData)))

val result = underTest.save(nino, UUID.randomUUID())(fakePostRequest.withJsonBody(Json.toJson(userData)))

status(result) shouldBe BAD_REQUEST
}
}
}

s"should return INTERNAL_SERVER_ERROR when saveUserData returns an error" in {
mockAuthorisation()
mockSaveUserData(aStateBenefitsUserData, Left(DataNotUpdatedError))
mockSaveUserData(userData, Left(DataNotUpdatedError))

val request = fakePutRequest.withJsonBody(Json.toJson(aStateBenefitsUserData))
val request = fakePutRequest.withJsonBody(Json.toJson(userData))
val result =
if (saveType.contains("save by sessionId")) underTest.save(nino, sessionDataId)(request) else underTest.saveByData(nino)(request)

Expand All @@ -92,9 +94,9 @@ class ClaimDataControllerSpec extends ControllerUnitTest

s"should return NoContent when stateBenefitsService returns Right(None)" in {
mockAuthorisation()
mockSaveUserData(aStateBenefitsUserData, Right(()))
mockSaveUserData(userData, Right(()))

val request = fakePutRequest.withJsonBody(Json.toJson(aStateBenefitsUserData))
val request = fakePutRequest.withJsonBody(Json.toJson(userData))
val result =
if (saveType.contains("save by sessionId")) underTest.save(nino, sessionDataId)(request) else underTest.saveByData(nino)(request)

Expand Down

0 comments on commit 3576049

Please sign in to comment.