Skip to content

Commit

Permalink
Clear staff & prisoner involvements and reset to draft when changing …
Browse files Browse the repository at this point in the history
…type
  • Loading branch information
ushkarev committed Oct 25, 2024
1 parent 9c7bc19 commit 93b9b39
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,22 @@ class Report(
fun popLastQuestion(): Question? = questions.removeLastOrNull()

fun changeType(newType: Type, changedAt: LocalDateTime, changedBy: String): Report {
copyToHistory(changedAt, changedBy)
questions.clear()
type = newType
if (type != newType) {
copyToHistory(changedAt, changedBy)
questions.clear()
type = newType
changeStatus(Status.DRAFT, changedAt, changedBy)
prisonersInvolved.clear()
staffInvolved.clear()
}
return this
}

fun changeStatus(newStatus: Status, changedAt: LocalDateTime, changedBy: String): Report {
status = newStatus
addStatusHistory(newStatus, changedAt, changedBy)
if (status != newStatus) {
status = newStatus
addStatusHistory(newStatus, changedAt, changedBy)
}
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class ReportRepositoryTest : IntegrationTestBase() {
),
)
report.addStatusHistory(Status.DRAFT, now, "user5")
report.addStatusHistory(Status.AWAITING_ANALYSIS, now, "user1")
report.addStaffInvolved(StaffRole.FIRST_ON_SCENE, "user1")
report.addPrisonerInvolved("A1234AA", PrisonerRole.VICTIM)

Expand Down Expand Up @@ -301,7 +302,7 @@ class ReportRepositoryTest : IntegrationTestBase() {

report = reportRepository.findOneEagerlyByReportReference(report.reportReference)
?: throw EntityNotFoundException()
assertThat(report.status).isEqualTo(Status.AWAITING_ANALYSIS)
assertThat(report.status).isEqualTo(Status.DRAFT)
assertThat(report.type).isEqualTo(Type.ASSAULT)
assertThat(report.getQuestions()).hasSize(1)
assertThat(report.getQuestions()[0].code).isEqualTo("SOME_QUESTION")
Expand All @@ -310,7 +311,9 @@ class ReportRepositoryTest : IntegrationTestBase() {
assertThat(report.history[2].questions).hasSize(3)
assertThat(report.history[2].questions[1].getResponses()).hasSize(2)
assertThat(report.history[2].questions[1].getResponses()[1].response).isEqualTo("OTHER")
assertThat(report.historyOfStatuses).hasSize(1)
assertThat(report.historyOfStatuses).hasSize(3)
assertThat(report.historyOfStatuses[0].status).isEqualTo(Status.DRAFT)
assertThat(report.historyOfStatuses[1].status).isEqualTo(Status.AWAITING_ANALYSIS)
assertThat(report.historyOfStatuses[2].status).isEqualTo(Status.DRAFT)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,8 @@ class ReportResourceTest : SqsIntegrationTestBase() {
status = Status.AWAITING_ANALYSIS,
generateQuestions = 2,
generateResponses = 2,
generateStaffInvolvement = 1,
generatePrisonerInvolvement = 1,
generateHistory = 0,
),
)
Expand All @@ -1720,8 +1722,8 @@ class ReportResourceTest : SqsIntegrationTestBase() {
"description": "A new incident created in the new service of type Finds",
"reportedBy": "USER1",
"reportedAt": "2023-12-05T12:31:56",
"status": "AWAITING_ANALYSIS",
"nomisStatus": "AWAN",
"status": "DRAFT",
"nomisStatus": null,
"assignedTo": "USER1",
"createdAt": "2023-12-05T12:31:56",
"modifiedAt": "2023-12-05T12:34:56",
Expand Down Expand Up @@ -1779,7 +1781,23 @@ class ReportResourceTest : SqsIntegrationTestBase() {
]
}
],
"questions": []
"questions": [],
"historyOfStatuses": [
{
"status": "AWAITING_ANALYSIS",
"nomisStatus": "AWAN",
"changedAt": "2023-12-05T12:31:56",
"changedBy": "USER1"
},
{
"status": "DRAFT",
"nomisStatus": null,
"changedAt": "2023-12-05T12:34:56",
"changedBy": "request-user"
}
],
"staffInvolved": [],
"prisonersInvolved": []
}
""",
false,
Expand All @@ -1802,6 +1820,8 @@ class ReportResourceTest : SqsIntegrationTestBase() {
status = Status.AWAITING_ANALYSIS,
generateQuestions = 1,
generateResponses = 1,
generateStaffInvolvement = 1,
generatePrisonerInvolvement = 1,
generateHistory = 1,
),
)
Expand All @@ -1825,8 +1845,8 @@ class ReportResourceTest : SqsIntegrationTestBase() {
"description": "A new incident created in the new service of type Finds",
"reportedBy": "USER1",
"reportedAt": "2023-12-05T12:31:56",
"status": "AWAITING_ANALYSIS",
"nomisStatus": "AWAN",
"status": "DRAFT",
"nomisStatus": null,
"assignedTo": "USER1",
"createdAt": "2023-12-05T12:31:56",
"modifiedAt": "2023-12-05T12:34:56",
Expand Down Expand Up @@ -1878,7 +1898,23 @@ class ReportResourceTest : SqsIntegrationTestBase() {
]
}
],
"questions": []
"questions": [],
"historyOfStatuses": [
{
"status": "AWAITING_ANALYSIS",
"nomisStatus": "AWAN",
"changedAt": "2023-12-05T12:31:56",
"changedBy": "USER1"
},
{
"status": "DRAFT",
"nomisStatus": null,
"changedAt": "2023-12-05T12:34:56",
"changedBy": "request-user"
}
],
"staffInvolved": [],
"prisonersInvolved": []
}
""",
false,
Expand Down

0 comments on commit 93b9b39

Please sign in to comment.