Skip to content

Commit

Permalink
Merge pull request #494 from hmrc/TGP-2524/Explicit-Audit-Event-Supp-…
Browse files Browse the repository at this point in the history
…Unit-Update-Goods-Record-bug-fix

TGP-2524: Explicit-Audit-Event-Supp-Unit-Update-Goods-Record-bug-fix
  • Loading branch information
besscerule authored Oct 10, 2024
2 parents c57c2ff + a6ae102 commit 2548922
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 38 deletions.
19 changes: 10 additions & 9 deletions app/factories/AuditEventFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,21 @@ case class AuditEventFactory() {
supplementaryRequest: SupplementaryRequest,
recordId: String
)(implicit hc: HeaderCarrier): DataEvent = {
val hasSupUnit = supplementaryRequest.hasSupplementaryUnit.getOrElse(false)
val suppUnitStringOpt = if (hasSupUnit) {
Some(s"${supplementaryRequest.supplementaryUnit.get} ${supplementaryRequest.measurementUnit.get}")
} else {
None
}
val auditDetails = Map(
val auditDetails = Map(
"journey" -> journey.toString,
"updateSection" -> SupplementaryUnitUpdate.toString,
"recordId" -> recordId,
"eori" -> supplementaryRequest.eori,
"affinityGroup" -> affinityGroup.toString,
"addSupplementaryUnit" -> hasSupUnit.toString
) ++ writeOptional("supplementaryUnit", suppUnitStringOpt)
"addSupplementaryUnit" -> supplementaryRequest.hasSupplementaryUnit.getOrElse(false).toString
) ++ writeOptional(
"supplementaryUnit",
if (supplementaryRequest.supplementaryUnit.isDefined) {
Some(s"${supplementaryRequest.supplementaryUnit.get} ${supplementaryRequest.measurementUnit.get}")
} else {
None
}
)
createSubmitGoodsRecordEvent(auditDetails)
}

Expand Down
113 changes: 84 additions & 29 deletions test/factories/AuditEventFactorySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class AuditEventFactorySpec extends SpecBase {
auditDetails("descendants") mustBe "1"
auditDetails("categoryAssessments") mustBe "2"
}

}

"create submit goods record event" - {
Expand Down Expand Up @@ -230,7 +229,6 @@ class AuditEventFactorySpec extends SpecBase {
auditDetails("commodityCodeEffectiveTo") mustBe "null"

}

}

"create event when journey is updating a goods record" - {
Expand Down Expand Up @@ -427,7 +425,6 @@ class AuditEventFactorySpec extends SpecBase {
auditDetails("providedSupplementaryUnit") mustBe "true"
auditDetails("supplementaryUnit") mustBe "99"
}

}

"and update is for goods details" in {
Expand Down Expand Up @@ -480,34 +477,93 @@ class AuditEventFactorySpec extends SpecBase {

}

"and update is for supplementary unit" in {
"and update is for supplementary unit" - {

val result = AuditEventFactory().createSubmitGoodsRecordEventForUpdateSupplementaryUnit(
AffinityGroup.Organisation,
UpdateRecordJourney,
SupplementaryRequest(
testEori,
testRecordId,
Some(true),
Some("supplementaryUnit"),
Some("measurementUnit")
),
testRecordId
)
"when hasSupp is present" in {
val result = AuditEventFactory().createSubmitGoodsRecordEventForUpdateSupplementaryUnit(
AffinityGroup.Organisation,
UpdateRecordJourney,
SupplementaryRequest(
testEori,
testRecordId,
Some(true),
Some("supplementaryUnit"),
Some("measurementUnit")
),
testRecordId
)

result.auditSource mustBe "trader-goods-profiles-frontend"
result.auditType mustBe "SubmitGoodsRecord"
result.tags.isEmpty mustBe false
result.auditSource mustBe "trader-goods-profiles-frontend"
result.auditType mustBe "SubmitGoodsRecord"
result.tags.isEmpty mustBe false

val auditDetails = result.detail
auditDetails.size mustBe 7
auditDetails("journey") mustBe "UpdateRecord"
auditDetails("updateSection") mustBe "supplementaryUnit"
auditDetails("eori") mustBe testEori
auditDetails("recordId") mustBe testRecordId
auditDetails("affinityGroup") mustBe "Organisation"
auditDetails("addSupplementaryUnit") mustBe "true"
auditDetails("supplementaryUnit") mustBe "supplementaryUnit measurementUnit"
val auditDetails = result.detail
auditDetails.size mustBe 7
auditDetails("journey") mustBe "UpdateRecord"
auditDetails("updateSection") mustBe "supplementaryUnit"
auditDetails("eori") mustBe testEori
auditDetails("recordId") mustBe testRecordId
auditDetails("affinityGroup") mustBe "Organisation"
auditDetails("addSupplementaryUnit") mustBe "true"
auditDetails("supplementaryUnit") mustBe "supplementaryUnit measurementUnit"
}

"when hasSupp is not present" in {
val result = AuditEventFactory().createSubmitGoodsRecordEventForUpdateSupplementaryUnit(
AffinityGroup.Organisation,
UpdateRecordJourney,
SupplementaryRequest(
testEori,
testRecordId,
None,
Some("supplementaryUnit"),
Some("measurementUnit")
),
testRecordId
)

result.auditSource mustBe "trader-goods-profiles-frontend"
result.auditType mustBe "SubmitGoodsRecord"
result.tags.isEmpty mustBe false

val auditDetails = result.detail
auditDetails.size mustBe 7
auditDetails("journey") mustBe "UpdateRecord"
auditDetails("updateSection") mustBe "supplementaryUnit"
auditDetails("eori") mustBe testEori
auditDetails("recordId") mustBe testRecordId
auditDetails("affinityGroup") mustBe "Organisation"
auditDetails("addSupplementaryUnit") mustBe "false"
auditDetails("supplementaryUnit") mustBe "supplementaryUnit measurementUnit"
}

"when suppUnit is not present" in {
val result = AuditEventFactory().createSubmitGoodsRecordEventForUpdateSupplementaryUnit(
AffinityGroup.Organisation,
UpdateRecordJourney,
SupplementaryRequest(
testEori,
testRecordId,
Some(false),
None,
Some("measurementUnit")
),
testRecordId
)

result.auditSource mustBe "trader-goods-profiles-frontend"
result.auditType mustBe "SubmitGoodsRecord"
result.tags.isEmpty mustBe false

val auditDetails = result.detail
auditDetails.size mustBe 6
auditDetails("journey") mustBe "UpdateRecord"
auditDetails("updateSection") mustBe "supplementaryUnit"
auditDetails("eori") mustBe testEori
auditDetails("recordId") mustBe testRecordId
auditDetails("affinityGroup") mustBe "Organisation"
auditDetails("addSupplementaryUnit") mustBe "false"
}
}
}
}
Expand Down Expand Up @@ -882,5 +938,4 @@ class AuditEventFactorySpec extends SpecBase {
}
}
}

}

0 comments on commit 2548922

Please sign in to comment.