-
-
Notifications
You must be signed in to change notification settings - Fork 159
Request meta tests boilerplate #1746
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
base: master
Are you sure you want to change the base?
Request meta tests boilerplate #1746
Conversation
Thanks, this looks great! I've changed the base of this PR, so that status checks run. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1746 +/- ##
=======================================
Coverage 90.75% 90.75%
=======================================
Files 468 468
Lines 14662 14662
Branches 2315 2315
=======================================
+ Hits 13306 13307 +1
+ Misses 920 919 -1
Partials 436 436 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
||
namespace JsonApiDotNetCoreTests.IntegrationTests.Meta; | ||
|
||
public sealed class RequestMetaTests : IClassFixture<IntegrationTestContext<TestableStartup<MetaDbContext>, MetaDbContext>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following endpoints are missing:
- operations: update-to-one-relationship
- operations: update-to-many-relationship
- operations: add-to-relationship
- operations: delete-from-relationship
Relationships come in two flavors: to-one (data
contains an object in the request body) and to-many (data
contains an array in the request body). We should have coverage for both.
Additionally, data
can contain either a resource object (consisting of attributes and/or relationships), or a resource identifier object (consisting of types/ids, but no fields). See the JSON:API spec for details and examples.
Furthermore, there are additional places where meta
can occur in request bodies. For example:
var document = new Document
{
Meta = [],
Data = new SingleOrManyData<ResourceObject>(new ResourceObject
{
Meta = [],
Relationships = new Dictionary<string, RelationshipObject?>
{
["some"] = new()
{
Meta = [],
Data = new SingleOrManyData<ResourceIdentifierObject>(new ResourceIdentifierObject
{
Meta = []
})
}
}
}),
Operations =
[
new AtomicOperationObject
{
Meta = [],
Data = new SingleOrManyData<ResourceObject>(new List<ResourceObject>
{
new()
{
Meta = [],
Relationships = new Dictionary<string, RelationshipObject?>
{
["some"] = new()
{
Meta = [],
Data = new SingleOrManyData<ResourceIdentifierObject>(new List<ResourceIdentifierObject>
{
new()
{
Meta = []
}
})
}
}
}
})
}
]
};
For demonstration, I've used data arrays only in operations above, but single/many can occur in all places.
Based on all the possible combinations, I don't think it makes sense to separate tests by the place where meta occurs (top-level, data, relationship, etc.). It would be easier to have a single test per endpoint/operation that contains all possible locations for that endpoint. However, because we're dealing with both to-one and to-many relationships, we'll need separate endpoints (because SupportTicket
contains a to-one, whereas ProductFamily
contains a to-many).
So, for example:
- Accepts_meta_in_patch_resource_request_with_to_one_relationship: PATCH /supportTickets
- Accepts_meta_in_patch_resource_request_with_to_many_relationship: PATCH /productFamilies
Oh, and relationship endpoints don't take attributes/relationships, so they should be removed from the existing tests.
meta = GetExampleMetaData() | ||
}; | ||
|
||
const string route = "/supportTickets"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a post-relationship request. It is a post-resource request that includes a relationship.
A post-relationship request would look like:
POST /supportTickets/1/relationships/productFamily
{
"data": {
"type": "productFamilies",
"id": "5"
}
}
Closes #1500
QUALITY CHECKLIST