Skip to content

Commit

Permalink
Enhanced and align tests for final cursor paging behavior changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmcelhanon committed Oct 29, 2024
1 parent d032204 commit 8b30f9c
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async Task<SpecificationResult> GetPagedAggregateIdsAsync()
{
if (countTemplateParameters.ParameterNames.Contains("MinAggregateId"))
{
throw new BadRequestParameterException(BadRequestException.DefaultDetail, ["Total count cannot be determined while using key set paging."]);
throw new BadRequestParameterException(BadRequestException.DefaultDetail, ["Total count cannot be determined while using cursor paging (when pageToken is specified)."]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public static bool IsValid(IQueryParameters queryParameters, int defaultPageLimi
{
if (queryParameters.Offset.HasValue)
{
errorMessage = "pageSize cannot be used with limit/offset paging.";
errorMessage = "Use limit instead of pageSize when using limit/offset paging.";
}
else
{
errorMessage = "pageToken is required when pageSize is specified.";
errorMessage = "PageToken is required when pageSize is specified.";
}

return false;
Expand All @@ -47,19 +47,19 @@ public static bool IsValid(IQueryParameters queryParameters, int defaultPageLimi
// Validate the values provided
if (queryParameters.Offset is < 0)
{
errorMessage = $"offset cannot be a negative value.";
errorMessage = $"Offset cannot be a negative value.";
return false;
}

if (queryParameters.Limit is < 0)
{
errorMessage = $"limit cannot be a negative value.";
errorMessage = $"Limit must be a value between 0 and {defaultPageLimitSize}.";
return false;
}

if (queryParameters.Limit.HasValue && queryParameters.Limit > defaultPageLimitSize)
{
errorMessage = $"limit cannot be greater than {defaultPageLimitSize}.";
errorMessage = $"Limit must be a value between 0 and {defaultPageLimitSize}.";
return false;
}
}
Expand All @@ -75,13 +75,13 @@ public static bool IsValid(IQueryParameters queryParameters, int defaultPageLimi
// Validate the values provided
if (queryParameters.PageSize is < 0)
{
errorMessage = $"pageSize cannot be a negative value.";
errorMessage = $"PageSize must be a value between 0 and {defaultPageLimitSize}.";
return false;
}

if (queryParameters.PageSize.HasValue && queryParameters.PageSize > defaultPageLimitSize)
{
errorMessage = $"pageSize cannot be greater than {defaultPageLimitSize}.";
errorMessage = $"PageSize must be a value between 0 and {defaultPageLimitSize}.";
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public enum Parameters
}

[TestCase(true, Parameters.None)]
[TestCase(false, Parameters.PageSize, "pageToken is required when pageSize is specified.")]
[TestCase(false, Parameters.PageSize, "PageToken is required when pageSize is specified.")]
[TestCase(true, Parameters.PageToken)]
[TestCase(true, Parameters.PageToken | Parameters.PageSize)]
[TestCase(true, Parameters.Limit)]
[TestCase(true, Parameters.Limit | Parameters.PageSize)]
[TestCase(false, Parameters.Limit | Parameters.PageToken, "Use pageSize instead of limit when using cursor paging with pageToken.")]
[TestCase(true, Parameters.Limit | Parameters.PageToken | Parameters.PageSize)]
[TestCase(true, Parameters.Offset)]
[TestCase(false, Parameters.Offset | Parameters.PageSize, "pageSize cannot be used with limit/offset paging.")]
[TestCase(false, Parameters.Offset | Parameters.PageSize, "Use limit instead of pageSize when using limit/offset paging.")]
[TestCase(false, Parameters.Offset | Parameters.PageToken, "Both offset and pageToken parameters were provided, but they support alternative paging approaches and cannot be used together.")]
[TestCase(false, Parameters.Offset | Parameters.PageToken | Parameters.PageSize, "Both offset and pageToken parameters were provided, but they support alternative paging approaches and cannot be used together.")]
[TestCase(true, Parameters.Offset | Parameters.Limit)]
Expand Down Expand Up @@ -101,7 +101,7 @@ public void IsValid_WithNegativeOffset_ShouldReturnFalseWithErrorMessage()

// Assert
result.ShouldBeFalse();
errorMessage.ShouldBe("offset cannot be a negative value.");
errorMessage.ShouldBe("Offset cannot be a negative value.");
}

[Test]
Expand All @@ -118,7 +118,7 @@ public void IsValid_WithNegativeLimit_ShouldReturnFalseWithErrorMessage()

// Assert
result.ShouldBeFalse();
errorMessage.ShouldBe("limit cannot be a negative value.");
errorMessage.ShouldBe($"Limit must be a value between 0 and {DefaultPageLimitSize}.");
}

[Test]
Expand All @@ -135,7 +135,7 @@ public void IsValid_WithLimitGreaterThanDefaultPageLimit_ShouldReturnFalseWithEr

// Assert
result.ShouldBeFalse();
errorMessage.ShouldBe($"limit cannot be greater than {DefaultPageLimitSize}.");
errorMessage.ShouldBe($"Limit must be a value between 0 and {DefaultPageLimitSize}.");
}

[Test]
Expand Down Expand Up @@ -171,7 +171,7 @@ public void IsValid_WithNegativePageSize_ShouldReturnFalseWithErrorMessage()

// Assert
result.ShouldBeFalse();
errorMessage.ShouldBe("pageSize cannot be a negative value.");
errorMessage.ShouldBe($"PageSize must be a value between 0 and {DefaultPageLimitSize}.");
}

[Test]
Expand All @@ -190,7 +190,7 @@ public void IsValid_WithPageSizeGreaterThanDefaultLimit_ShouldReturnFalseWithErr

// Assert
result.ShouldBeFalse();
errorMessage.ShouldBe($"pageSize cannot be greater than {DefaultPageLimitSize}.");
errorMessage.ShouldBe($"PageSize must be a value between 0 and {DefaultPageLimitSize}.");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "d3d5da8b-42ff-4fcb-bb76-d215b5cebd98",
"_postman_id": "5e983aaa-3e8f-45dd-af38-2aa59f79ceda",
"name": "Ed-Fi ODS/API Integration Test Suite ResponseTests",
"description": "Localhost integration testing using Postman Scripts",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
Expand Down Expand Up @@ -863,17 +863,18 @@
" pm.expect(pm.response.code).to.equal(400);",
"});",
"",
"pm.test(\"Should return a message indicating that the limit must be omitted or set to a value between 0 and 500.\", () => {",
"pm.test(\"Should return a message indicating that the limit must be between 0 and 500.\", () => {",
" const problemDetails = pm.response.json();",
"",
" pm.expect(pm.response.code).equal(problemDetails.status);",
" pm.expect(problemDetails.type).to.equal(\"urn:ed-fi:api:bad-request:parameter-validation-failed\");",
" pm.expect(problemDetails.detail).to.equal(\"The request construction was invalid.\");",
"",
" pm.expect(problemDetails.errors[0]).to.equal(\"Limit must be omitted or set to a value between 0 and 500.\");",
" pm.expect(problemDetails.errors[0]).to.equal(\"Limit must be a value between 0 and 500.\");",
"});"
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
},
{
Expand All @@ -882,7 +883,8 @@
"exec": [
""
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
}
],
Expand Down Expand Up @@ -927,17 +929,18 @@
" pm.expect(pm.response.code).to.equal(400);",
"});",
"",
"pm.test(\"Should return a message indicating that the limit must be omitted or set to a value between 0 and 500.\", () => {",
"pm.test(\"Should return a message indicating that the limit must be a value between 0 and 500.\", () => {",
" const problemDetails = pm.response.json();",
"",
" pm.expect(pm.response.code).equal(problemDetails.status);",
" pm.expect(problemDetails.type).to.equal(\"urn:ed-fi:api:bad-request:parameter-validation-failed\");",
" pm.expect(problemDetails.detail).to.equal(\"The request construction was invalid.\");",
"",
" pm.expect(problemDetails.errors[0]).to.equal(\"Limit must be omitted or set to a value between 0 and 500.\");",
" pm.expect(problemDetails.errors[0]).to.equal(\"Limit must be a value between 0 and 500.\");",
"});"
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
},
{
Expand All @@ -946,7 +949,8 @@
"exec": [
""
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
}
],
Expand Down Expand Up @@ -2520,7 +2524,8 @@
"exec": [
""
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
},
{
Expand All @@ -2531,17 +2536,18 @@
" pm.expect(pm.response.code).to.equal(400);",
"});",
"",
"pm.test(\"Should return a message indicating that the limit must be omitted or set to a value between 0 and 500.\", () => {",
"pm.test(\"Should return a message indicating that the limit must be a value between 0 and 500.\", () => {",
" const problemDetails = pm.response.json();",
"",
" pm.expect(pm.response.code).equal(problemDetails.status);",
" pm.expect(problemDetails.type).to.equal(\"urn:ed-fi:api:bad-request:parameter-validation-failed\");",
" pm.expect(problemDetails.detail).to.equal(\"The request construction was invalid.\");",
"",
" pm.expect(problemDetails.errors[0]).to.equal(\"Limit must be omitted or set to a value between 0 and 500.\");",
" pm.expect(problemDetails.errors[0]).to.equal(\"Limit must be a value between 0 and 500.\");",
"});"
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
}
],
Expand Down Expand Up @@ -2588,7 +2594,8 @@
"exec": [
""
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
},
{
Expand All @@ -2599,17 +2606,18 @@
" pm.expect(pm.response.code).to.equal(400);",
"});",
"",
"pm.test(\"Should return a message indicating that the limit must be omitted or set to a value between 0 and 500.\", () => {",
"pm.test(\"Should return a message indicating that the limit must be a value between 0 and 500.\", () => {",
" const problemDetails = pm.response.json();",
"",
" pm.expect(pm.response.code).equal(problemDetails.status);",
" pm.expect(problemDetails.type).to.equal(\"urn:ed-fi:api:bad-request:parameter-validation-failed\");",
" pm.expect(problemDetails.detail).to.equal(\"The request construction was invalid.\");",
"",
" pm.expect(problemDetails.errors[0]).to.equal(\"Limit must be omitted or set to a value between 0 and 500.\");",
" pm.expect(problemDetails.errors[0]).to.equal(\"Limit must be a value between 0 and 500.\");",
"});"
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
}
],
Expand Down
Loading

0 comments on commit 8b30f9c

Please sign in to comment.