Skip to content

Commit 607ca90

Browse files
Add missing meta data coverage
1 parent cacd9c6 commit 607ca90

2 files changed

Lines changed: 44 additions & 17 deletions

File tree

test/JsonApiDotNetCoreTests/IntegrationTests/Meta/OperationsRequestMetaTests.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Net;
2-
using System.Text.Json;
32
using FluentAssertions;
43
using JsonApiDotNetCore.Serialization.Objects;
54
using JsonApiDotNetCore.Serialization.Request.Adapters;
@@ -45,6 +44,7 @@ public async Task Accepts_meta_in_atomic_update_resource_operation()
4544
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
4645

4746
var documentMeta = _fakers.DocumentMeta.GenerateOne();
47+
var resourceMeta = _fakers.ResourceMeta.GenerateOne();
4848

4949
SupportTicket existingTicket = _fakers.SupportTicket.GenerateOne();
5050

@@ -68,7 +68,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
6868
attributes = new
6969
{
7070
description = existingTicket.Description
71-
}
71+
},
72+
meta = resourceMeta
7273
}
7374
}
7475
},
@@ -95,10 +96,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
9596

9697
ResourceObject? resource = operation.Data.SingleValue;
9798
resource.Should().NotBeNull();
98-
resource.Type.Should().Be("supportTickets");
99-
resource.Id.Should().Be(existingTicket.StringId);
100-
resource.Attributes.Should().NotBeNull();
101-
resource.Attributes.Should().ContainKey("description");
99+
resource.Meta.Should().BeEquivalentToJson(resourceMeta);
102100
}
103101

104102
[Fact]
@@ -158,6 +156,7 @@ public async Task Accepts_meta_in_relationship_of_atomic_add_resource_operation(
158156
var documentMeta = _fakers.DocumentMeta.GenerateOne();
159157
var resourceMeta = _fakers.ResourceMeta.GenerateOne();
160158
var relationshipMeta = _fakers.RelationshipMeta.GenerateOne();
159+
var identifierMeta = _fakers.RelationshipIdentifierMeta.GenerateOne();
161160

162161
string newTicketDescription = _fakers.SupportTicket.GenerateOne().Description;
163162
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
@@ -189,7 +188,8 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
189188
data = new
190189
{
191190
type = "productFamilies",
192-
id = existingFamily.StringId
191+
id = existingFamily.StringId,
192+
meta = identifierMeta
193193
},
194194
meta = relationshipMeta
195195
}
@@ -228,7 +228,14 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
228228
operation.Data.SingleValue.Relationships.Should().ContainKey("productFamily").WhoseValue.With(value =>
229229
{
230230
value.Should().NotBeNull();
231+
231232
value.Meta.Should().BeEquivalentToJson(relationshipMeta);
233+
234+
value.Data.Should().NotBeNull();
235+
236+
value.Data.SingleValue.Should().NotBeNull();
237+
238+
value.Data.SingleValue.Meta.Should().BeEquivalentToJson(identifierMeta);
232239
});
233240
}
234241

@@ -550,6 +557,7 @@ public async Task Accepts_meta_in_remove_from_relationship_operation()
550557

551558
var documentMeta = _fakers.DocumentMeta.GenerateOne();
552559
var relationshipMeta = _fakers.RelationshipMeta.GenerateOne();
560+
var identifierMeta = _fakers.RelationshipIdentifierMeta.GenerateOne();
553561

554562
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
555563
SupportTicket existingTicket1 = _fakers.SupportTicket.GenerateOne();
@@ -587,6 +595,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
587595
{
588596
type = "supportTickets",
589597
id = existingTicket1.StringId,
598+
meta = identifierMeta
590599
}
591600
},
592601
meta = relationshipMeta
@@ -617,8 +626,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
617626
op.Data.ManyValue.Should().NotBeNull();
618627
op.Data.ManyValue.Should().HaveCount(1);
619628

620-
op.Data.ManyValue[0].Type.Should().Be("supportTickets");
621-
op.Data.ManyValue[0].Id.Should().Be(existingTicket1.StringId);
629+
op.Data.ManyValue[0].Meta.Should().BeEquivalentToJson(identifierMeta);
622630
}
623631

624632
private sealed class CapturingDocumentAdapter : IDocumentAdapter

test/JsonApiDotNetCoreTests/IntegrationTests/Meta/RequestMetaTests.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Net;
2-
using System.Text.Json;
32
using FluentAssertions;
43
using JsonApiDotNetCore.Serialization.Objects;
54
using JsonApiDotNetCore.Serialization.Request.Adapters;
@@ -47,6 +46,7 @@ public async Task Accepts_meta_in_update_resource_request_with_to_one_relationsh
4746
var documentMeta = _fakers.DocumentMeta.GenerateOne();
4847
var resourceMeta = _fakers.ResourceMeta.GenerateOne();
4948
var relationshipMeta = _fakers.RelationshipMeta.GenerateOne();
49+
var identifierMeta = _fakers.RelationshipIdentifierMeta.GenerateOne();
5050

