Skip to content

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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

mrmarcosmagalhaes
Copy link

@mrmarcosmagalhaes mrmarcosmagalhaes commented Jul 16, 2025

Closes #1500

QUALITY CHECKLIST

@bkoelman bkoelman changed the base branch from request-meta-tests-boilerplate to master July 19, 2025 09:08
@bkoelman
Copy link
Member

Thanks, this looks great!

I've changed the base of this PR, so that status checks run.

Copy link

codecov bot commented Jul 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.75%. Comparing base (8c59d1b) to head (3605490).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


namespace JsonApiDotNetCoreTests.IntegrationTests.Meta;

public sealed class RequestMetaTests : IClassFixture<IntegrationTestContext<TestableStartup<MetaDbContext>, MetaDbContext>>
Copy link
Member

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";
Copy link
Member

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"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add tests for submitting meta
2 participants