Skip to content

Commit

Permalink
Merge pull request #87 from nightingaleproject/fix-datetime-offset-bug
Browse files Browse the repository at this point in the history
Fixes a bug caused by Newtonsoft JSON parser altering datetimes
  • Loading branch information
smacadam authored Jan 26, 2024
2 parents a851254 + 81cc895 commit f59b7c7
Show file tree
Hide file tree
Showing 4 changed files with 2,041 additions and 3 deletions.
21 changes: 20 additions & 1 deletion messaging.tests/Integration/BundlesControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ protected async Task<int> GetTableCount<T>(IQueryable<T> table, int expectedCoun
return count;
}


[Fact]
public async System.Threading.Tasks.Task ParseBatchIncomingMessages()
{
Expand Down Expand Up @@ -474,6 +473,26 @@ public async void PostWithInvalidJurisdictionGetsError()
Assert.Equal(HttpStatusCode.BadRequest, createSubmissionMessage.StatusCode);
}

[Fact]
public async void PostPreservesLocalTime()
{
// Clear any messages in the database for a clean test
DatabaseHelper.ResetDatabase(_context);

// Use a record with all datetimes set to using an offset that aligns with PST
string pstMsg = FixtureStream("fixtures/json/DeathRecordSubmissionMessagePST.json").ReadToEnd();

// Submit that Death Record
HttpResponseMessage createSubmissionMessage = await JsonResponseHelpers.PostJsonAsync(_client, $"/CA/Bundle", pstMsg);
Assert.Equal(HttpStatusCode.NoContent, createSubmissionMessage.StatusCode);

// Make sure the record as stored has not had the local times converted from PST
// Note: running this test on a system actually in PST could create a false positive!
Assert.Equal(1, await GetTableCount(_context.IncomingMessageItems, 1));
var messageItem = _context.IncomingMessageItems.First();
Assert.Contains("\"timestamp\":\"2021-01-20T00:00:00-08:00\"", messageItem.Message);
}

[Fact]
public async void PostCatchMissingSourceEndpoint()
{
Expand Down
Loading

0 comments on commit f59b7c7

Please sign in to comment.