5151
SupportTicket existingTicket = _fakers.SupportTicket.GenerateOne();
5252
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
@@ -71,7 +71,8 @@ await _testContext.RunOnDatabaseAsync(async dbContex =>
7171
data = new
7272
{
7373
type = "productFamilies",
74-
id = existingFamily.StringId
74+
id = existingFamily.StringId,
75+
meta = identifierMeta
7576
},
7677
meta = relationshipMeta
7778
}
@@ -103,6 +104,8 @@ await _testContext.RunOnDatabaseAsync(async dbContex =>
103104
{
104105
value.Should().NotBeNull();
105106
value.Meta.Should().BeEquivalentToJson(relationshipMeta);
107+
value.Data.SingleValue.Should().NotBeNull();
108+
value.Data.SingleValue.Meta.Should().BeEquivalentToJson(identifierMeta);
106109
});
107110
}
108111

@@ -197,6 +200,9 @@ public async Task Accepts_meta_in_post_resource_request_with_to_one_relationship
197200
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
198201

199202
var documentMeta = _fakers.DocumentMeta.GenerateOne();
203+
var resourceMeta = _fakers.ResourceMeta.GenerateOne();
204+
var relationshipMeta = _fakers.RelationshipMeta.GenerateOne();
205+
var identifierMeta = _fakers.RelationshipIdentifierMeta.GenerateOne();
200206

201207
string newTicketDescription = _fakers.SupportTicket.GenerateOne().Description;
202208
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
@@ -223,10 +229,13 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
223229
data = new
224230
{
225231
type = "productFamilies",
226-
id = existingFamily.StringId
227-
}
232+
id = existingFamily.StringId,
233+
meta = identifierMeta
234+
},
235+
meta = relationshipMeta
228236
}
229-
}
237+
},
238+
meta = resourceMeta
230239
},
231240
meta = documentMeta
232241
};
@@ -243,13 +252,19 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
243252

244253
store.Document.Meta.Should().BeEquivalentToJson(documentMeta);
245254
store.Document.Data.SingleValue.Should().NotBeNull();
255+
256+
store.Document.Data.SingleValue.Meta.Should().BeEquivalentToJson(resourceMeta);
257+
246258
store.Document.Data.SingleValue.Relationships.Should().NotBeNull();
247259
store.Document.Data.SingleValue.Relationships.Should().ContainKey("productFamily").WhoseValue.With(value =>
248260
{
249261
value.Should().NotBeNull();
262+
263+
value.Meta.Should().BeEquivalentToJson(relationshipMeta);
264+
250265
value.Data.SingleValue.Should().NotBeNull();
251-
value.Data.SingleValue.Type.Should().Be("productFamilies");
252-
value.Data.SingleValue.Id.Should().Be(existingFamily.StringId);
266+
267+
value.Data.SingleValue.Meta.Should().BeEquivalentToJson(identifierMeta);
253268
});
254269
}
255270

@@ -261,6 +276,7 @@ public async Task Accepts_meta_in_post_resource_request_with_to_many_relationshi
261276

262277
var documentMeta = _fakers.DocumentMeta.GenerateOne();
263278
var resourceMeta = _fakers.ResourceMeta.GenerateOne();
279+
var relationshipMeta = _fakers.RelationshipMeta.GenerateOne();
264280
var identifierMeta1 = _fakers.RelationshipIdentifierMeta.GenerateOne();
265281
var identifierMeta2 = _fakers.RelationshipIdentifierMeta.GenerateOne();
266282

@@ -302,7 +318,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
302318
meta = identifierMeta2
303319
}
304320
},
305-
321+
meta = relationshipMeta
306322
}
307323
},
308324
meta = resourceMeta
@@ -326,10 +342,13 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
326342
store.Document.Data.SingleValue.Meta.Should().BeEquivalentToJson(resourceMeta);
327343

328344
store.Document.Data.SingleValue.Relationships.Should().NotBeNull();
345+
329346
store.Document.Data.SingleValue.Relationships.Should().ContainKey("tickets").WhoseValue.With(value =>
330347
{
331348
value.Should().NotBeNull();
332349

350+
value.Meta.Should().BeEquivalentToJson(relationshipMeta);
351+
333352
value.Data.ManyValue.Should().HaveCount(2);
334353

335354
value.Data.ManyValue[0].Meta.Should().BeEquivalentToJson(identifierMeta1);

0 commit comments

Comments
 (0)