Skip to content

Commit 169acc7

Browse files
author
Bart Koelman
committed
Added missing assertions on request body in error meta
1 parent 6e0d287 commit 169acc7

21 files changed

+286
-0
lines changed

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ public async Task Cannot_create_resource_for_href_element()
497497
error.Title.Should().Be("Failed to deserialize request body: The 'href' element is not supported.");
498498
error.Detail.Should().BeNull();
499499
error.Source.Pointer.Should().Be("/atomic:operations[0]/href");
500+
501+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
500502
}
501503

502504
[Fact]
@@ -533,6 +535,8 @@ public async Task Cannot_create_resource_for_ref_element()
533535
error.Title.Should().Be("Failed to deserialize request body: The 'relationship' element is required.");
534536
error.Detail.Should().BeNull();
535537
error.Source.Pointer.Should().Be("/atomic:operations[0]/ref");
538+
539+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
536540
}
537541

538542
[Fact]
@@ -565,6 +569,8 @@ public async Task Cannot_create_resource_for_missing_data()
565569
error.Title.Should().Be("Failed to deserialize request body: The 'data' element is required.");
566570
error.Detail.Should().BeNull();
567571
error.Source.Pointer.Should().Be("/atomic:operations[0]");
572+
573+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
568574
}
569575

570576
[Fact]
@@ -598,6 +604,8 @@ public async Task Cannot_create_resource_for_null_data()
598604
error.Title.Should().Be("Failed to deserialize request body: Expected an object in 'data' element, instead of 'null'.");
599605
error.Detail.Should().BeNull();
600606
error.Source.Pointer.Should().Be("/atomic:operations[0]/data");
607+
608+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
601609
}
602610

603611
[Fact]
@@ -643,6 +651,8 @@ public async Task Cannot_create_resource_for_array_data()
643651
error.Title.Should().Be("Failed to deserialize request body: Expected an object in 'data' element, instead of an array.");
644652
error.Detail.Should().BeNull();
645653
error.Source.Pointer.Should().Be("/atomic:operations[0]/data");
654+
655+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
646656
}
647657

648658
[Fact]
@@ -681,6 +691,8 @@ public async Task Cannot_create_resource_for_missing_type()
681691
error.Title.Should().Be("Failed to deserialize request body: The 'type' element is required.");
682692
error.Detail.Should().BeNull();
683693
error.Source.Pointer.Should().Be("/atomic:operations[0]/data");
694+
695+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
684696
}
685697

686698
[Fact]
@@ -717,6 +729,8 @@ public async Task Cannot_create_resource_for_unknown_type()
717729
error.Title.Should().Be("Failed to deserialize request body: Unknown resource type found.");
718730
error.Detail.Should().Be($"Resource type '{Unknown.ResourceType}' does not exist.");
719731
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/type");
732+
733+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
720734
}
721735

722736
[Fact]
@@ -757,6 +771,8 @@ public async Task Cannot_create_resource_attribute_with_blocked_capability()
757771
error.Title.Should().Be("Failed to deserialize request body: Attribute value cannot be assigned when creating resource.");
758772
error.Detail.Should().Be("The attribute 'createdAt' on resource type 'lyrics' cannot be assigned to.");
759773
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/attributes/createdAt");
774+
775+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
760776
}
761777

762778
[Fact]
@@ -800,6 +816,8 @@ public async Task Cannot_create_resource_with_readonly_attribute()
800816
error.Title.Should().Be("Failed to deserialize request body: Attribute is read-only.");
801817
error.Detail.Should().Be("Attribute 'isArchived' on resource type 'playlists' is read-only.");
802818
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/attributes/isArchived");
819+
820+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
803821
}
804822

805823
[Fact]
@@ -840,6 +858,8 @@ public async Task Cannot_create_resource_with_incompatible_attribute_value()
840858
error.Title.Should().Be("Failed to deserialize request body: Incompatible attribute value found.");
841859
error.Detail.Should().Be("Failed to convert attribute 'bornAt' with value '12345' of type 'Number' to type 'DateTimeOffset'.");
842860
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/attributes/bornAt");
861+
862+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
843863
}
844864

845865
[Fact]

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceWithClientGeneratedIdTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ public async Task Cannot_create_resource_for_incompatible_ID()
228228
error.Title.Should().Be("Failed to deserialize request body: Incompatible 'id' value found.");
229229
error.Detail.Should().Be($"Failed to convert '{guid}' of type 'String' to type 'Int32'.");
230230
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/id");
231+
232+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
231233
}
232234

