generated from ministryofjustice/hmpps-template-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): add reusable auditEvent object to create an audit event
- Loading branch information
Showing
5 changed files
with
63 additions
and
36 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/uk/gov/justice/digital/hmpps/learnerrecordsapi/config/AuditEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package uk.gov.justice.digital.hmpps.learnerrecordsapi.config | ||
|
||
import uk.gov.justice.hmpps.sqs.audit.HmppsAuditEvent | ||
import java.time.Instant | ||
import java.util.UUID | ||
|
||
object AuditEvent { | ||
|
||
val learnerRecordsApi = "learner-records-api" | ||
val subjectTypeRead = "Read" | ||
val readRequestReceived = "Read Request Received" | ||
|
||
fun createAuditEvent(userName: String, requestParams: String): HmppsAuditEvent { | ||
val hmppsLRSEvent = HmppsAuditEvent( | ||
readRequestReceived, | ||
"From $userName", | ||
subjectTypeRead, | ||
UUID.randomUUID().toString(), | ||
Instant.now(), | ||
userName, | ||
learnerRecordsApi, | ||
requestParams, | ||
) | ||
return hmppsLRSEvent | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/test/kotlin/uk/gov/justice/digital/hmpps/learnerrecordsapi/config/AuditEventTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package uk.gov.justice.digital.hmpps.learnerrecordsapi.config | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.Gender | ||
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnersRequest | ||
import java.time.Instant | ||
import java.time.LocalDate | ||
|
||
class AuditEventTest { | ||
|
||
@Test | ||
fun `should create Audit Event when correct set of parameters are passed`() { | ||
val request = LearnersRequest( | ||
givenName = "Firstname", | ||
familyName = "Lastname", | ||
dateOfBirth = LocalDate.of(1990, 1, 1), | ||
gender = Gender.valueOf("MALE"), | ||
lastKnownPostCode = "NE2 2AS", | ||
emailAddress = "test@example.com", | ||
) | ||
val hmppsAuditEvent = AuditEvent.createAuditEvent("User", request.toString()) | ||
assertEquals("learner-records-api", hmppsAuditEvent.service) | ||
assertEquals("Read", hmppsAuditEvent.subjectType) | ||
assertEquals("Read Request Received", hmppsAuditEvent.what) | ||
assertEquals("User", hmppsAuditEvent.who) | ||
assertThat(hmppsAuditEvent.`when`).isBeforeOrEqualTo(Instant.now()) | ||
assertTrue(hmppsAuditEvent.details.toString().contains("NE2 2AS")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters