ISSUE #20570: allow incident to be set to new from any points (#20585)

* fix: allow incident to be set to new from any points

* fix: added test back
This commit is contained in:
Teddy 2025-04-03 17:01:17 +02:00 committed by GitHub
parent a6c96611fd
commit 0028ae0cd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 37 deletions

View File

@ -155,32 +155,6 @@ public class TestCaseResolutionStatusRepository
return JsonUtils.readValue(jsonThread, Thread.class); return JsonUtils.readValue(jsonThread, Thread.class);
} }
/**
* Ensure we are following the correct status flow
*/
private void validateStatus(
TestCaseResolutionStatusTypes lastStatus, TestCaseResolutionStatusTypes newStatus) {
switch (lastStatus) {
case New -> {
/* New can go to any status */
}
case Ack -> {
if (newStatus.equals(TestCaseResolutionStatusTypes.New)) {
throw IncidentManagerException.invalidStatus(lastStatus, newStatus);
}
}
case Assigned -> {
if (List.of(TestCaseResolutionStatusTypes.New, TestCaseResolutionStatusTypes.Ack)
.contains(newStatus)) {
throw IncidentManagerException.invalidStatus(lastStatus, newStatus);
}
}
// We only validate status if the last one is unresolved, so we should
// never land here
default -> throw IncidentManagerException.invalidStatus(lastStatus, newStatus);
}
}
@Override @Override
@Transaction @Transaction
public void storeInternal( public void storeInternal(
@ -195,9 +169,6 @@ public class TestCaseResolutionStatusRepository
// if we have an ongoing incident, set the stateId if the new record to be created // if we have an ongoing incident, set the stateId if the new record to be created
// and validate the flow // and validate the flow
if (Boolean.TRUE.equals(unresolvedIncident(lastIncident))) { if (Boolean.TRUE.equals(unresolvedIncident(lastIncident))) {
validateStatus(
lastIncident.getTestCaseResolutionStatusType(),
recordEntity.getTestCaseResolutionStatusType());
// If there is an unresolved incident update the state ID // If there is an unresolved incident update the state ID
recordEntity.setStateId(lastIncident.getStateId()); recordEntity.setStateId(lastIncident.getStateId());
// If the last incident had a severity assigned and the incoming incident does not, inherit // If the last incident had a severity assigned and the incoming incident does not, inherit

View File

@ -1820,7 +1820,7 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
} }
@Test @Test
void unauthorizedTestCaseResolutionFlow(TestInfo test) void authorizedTestCaseResolutionFlow(TestInfo test)
throws HttpResponseException, ParseException { throws HttpResponseException, ParseException {
TestCase testCaseEntity = createEntity(createRequest(getEntityName(test)), ADMIN_AUTH_HEADERS); TestCase testCaseEntity = createEntity(createRequest(getEntityName(test)), ADMIN_AUTH_HEADERS);
// Add failed test case, which will create a NEW incident // Add failed test case, which will create a NEW incident
@ -1840,13 +1840,8 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
.withTestCaseResolutionStatusDetails(new Assigned().withAssignee(USER1_REF)); .withTestCaseResolutionStatusDetails(new Assigned().withAssignee(USER1_REF));
createTestCaseFailureStatus(createAssignedIncident); createTestCaseFailureStatus(createAssignedIncident);
assertResponseContains( createTestCaseFailureStatus(
() -> createAssignedIncident.withTestCaseResolutionStatusType(TestCaseResolutionStatusTypes.Ack));
createTestCaseFailureStatus(
createAssignedIncident.withTestCaseResolutionStatusType(
TestCaseResolutionStatusTypes.Ack)),
BAD_REQUEST,
"Incident with status [Assigned] cannot be moved to [Ack]");
} }
@Test @Test