233235
[Fact]
@@ -266,6 +268,8 @@ public async Task Cannot_create_resource_for_ID_and_local_ID()
266268
error.Title.Should().Be("Failed to deserialize request body: The 'id' and 'lid' element are mutually exclusive.");
267269
error.Detail.Should().BeNull();
268270
error.Source.Pointer.Should().Be("/atomic:operations[0]/data");
271+
272+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
269273
}
270274
}
271275
}

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceWithToManyRelationshipTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ public async Task Cannot_create_for_missing_relationship_type()
235235
error.Title.Should().Be("Failed to deserialize request body: The 'type' element is required.");
236236
error.Detail.Should().BeNull();
237237
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/performers/data[0]");
238+
239+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
238240
}
239241

240242
[Fact]
@@ -285,6 +287,8 @@ public async Task Cannot_create_for_unknown_relationship_type()
285287
error.Title.Should().Be("Failed to deserialize request body: Unknown resource type found.");
286288
error.Detail.Should().Be($"Resource type '{Unknown.ResourceType}' does not exist.");
287289
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/performers/data[0]/type");
290+
291+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
288292
}
289293

290294
[Fact]
@@ -334,6 +338,8 @@ public async Task Cannot_create_for_missing_relationship_ID()
334338
error.Title.Should().Be("Failed to deserialize request body: The 'id' or 'lid' element is required.");
335339
error.Detail.Should().BeNull();
336340
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/performers/data[0]");
341+
342+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
337343
}
338344

339345
[Fact]
@@ -454,6 +460,8 @@ public async Task Cannot_create_on_relationship_type_mismatch()
454460
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
455461
error.Detail.Should().Be("Type 'playlists' is incompatible with type 'performers' of relationship 'performers'.");
456462
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/performers/data[0]/type");
463+
464+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
457465
}
458466

459467
[Fact]
@@ -572,6 +580,8 @@ public async Task Cannot_create_with_missing_data_in_OneToMany_relationship()
572580
error.Title.Should().Be("Failed to deserialize request body: The 'data' element is required.");
573581
error.Detail.Should().BeNull();
574582
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/performers");
583+
584+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
575585
}
576586

577587
[Fact]
@@ -615,6 +625,8 @@ public async Task Cannot_create_with_null_data_in_ManyToMany_relationship()
615625
error.Title.Should().Be("Failed to deserialize request body: Expected an array in 'data' element, instead of 'null'.");
616626
error.Detail.Should().BeNull();
617627
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/tracks/data");
628+
629+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
618630
}
619631

620632
[Fact]
@@ -660,6 +672,8 @@ public async Task Cannot_create_with_object_data_in_ManyToMany_relationship()
660672
error.Title.Should().Be("Failed to deserialize request body: Expected an array in 'data' element, instead of an object.");
661673
error.Detail.Should().BeNull();
662674
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/tracks/data");
675+
676+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
663677
}
664678
}
665679
}

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceWithToOneRelationshipTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ public async Task Cannot_create_for_missing_data_in_relationship()
296296
error.Title.Should().Be("Failed to deserialize request body: The 'data' element is required.");
297297
error.Detail.Should().BeNull();
298298
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/lyric");
299+
300+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
299301
}
300302

301303
[Fact]
@@ -346,6 +348,8 @@ public async Task Cannot_create_for_array_data_in_relationship()
346348
error.Title.Should().Be("Failed to deserialize request body: Expected an object or 'null' in 'data' element, instead of an array.");
347349
error.Detail.Should().BeNull();
348350
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/lyric/data");
351+
352+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
349353
}
350354

351355
[Fact]
@@ -392,6 +396,8 @@ public async Task Cannot_create_for_missing_relationship_type()
392396
error.Title.Should().Be("Failed to deserialize request body: The 'type' element is required.");
393397
error.Detail.Should().BeNull();
394398
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/lyric/data");
399+
400+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
395401
}
396402

397403
[Fact]
@@ -439,6 +445,8 @@ public async Task Cannot_create_for_unknown_relationship_type()
439445
error.Title.Should().Be("Failed to deserialize request body: Unknown resource type found.");
440446
error.Detail.Should().Be($"Resource type '{Unknown.ResourceType}' does not exist.");
441447
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/lyric/data/type");
448+
449+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
442450
}
443451

444452
[Fact]
@@ -485,6 +493,8 @@ public async Task Cannot_create_for_missing_relationship_ID()
485493
error.Title.Should().Be("Failed to deserialize request body: The 'id' or 'lid' element is required.");
486494
error.Detail.Should().BeNull();
487495
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/lyric/data");
496+
497+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
488498
}
489499

490500
[Fact]
@@ -581,6 +591,8 @@ public async Task Cannot_create_on_relationship_type_mismatch()
581591
error.Title.Should().Be("Failed to deserialize request body: Incompatible resource type found.");
582592
error.Detail.Should().Be("Type 'playlists' is incompatible with type 'lyrics' of relationship 'lyric'.");
583593
error.Source.Pointer.Should().Be("/atomic:operations[0]/data/relationships/lyric/data/type");
594+
595+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
584596
}
585597

586598
[Fact]

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Deleting/AtomicDeleteResourceTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ public async Task Cannot_delete_resource_for_href_element()
359359
error.Title.Should().Be("Failed to deserialize request body: The 'href' element is not supported.");
360360
error.Detail.Should().BeNull();
361361
error.Source.Pointer.Should().Be("/atomic:operations[0]/href");
362+
363+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
362364
}
363365

364366
[Fact]
@@ -391,6 +393,8 @@ public async Task Cannot_delete_resource_for_missing_ref_element()
391393
error.Title.Should().Be("Failed to deserialize request body: The 'ref' element is required.");
392394
error.Detail.Should().BeNull();
393395
error.Source.Pointer.Should().Be("/atomic:operations[0]");
396+
397+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
394398
}
395399

396400
[Fact]
@@ -427,6 +431,8 @@ public async Task Cannot_delete_resource_for_missing_type()
427431
error.Title.Should().Be("Failed to deserialize request body: The 'type' element is required.");
428432
error.Detail.Should().BeNull();
429433
error.Source.Pointer.Should().Be("/atomic:operations[0]/ref");
434+
435+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
430436
}
431437

432438
[Fact]
@@ -464,6 +470,8 @@ public async Task Cannot_delete_resource_for_unknown_type()
464470
error.Title.Should().Be("Failed to deserialize request body: Unknown resource type found.");
465471
error.Detail.Should().Be($"Resource type '{Unknown.ResourceType}' does not exist.");
466472
error.Source.Pointer.Should().Be("/atomic:operations[0]/ref/type");
473+
474+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
467475
}
468476

469477
[Fact]
@@ -500,6 +508,8 @@ public async Task Cannot_delete_resource_for_missing_ID()
500508
error.Title.Should().Be("Failed to deserialize request body: The 'id' or 'lid' element is required.");
501509
error.Detail.Should().BeNull();
502510
error.Source.Pointer.Should().Be("/atomic:operations[0]/ref");
511+
512+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
503513
}
504514

505515
[Fact]
@@ -578,6 +588,8 @@ public async Task Cannot_delete_resource_for_incompatible_ID()
578588
error.Title.Should().Be("Failed to deserialize request body: Incompatible 'id' value found.");
579589
error.Detail.Should().Be($"Failed to convert '{guid}' of type 'String' to type 'Int64'.");
580590
error.Source.Pointer.Should().Be("/atomic:operations[0]/ref/id");
591+
592+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
581593
}
582594

583595
[Fact]
@@ -616,6 +628,8 @@ public async Task Cannot_delete_resource_for_ID_and_local_ID()
616628
error.Title.Should().Be("Failed to deserialize request body: The 'id' and 'lid' element are mutually exclusive.");
617629
error.Detail.Should().BeNull();
618630
error.Source.Pointer.Should().Be("/atomic:operations[0]/ref");
631+
632+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
619633
}
620634
}
621635
}

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Mixed/AtomicRequestBodyTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public async Task Cannot_process_for_missing_operations_array()
9191
error.Title.Should().Be("Failed to deserialize request body: No operations found.");
9292
error.Detail.Should().BeNull();
9393
error.Source.Should().BeNull();
94+
95+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
9496
}
9597

9698
[Fact]
@@ -117,6 +119,8 @@ public async Task Cannot_process_empty_operations_array()
117119
error.Title.Should().Be("Failed to deserialize request body: No operations found.");
118120
error.Detail.Should().BeNull();
119121
error.Source.Should().BeNull();
122+
123+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
120124
}
121125

122126
[Fact]

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Mixed/MaximumOperationsPerRequestTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public async Task Cannot_process_more_operations_than_maximum()
7575
error.Title.Should().Be("Failed to deserialize request body: Too many operations in request.");
7676
error.Detail.Should().Be("The number of operations in this request (3) is higher than the maximum of 2.");
7777
error.Source.Pointer.Should().Be("/atomic:operations");
78+
79+
responseDocument.Meta["requestBody"].ToString().Should().NotBeNullOrEmpty();
7880
}
7981

8082
[Fact]

0 commit comments

Comments
 (0)