-
-
Notifications
You must be signed in to change notification settings - Fork 158
Support query param operations on nested resources #634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d787ff6
fix: support include on nested resources route
maurei f530d37
fix: related unit test
maurei daab069
test: add nested resource filter test
maurei 5a33e72
chore: abort attempt to fix filter/sort/select/page
maurei 2082d1b
fix: rogue character
maurei 5f920a2
feat: 400 on unsupported nested resources query params
maurei e65a02e
fix: redundant spacing
maurei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/NestedResourceTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Linq; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Bogus; | ||
using JsonApiDotNetCoreExample.Models; | ||
using JsonApiDotNetCoreExampleTests.Helpers.Models; | ||
using Xunit; | ||
using Person = JsonApiDotNetCoreExample.Models.Person; | ||
|
||
namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec | ||
{ | ||
public class NestedResourceTests : FunctionalTestCollection<StandardApplicationFactory> | ||
{ | ||
private readonly Faker<TodoItem> _todoItemFaker; | ||
private readonly Faker<Person> _personFaker; | ||
private readonly Faker<Passport> _passportFaker; | ||
|
||
public NestedResourceTests(StandardApplicationFactory factory) : base(factory) | ||
{ | ||
_todoItemFaker = new Faker<TodoItem>() | ||
.RuleFor(t => t.Description, f => f.Lorem.Sentence()) | ||
.RuleFor(t => t.Ordinal, f => f.Random.Number()) | ||
.RuleFor(t => t.CreatedDate, f => f.Date.Past()); | ||
_personFaker = new Faker<Person>() | ||
.RuleFor(t => t.FirstName, f => f.Name.FirstName()) | ||
.RuleFor(t => t.LastName, f => f.Name.LastName()); | ||
_passportFaker = new Faker<Passport>() | ||
.RuleFor(t => t.SocialSecurityNumber, f => f.Random.Number()); | ||
} | ||
|
||
[Fact] | ||
public async Task NestedResourceRoute_RequestWithIncludeQueryParam_ReturnsRequestedRelationships() | ||
{ | ||
// Arrange | ||
var assignee = _dbContext.Add(_personFaker.Generate()).Entity; | ||
var todo = _dbContext.Add(_todoItemFaker.Generate()).Entity; | ||
var owner = _dbContext.Add(_personFaker.Generate()).Entity; | ||
var passport = _dbContext.Add(_passportFaker.Generate()).Entity; | ||
_dbContext.SaveChanges(); | ||
todo.AssigneeId = assignee.Id; | ||
todo.OwnerId = owner.Id; | ||
owner.PassportId = passport.Id; | ||
_dbContext.SaveChanges(); | ||
|
||
// Act | ||
var (body, response) = await Get($"/api/v1/people/{assignee.Id}/assignedTodoItems?include=owner.passport"); | ||
|
||
// Assert | ||
AssertEqualStatusCode(HttpStatusCode.OK, response); | ||
var resultTodoItem = _deserializer.DeserializeList<TodoItemClient>(body).Data.SingleOrDefault(); | ||
Assert.Equal(todo.Id, resultTodoItem.Id); | ||
Assert.Equal(todo.Owner.Id, resultTodoItem.Owner.Id); | ||
Assert.Equal(todo.Owner.Passport.Id, resultTodoItem.Owner.Passport.Id); | ||
} | ||
|
||
[Theory] | ||
[InlineData("filter[ordinal]=1")] | ||
[InlineData("fields=ordinal")] | ||
[InlineData("sort=ordinal")] | ||
[InlineData("page[number]=1")] | ||
[InlineData("page[size]=10")] | ||
public async Task NestedResourceRoute_RequestWithUnsupportedQueryParam_ReturnsBadRequest(string queryParam) | ||
{ | ||
// Act | ||
var (body, response) = await Get($"/api/v1/people/1/assignedTodoItems?{queryParam}"); | ||
maurei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Assert | ||
AssertEqualStatusCode(HttpStatusCode.BadRequest, response); | ||
Assert.Contains("currently not supported", body); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.