Skip to content

Commit 63897db

Browse files
Request meta tests boilerplate (#1746)
* Basic boilerplate for writing meta tests Related to #1500 * test: accepts top level meta in POST resource request * test: accepts top level meta in PATCH relationship request * test: accepts top level meta in POST relationship request * test: accepts top level meta in DELETE relationship request * test: accepts top level meta in atomic UPDATE resource request * test: accepts top level meta in atomic ADD resource request * test: accepts top level meta in atomic REMOVE resource request * test: accepts meta in data of POST resource request * test: accepts meta in relationship of POST resource request * test: accepts meta in data of atomic ADD resource request * test: accepts meta in relationship of atomic UPDATE resource request * refactor after execute inspect code script * remove code style warnings * Rune code cleanup * Fix inspections * Align request meta integration tests with JSON:API requirements * fix some code styles * fix missing code styles warnings * Fix clean up code warnings * Fix inspect code warnings * Fix clean up warnings * Add meta fakers and refactor * Add post resource request with to many relationships * Add relationship endpoints tests * Isolate atomic operations request tests * Add missing meta data coverage * Resolve code cleanup warnings * Resolve remaining code cleanup warnings * Fix build * fix warnings * Add test to check meta in operation level * Revert "Add test to check meta in operation level" This reverts commit 5ee4d79. * Add test to check meta in operation level * Fix compilation error * fix warnings * fix cleanup-code task * Pushed updates addressing review comments. * Pushed updates addressing missing review comments. * Fix failed code inspection * Pushed updates addressing review comments. * Pushed updates addressing missing review comments. * Pushed updates addressing review comments. * Fix compilation error. * Fix cleanup code errors. * Fix build errors. * Fix build errors. * Pushed updates addressing review comments. * Pushed updates addressing review comments. * Fix declaration order * Cleanup whitespace --------- Co-authored-by: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
1 parent b7a7307 commit 63897db

7 files changed

Lines changed: 1421 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using JsonApiDotNetCore.Serialization.Objects;
2+
using JsonApiDotNetCore.Serialization.Request.Adapters;
3+
4+
namespace JsonApiDotNetCoreTests.IntegrationTests.Meta;
5+
6+
internal sealed class CapturingDocumentAdapter : IDocumentAdapter
7+
{
8+
private readonly IDocumentAdapter _innerAdapter;
9+
private readonly RequestDocumentStore _requestDocumentStore;
10+
11+
public CapturingDocumentAdapter(IDocumentAdapter innerAdapter, RequestDocumentStore requestDocumentStore)
12+
{
13+
ArgumentNullException.ThrowIfNull(innerAdapter);
14+
ArgumentNullException.ThrowIfNull(requestDocumentStore);
15+
16+
_innerAdapter = innerAdapter;
17+
_requestDocumentStore = requestDocumentStore;
18+
}
19+
20+
public object? Convert(Document document)
21+
{
22+
_requestDocumentStore.Document = document;
23+
return _innerAdapter.Convert(document);
24+
}
25+
}

test/JsonApiDotNetCoreTests/IntegrationTests/Meta/MetaFakers.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,51 @@ internal sealed class MetaFakers
1616
.MakeDeterministic()
1717
.RuleFor(supportTicket => supportTicket.Description, faker => faker.Lorem.Paragraph()));
1818

19+
private readonly Lazy<Faker<Dictionary<string, object?>>> _lazyDocumentMetaFaker = new(() => new Faker<Dictionary<string, object?>>()
20+
.MakeDeterministic()
21+
.CustomInstantiator(faker => new Dictionary<string, object?>
22+
{
23+
["requestId"] = faker.Random.Guid().ToString(),
24+
["isUrgent"] = faker.Random.Bool()
25+
}));
26+
27+
private readonly Lazy<Faker<Dictionary<string, object?>>> _lazyResourceMetaFaker = new(() => new Faker<Dictionary<string, object?>>()
28+
.MakeDeterministic()
29+
.CustomInstantiator(faker => new Dictionary<string, object?>
30+
{
31+
["editedBy"] = faker.Internet.UserName(),
32+
["revision"] = faker.Random.Int(1, 10)
33+
}));
34+
35+
private readonly Lazy<Faker<Dictionary<string, object?>>> _lazyRelationshipMetaFaker = new(() => new Faker<Dictionary<string, object?>>()
36+
.MakeDeterministic()
37+
.CustomInstantiator(faker => new Dictionary<string, object?>
38+
{
39+
["source"] = faker.PickRandom("ui", "api", "import"),
40+
["confidence"] = faker.Random.Double(0.1),
41+
["details"] = null
42+
}));
43+
44+
private readonly Lazy<Faker<Dictionary<string, object?>>> _lazyIdentifierMetaFaker = new(() => new Faker<Dictionary<string, object?>>()
45+
.MakeDeterministic()
46+
.CustomInstantiator(faker => new Dictionary<string, object?>
47+
{
48+
["index"] = faker.IndexFaker,
49+
["optionalNote"] = faker.Lorem.Word()
50+
}));
51+
52+
private readonly Lazy<Faker<Dictionary<string, object?>>> _lazyOperationMetaFaker = new(() => new Faker<Dictionary<string, object?>>()
53+
.MakeDeterministic()
54+
.CustomInstantiator(faker => new Dictionary<string, object?>
55+
{
56+
["version"] = faker.Random.Int(1, 10)
57+
}));
58+
1959
public Faker<ProductFamily> ProductFamily => _lazyProductFamilyFaker.Value;
2060
public Faker<SupportTicket> SupportTicket => _lazySupportTicketFaker.Value;
61+
public Faker<Dictionary<string, object?>> DocumentMeta => _lazyDocumentMetaFaker.Value;
62+
public Faker<Dictionary<string, object?>> ResourceMeta => _lazyResourceMetaFaker.Value;
63+
public Faker<Dictionary<string, object?>> RelationshipMeta => _lazyRelationshipMetaFaker.Value;
64+
public Faker<Dictionary<string, object?>> IdentifierMeta => _lazyIdentifierMetaFaker.Value;
65+
public Faker<Dictionary<string, object?>> OperationMeta => _lazyOperationMetaFaker.Value;
2166
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using JsonApiDotNetCore.AtomicOperations;
2+
using JsonApiDotNetCore.Configuration;
3+
using JsonApiDotNetCore.Controllers;
4+
using JsonApiDotNetCore.Middleware;
5+
using JsonApiDotNetCore.Resources;
6+
using Microsoft.Extensions.Logging;
7+
8+
namespace JsonApiDotNetCoreTests.IntegrationTests.Meta;
9+
10+
public sealed class OperationsController(
11+
IJsonApiOptions options, IResourceGraph resourceGraph, ILoggerFactory loggerFactory, IOperationsProcessor processor, IJsonApiRequest request,
12+
ITargetedFields targetedFields, IAtomicOperationFilter operationFilter)
13+
: JsonApiOperationsController(options, resourceGraph, loggerFactory, processor, request, targetedFields, operationFilter);

0 commit comments

Comments
 (0)