Skip to content

Commit

Permalink
Added idempotent handling of the Resolve incident
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Feb 6, 2024
1 parent b9baa60 commit efef1df
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ public async Task ResolveCommand_Succeeds()

await Host.IncidentDetailsShouldBe(Incident with { Status = IncidentStatus.Resolved, Version = 2 });
}
[Fact]
[Trait("Category", "Acceptance")]
public async Task ResolvingTwiceTheSame_Incident_Succeeds()
{
var version = Incident.Version;
Action<Scenario> resolve = x =>
{
x.Post.Json(new ResolveIncident(Incident.Id, agentId, resolutionType, version))
.ToUrl($"/api/agents/{agentId}/incidents/{Incident.Id}/resolve");
x.StatusCodeShouldBeOk();
};
await Host.Scenario(resolve);
version++;

await Host.Scenario(resolve);
await Host.IncidentDetailsShouldBe(Incident with { Status = IncidentStatus.Resolved, Version = 2 });
}

private readonly Guid agentId = Guid.NewGuid();
private readonly ResolutionType resolutionType = new Faker().PickRandom<ResolutionType>();
Expand Down
1 change: 1 addition & 0 deletions Sample/Helpdesk.Wolverine/Helpdesk.Api/Helpdesk.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Incidents\ResolvingBatch\" />
<Folder Include="Internal\Generated\"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ public static class ResolveEndpoint
DateTimeOffset now
)
{
if (incident.Status is IncidentStatus.Resolved or IncidentStatus.Closed)
throw new InvalidOperationException("Cannot resolve already resolved or closed incident");
switch (incident.Status)
{
case IncidentStatus.Resolved or IncidentStatus.ResolutionAcknowledgedByCustomer:
return (Ok(), []);
case IncidentStatus.Closed:
throw new InvalidOperationException("Cannot resolve already resolved or closed incident");
}

if (incident.HasOutstandingResponseToCustomer)
throw new InvalidOperationException("Cannot resolve incident that has outstanding responses to customer");
Expand Down

0 comments on commit efef1df

Please sign in to comment.