Skip to content

Commit

Permalink
[DMS-419] DateTime search should be exact (#358)
Browse files Browse the repository at this point in the history
* DateTime search should be exact

* Make consistent date time formats
  • Loading branch information
simpat-adam authored Dec 2, 2024
1 parent 310e1f0 commit 3d59b1a
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/dms/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@
},
"cSpell.words": [
"Retryable",
"sszzz"
"ssZ"
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ public async Task It_should_update_the_lastmodifieddate_in_the_document_body()
);

(getResult! as GetResult.GetSuccess)!.LastModifiedDate.Should().NotBe(_courseOfferingInsertDateTime);
_courseOfferingLastModifiedDate.Should().Be(DateTime.ParseExact("2024-10-29T14:54:49+00:00", "yyyy-MM-ddTHH:mm:sszzz", DateTimeFormatInfo.InvariantInfo));
_courseOfferingLastModifiedDate.Should().Be(DateTime.ParseExact("2024-10-29T14:54:49Z", "yyyy-MM-ddTHH:mm:ssZ", DateTimeFormatInfo.InvariantInfo));
(getResult! as GetResult.GetSuccess)!.EdfiDoc["_lastModifiedDate"]!.GetValue<DateTime>().Should().NotBe(_courseOfferingLastModifiedDate);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal static IPipelineStep Middleware()
public class Given_Valid_Request_Body : InjectLastModifiedDateToEdFiDocumentMiddlewareTests
{
private readonly PipelineContext _context = No.PipelineContext();
private readonly string _pattern = @"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$";
private readonly string _pattern = @"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$";
private readonly string _propertyName = "_lastModifiedDate";

[SetUp]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ out DateOnly dateValue
jsonNode.ReplaceWith(
dateValue
.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc)
.ToString("yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture)
.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ var originalIdentityJsonPath in originalIdentityJsonPaths

// finally update _lastModifiedDate
DateTimeOffset utcNow = DateTimeOffset.UtcNow;
string formattedUtcDateTime = utcNow.ToString("yyyy-MM-ddTHH:mm:sszzz");
string formattedUtcDateTime = utcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
returnEdFiDoc["_lastModifiedDate"] = formattedUtcDateTime;

return new UpdateCascadeResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task Execute(PipelineContext context, Func<Task> next)
);

DateTimeOffset utcNow = DateTimeOffset.UtcNow;
string formattedUtcDateTime = utcNow.ToString("yyyy-MM-ddTHH:mm:sszzz");
string formattedUtcDateTime = utcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
context.ParsedBody["_lastModifiedDate"] = formattedUtcDateTime;
await next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using System.Globalization;
using System.Text.Json.Nodes;
using EdFi.DataManagementService.Core.ApiSchema.Model;
using EdFi.DataManagementService.Core.External.Model;
Expand Down Expand Up @@ -106,6 +107,24 @@ QueryField[] possibleQueryFields
return null;
}

if (matchingQueryField.DocumentPathsWithType[0].Type == "date-time" && DateOnly.TryParse(
clientQueryTerm.Value,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
out DateOnly dateValue
))
{
string fullDateTimeString = dateValue
.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc)
.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture);

return new QueryElementAndType(
QueryFieldName: clientQueryTerm.Key,
DocumentPathsAndTypes: matchingQueryField.DocumentPathsWithType,
Value: fullDateTimeString
);
}

return new QueryElementAndType(
QueryFieldName: clientQueryTerm.Key,
DocumentPathsAndTypes: matchingQueryField.DocumentPathsWithType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,6 @@ Feature: Data strictness
"studentUniqueId": "604906"
},
"studentAssessmentIdentifier": "/Qhqqe/gI4p3RguP68ZEDArGHM64FKnCg/RLHG8c",
"administrationDate": "2021-09-28T00:00:00+00:00"
"administrationDate": "2021-09-28T00:00:00Z"
}
"""
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ Feature: Query String handling for GET requests for Resource Queries
And the system has these "academicweeks"
| weekIdentifier | beginDate | endDate | totalInstructionalDays | schoolReference |
| Week One | 2024-05-15 | 2024-05-22 | 2 | {"schoolId": 2} |
And the system has these "students"
| studentUniqueId | firstName | lastSurname | birthDate |
| unique | Jane | Doe | 2012-01-20 |
And the system has these "assessments"
| assessmentIdentifier | namespace | assessmentCategoryDescriptor | assessmentTitle | assessmentVersion | maxRawScore | revisionDate | academicSubjects |
| 01774fa3-06f1-47fe-8801-c8b1e65057f2 | Assessment.xml | uri://ed-fi.org/AssessmentCategoryDescriptor#Benchmark test | 3rd Grade Reading | 2021 | 10 | 2021-09-19 | [{"academicSubjectDescriptor": "uri://ed-fi.org/AcademicSubjectDescriptor#English Language Arts"}] |
And the system has these "studentAssessments"
| studentReference | assessmentReference | administrationDate | studentAssessmentIdentifier |
| { "studentUniqueId": "unique" } | {"assessmentIdentifier": "01774fa3-06f1-47fe-8801-c8b1e65057f2", "namespace": "Assessment.xml" } | "2021-09-28T00:10:00Z" | studentAssessmentIdentifier |

@API-124
Scenario: 01 Ensure clients can GET information when querying by valid date
Expand Down Expand Up @@ -226,3 +235,65 @@ Feature: Query String handling for GET requests for Resource Queries
"totalInstructionalDays": 2
}]
"""

Scenario: 13 Ensure clients get empty array when querying datetime with no time component and no midnight match
When a GET request is made to "/ed-fi/studentAssessments?administrationDate=2021-09-28"
Then it should respond with 200
And the response body is
"""
[]
"""

Scenario: 14 Ensure clients get correct results when querying datetime with time component
When a GET request is made to "/ed-fi/studentAssessments?administrationDate=2021-09-28T00:10:00Z"
Then it should respond with 200
And the response body is
"""
[
{
"studentAssessmentIdentifier": "studentAssessmentIdentifier",
"assessmentReference": {
"namespace": "Assessment.xml",
"assessmentIdentifier": "01774fa3-06f1-47fe-8801-c8b1e65057f2"
},
"administrationDate": "2021-09-28T00:10:00Z",
"id": "{id}",
"studentReference": {
"studentUniqueId": "unique"
}
}
]
"""

@addwait
Scenario: 15 Ensure clients get midnight results when querying without a time component
Given a POST request is made to "/ed-fi/studentAssessments" with
"""
{
"studentReference": { "studentUniqueId": "unique" },
"assessmentReference": {
"assessmentIdentifier": "01774fa3-06f1-47fe-8801-c8b1e65057f2",
"namespace": "Assessment.xml"
},
"administrationDate": "2021-09-28T00:00:00Z",
"studentAssessmentIdentifier": "studentAssessmentIdentifier"
}
"""
When a GET request is made to "/ed-fi/studentAssessments?administrationDate=2021-09-28"
Then it should respond with 200
And the response body is
"""
[
{
"studentAssessmentIdentifier": "studentAssessmentIdentifier",
"assessmentReference": {
"namespace": "Assessment.xml",
"assessmentIdentifier": "01774fa3-06f1-47fe-8801-c8b1e65057f2"
},
"administrationDate": "2021-09-28T00:00:00Z",
"id": "{id}",
"studentReference": {
"studentUniqueId": "unique"
}
}]
"""

0 comments on commit 3d59b1a

Please sign in to comment.