Skip to content

Commit 7c768eb

Browse files
test: accepts meta in relationship of POST resource request
1 parent 6bf58d3 commit 7c768eb

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

test/JsonApiDotNetCoreTests/IntegrationTests/Meta/RequestMetaTests.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,64 @@ public async Task Accepts_meta_in_data_of_post_resource_request()
448448
ValidateMetaData(store.Document.Data.SingleValue.Meta);
449449
}
450450

451+
[Fact]
452+
public async Task Accepts_meta_in_relationship_of_post_resource_request()
453+
{
454+
// Arrange
455+
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
456+
457+
SupportTicket existingTicket = _fakers.SupportTicket.GenerateOne();
458+
459+
ProductFamily existingProductFamily = _fakers.ProductFamily.GenerateOne();
460+
461+
await _testContext.RunOnDatabaseAsync(async dbContext =>
462+
{
463+
dbContext.ProductFamilies.Add(existingProductFamily);
464+
await dbContext.SaveChangesAsync();
465+
});
466+
467+
var requestBody = new
468+
{
469+
data = new
470+
{
471+
type = "supportTickets",
472+
attributes = new
473+
{
474+
description = existingTicket.Description,
475+
},
476+
relationships = new
477+
{
478+
productFamily = new
479+
{
480+
data = new
481+
{
482+
type = "productFamilies",
483+
id = existingProductFamily.StringId
484+
},
485+
meta = GetExampleMetaData()
486+
}
487+
}
488+
}
489+
};
490+
491+
string route = $"/supportTickets";
492+
493+
// Act
494+
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAsync<Document>(route, requestBody);
495+
496+
// Assert
497+
httpResponse.ShouldHaveStatusCode(HttpStatusCode.Created);
498+
499+
store.Document.Should().NotBeNull();
500+
store.Document.Data.SingleValue.Should().NotBeNull();
501+
store.Document.Data.SingleValue.Relationships.Should().NotBeNull();
502+
store.Document.Data.SingleValue.Relationships.Should().HaveCount(1);
503+
store.Document.Data.SingleValue.Relationships.TryGetValue("productFamily", out var relationship).Should().BeTrue();
504+
relationship!.Meta.Should().NotBeNull();
505+
506+
ValidateMetaData(relationship.Meta);
507+
}
508+
451509
private static Object GetExampleMetaData()
452510
{
453511
return new

0 commit comments

Comments
 (0)