Skip to content

Commit

Permalink
fix: Published status was overwritten by Fetch status using get detai…
Browse files Browse the repository at this point in the history
…ls and overview (#239)

* Add status to first DB and then return updated correspondence

* set latestStatus as new Correspondence entity instead of directly changing members

* use DateTime instead of DateTimeOffset

* show status history in order of occurance

* add assert for statushistory in GetCorrespondenceDetails
  • Loading branch information
CelineTrammi authored Aug 30, 2024
1 parent 93f9a80 commit 941f5f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ public async Task GetCorrespondenceDetails_AsReceiver_UpdatesStatusToFetched()
var getCorrespondenceDetailsResponse = await _client.GetAsync($"correspondence/api/v1/correspondence/{correspondence?.CorrespondenceIds.FirstOrDefault()}/details");
Assert.True(getCorrespondenceDetailsResponse.IsSuccessStatusCode, await getCorrespondenceDetailsResponse.Content.ReadAsStringAsync());
var response = await getCorrespondenceDetailsResponse.Content.ReadFromJsonAsync<CorrespondenceDetailsExt>(_responseSerializerOptions);
Assert.Contains(response.StatusHistory, item => item.Status == CorrespondenceStatusExt.Published);
Assert.Contains(response.StatusHistory, item => item.Status == CorrespondenceStatusExt.Fetched);
Assert.Equal(response.Status, CorrespondenceStatusExt.Fetched);
}

Expand All @@ -348,6 +350,8 @@ public async Task GetCorrespondenceDetails_AsSender_KeepsStatusAsPublished()
var getCorrespondenceDetailsResponse = await _client.GetAsync($"correspondence/api/v1/correspondence/{correspondence?.CorrespondenceIds.FirstOrDefault()}/details");
Assert.True(getCorrespondenceDetailsResponse.IsSuccessStatusCode, await getCorrespondenceDetailsResponse.Content.ReadAsStringAsync());
var response = await getCorrespondenceDetailsResponse.Content.ReadFromJsonAsync<CorrespondenceDetailsExt>(_responseSerializerOptions);
Assert.Contains(response.StatusHistory, item => item.Status == CorrespondenceStatusExt.Published);
Assert.DoesNotContain(response.StatusHistory, item => item.Status == CorrespondenceStatusExt.Fetched);
Assert.Equal(response.Status, CorrespondenceStatusExt.Published);
}
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<OneOf<GetCorrespondenceDetailsResponse, Error>> Process(Guid c
{
return Errors.NoAccessToResource;
}
var latestStatus = correspondence.Statuses.OrderByDescending(s => s.StatusChanged).FirstOrDefault();
var latestStatus = correspondence.Statuses?.OrderByDescending(s => s.StatusChanged).FirstOrDefault();
if (latestStatus == null)
{
return Errors.CorrespondenceNotFound;
Expand All @@ -44,10 +44,13 @@ public async Task<OneOf<GetCorrespondenceDetailsResponse, Error>> Process(Guid c

if (isRecipient && latestStatus.Status == CorrespondenceStatus.Published)
{
latestStatus.Status = CorrespondenceStatus.Fetched;
latestStatus.StatusText = CorrespondenceStatus.Fetched.ToString();
latestStatus.StatusChanged = DateTimeOffset.UtcNow;

latestStatus = new CorrespondenceStatusEntity{
CorrespondenceId = correspondence.Id,
Status = CorrespondenceStatus.Fetched,
StatusText = CorrespondenceStatus.Fetched.ToString(),
StatusChanged = DateTime.Now
};

await _correspondenceStatusRepository.AddCorrespondenceStatus(new CorrespondenceStatusEntity
{
CorrespondenceId = correspondence.Id,
Expand All @@ -71,7 +74,7 @@ await _correspondenceStatusRepository.AddCorrespondenceStatus(new Correspondence
Notifications = correspondence.Notifications == null ? new List<CorrespondenceNotificationEntity>() : correspondence.Notifications,
VisibleFrom = correspondence.VisibleFrom,
IsReservable = correspondence.IsReservable == null || correspondence.IsReservable.Value,
StatusHistory = correspondence.Statuses,
StatusHistory = correspondence.Statuses?.OrderBy(s => s.StatusChanged).ToList() ?? [],
ResourceId = correspondence.ResourceId
};
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ public async Task<OneOf<GetCorrespondenceOverviewResponse, Error>> Process(Guid

if (isRecipient && latestStatus.Status == CorrespondenceStatus.Published)
{
latestStatus.Status = CorrespondenceStatus.Fetched;
latestStatus.StatusText = CorrespondenceStatus.Fetched.ToString();
latestStatus.StatusChanged = DateTimeOffset.UtcNow;
latestStatus = new CorrespondenceStatusEntity{
CorrespondenceId = correspondence.Id,
Status = CorrespondenceStatus.Fetched,
StatusText = CorrespondenceStatus.Fetched.ToString(),
StatusChanged = DateTime.Now
};

await _correspondenceStatusRepository.AddCorrespondenceStatus(new CorrespondenceStatusEntity
{
Expand Down

0 comments on commit 941f5f6

Please sign in to comment.