Skip to content

Commit d34319e

Browse files
test: accepts top level meta in POST relationship request
1 parent 11a6580 commit d34319e

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/JsonApiDotNetCoreTests/IntegrationTests/Meta/RequestMetaTests.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,62 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
172172
ValidateMetaData(store.Document.Meta);
173173
}
174174

175+
[Fact]
176+
public async Task Accepts_top_level_meta_in_post_relationship_request()
177+
{
178+
// Arrange
179+
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
180+
181+
SupportTicket existingTicket = _fakers.SupportTicket.GenerateOne();
182+
183+
ProductFamily existingProductFamily = _fakers.ProductFamily.GenerateOne();
184+
185+
await _testContext.RunOnDatabaseAsync(async dbContext =>
186+
{
187+
dbContext.ProductFamilies.Add(existingProductFamily);
188+
await dbContext.SaveChangesAsync();
189+
});
190+
191+
var requestBody = new
192+
{
193+
data = new
194+
{
195+
type = "supportTickets",
196+
attributes = new
197+
{
198+
description = existingTicket.Description,
199+
},
200+
relationships = new
201+
{
202+
productFamily = new
203+
{
204+
data = new
205+
{
206+
type = "productFamilies",
207+
id = existingProductFamily.StringId
208+
}
209+
}
210+
}
211+
},
212+
meta = GetExampleMetaData()
213+
};
214+
215+
string route = $"/supportTickets";
216+
217+
// Act
218+
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAsync<Document>(route, requestBody);
219+
220+
// Assert
221+
httpResponse.ShouldHaveStatusCode(HttpStatusCode.Created);
222+
223+
store.Document.Should().NotBeNull();
224+
store.Document.Data.SingleValue.Should().NotBeNull();
225+
store.Document.Data.SingleValue.Relationships.Should().NotBeNull();
226+
store.Document.Data.SingleValue.Relationships.Should().HaveCount(1);
227+
228+
ValidateMetaData(store.Document.Meta);
229+
}
230+
175231
private static Object GetExampleMetaData()
176232
{
177233
return new

0 commit comments

Comments
 (0)