6
6
using System . Threading . Tasks ;
7
7
using Bogus ;
8
8
using JsonApiDotNetCore . Models ;
9
+ using JsonApiDotNetCore . Models . JsonApiDocuments ;
9
10
using JsonApiDotNetCoreExample ;
10
11
using JsonApiDotNetCoreExample . Data ;
11
12
using JsonApiDotNetCoreExample . Models ;
@@ -149,7 +150,13 @@ public async Task Unauthorized_TodoItem()
149
150
150
151
// Assert
151
152
var body = await response . Content . ReadAsStringAsync ( ) ;
152
- Assert . True ( HttpStatusCode . Forbidden == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
153
+ Assert . Equal ( HttpStatusCode . Forbidden , response . StatusCode ) ;
154
+
155
+ var errorDocument = JsonConvert . DeserializeObject < ErrorDocument > ( body ) ;
156
+ Assert . Single ( errorDocument . Errors ) ;
157
+ Assert . Equal ( HttpStatusCode . Forbidden , errorDocument . Errors [ 0 ] . StatusCode ) ;
158
+ Assert . Equal ( "You are not allowed to update the author of todo items." , errorDocument . Errors [ 0 ] . Title ) ;
159
+ Assert . Null ( errorDocument . Errors [ 0 ] . Detail ) ;
153
160
}
154
161
155
162
[ Fact ]
@@ -163,7 +170,13 @@ public async Task Unauthorized_Passport()
163
170
164
171
// Assert
165
172
var body = await response . Content . ReadAsStringAsync ( ) ;
166
- Assert . True ( HttpStatusCode . Forbidden == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
173
+ Assert . Equal ( HttpStatusCode . Forbidden , response . StatusCode ) ;
174
+
175
+ var errorDocument = JsonConvert . DeserializeObject < ErrorDocument > ( body ) ;
176
+ Assert . Single ( errorDocument . Errors ) ;
177
+ Assert . Equal ( HttpStatusCode . Forbidden , errorDocument . Errors [ 0 ] . StatusCode ) ;
178
+ Assert . Equal ( "You are not allowed to include passports on individual persons." , errorDocument . Errors [ 0 ] . Title ) ;
179
+ Assert . Null ( errorDocument . Errors [ 0 ] . Detail ) ;
167
180
}
168
181
169
182
[ Fact ]
@@ -185,8 +198,13 @@ public async Task Unauthorized_Article()
185
198
186
199
// Assert
187
200
var body = await response . Content . ReadAsStringAsync ( ) ;
188
- Assert . True ( HttpStatusCode . Forbidden == response . StatusCode , $ " { route } returned { response . StatusCode } status code with payload: { body } " ) ;
201
+ Assert . Equal ( HttpStatusCode . Forbidden , response . StatusCode ) ;
189
202
203
+ var errorDocument = JsonConvert . DeserializeObject < ErrorDocument > ( body ) ;
204
+ Assert . Single ( errorDocument . Errors ) ;
205
+ Assert . Equal ( HttpStatusCode . Forbidden , errorDocument . Errors [ 0 ] . StatusCode ) ;
206
+ Assert . Equal ( "You are not allowed to see this article." , errorDocument . Errors [ 0 ] . Title ) ;
207
+ Assert . Null ( errorDocument . Errors [ 0 ] . Detail ) ;
190
208
}
191
209
192
210
[ Fact ]
@@ -300,10 +318,14 @@ public async Task Cascade_Permission_Error_Create_ToOne_Relationship()
300
318
301
319
// Assert
302
320
var body = await response . Content . ReadAsStringAsync ( ) ;
303
- // should throw 403 in PersonResource implicit hook
304
- Assert . True ( HttpStatusCode . Forbidden == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
305
- }
321
+ Assert . Equal ( HttpStatusCode . Forbidden , response . StatusCode ) ;
306
322
323
+ var errorDocument = JsonConvert . DeserializeObject < ErrorDocument > ( body ) ;
324
+ Assert . Single ( errorDocument . Errors ) ;
325
+ Assert . Equal ( HttpStatusCode . Forbidden , errorDocument . Errors [ 0 ] . StatusCode ) ;
326
+ Assert . Equal ( "You are not allowed to update fields or relationships of locked todo items." , errorDocument . Errors [ 0 ] . Title ) ;
327
+ Assert . Null ( errorDocument . Errors [ 0 ] . Detail ) ;
328
+ }
307
329
308
330
[ Fact ]
309
331
public async Task Cascade_Permission_Error_Updating_ToOne_Relationship ( )
@@ -348,8 +370,13 @@ public async Task Cascade_Permission_Error_Updating_ToOne_Relationship()
348
370
349
371
// Assert
350
372
var body = await response . Content . ReadAsStringAsync ( ) ;
351
- Assert . True ( HttpStatusCode . Forbidden == response . StatusCode , $ " { route } returned { response . StatusCode } status code with payload: { body } " ) ;
373
+ Assert . Equal ( HttpStatusCode . Forbidden , response . StatusCode ) ;
352
374
375
+ var errorDocument = JsonConvert . DeserializeObject < ErrorDocument > ( body ) ;
376
+ Assert . Single ( errorDocument . Errors ) ;
377
+ Assert . Equal ( HttpStatusCode . Forbidden , errorDocument . Errors [ 0 ] . StatusCode ) ;
378
+ Assert . Equal ( "You are not allowed to update fields or relationships of locked persons." , errorDocument . Errors [ 0 ] . Title ) ;
379
+ Assert . Null ( errorDocument . Errors [ 0 ] . Detail ) ;
353
380
}
354
381
355
382
[ Fact ]
@@ -395,12 +422,15 @@ public async Task Cascade_Permission_Error_Updating_ToOne_Relationship_Deletion(
395
422
396
423
// Assert
397
424
var body = await response . Content . ReadAsStringAsync ( ) ;
398
- Assert . True ( HttpStatusCode . Forbidden == response . StatusCode , $ " { route } returned { response . StatusCode } status code with payload: { body } " ) ;
425
+ Assert . Equal ( HttpStatusCode . Forbidden , response . StatusCode ) ;
399
426
427
+ var errorDocument = JsonConvert . DeserializeObject < ErrorDocument > ( body ) ;
428
+ Assert . Single ( errorDocument . Errors ) ;
429
+ Assert . Equal ( HttpStatusCode . Forbidden , errorDocument . Errors [ 0 ] . StatusCode ) ;
430
+ Assert . Equal ( "You are not allowed to update fields or relationships of locked persons." , errorDocument . Errors [ 0 ] . Title ) ;
431
+ Assert . Null ( errorDocument . Errors [ 0 ] . Detail ) ;
400
432
}
401
433
402
-
403
-
404
434
[ Fact ]
405
435
public async Task Cascade_Permission_Error_Delete_ToOne_Relationship ( )
406
436
{
@@ -422,10 +452,14 @@ public async Task Cascade_Permission_Error_Delete_ToOne_Relationship()
422
452
423
453
// Assert
424
454
var body = await response . Content . ReadAsStringAsync ( ) ;
425
- Assert . True ( HttpStatusCode . Forbidden == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
426
- }
427
-
455
+ Assert . Equal ( HttpStatusCode . Forbidden , response . StatusCode ) ;
428
456
457
+ var errorDocument = JsonConvert . DeserializeObject < ErrorDocument > ( body ) ;
458
+ Assert . Single ( errorDocument . Errors ) ;
459
+ Assert . Equal ( HttpStatusCode . Forbidden , errorDocument . Errors [ 0 ] . StatusCode ) ;
460
+ Assert . Equal ( "You are not allowed to update fields or relationships of locked todo items." , errorDocument . Errors [ 0 ] . Title ) ;
461
+ Assert . Null ( errorDocument . Errors [ 0 ] . Detail ) ;
462
+ }
429
463
430
464
[ Fact ]
431
465
public async Task Cascade_Permission_Error_Create_ToMany_Relationship ( )
@@ -473,7 +507,13 @@ public async Task Cascade_Permission_Error_Create_ToMany_Relationship()
473
507
474
508
// Assert
475
509
var body = await response . Content . ReadAsStringAsync ( ) ;
476
- Assert . True ( HttpStatusCode . Forbidden == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
510
+ Assert . Equal ( HttpStatusCode . Forbidden , response . StatusCode ) ;
511
+
512
+ var errorDocument = JsonConvert . DeserializeObject < ErrorDocument > ( body ) ;
513
+ Assert . Single ( errorDocument . Errors ) ;
514
+ Assert . Equal ( HttpStatusCode . Forbidden , errorDocument . Errors [ 0 ] . StatusCode ) ;
515
+ Assert . Equal ( "You are not allowed to update fields or relationships of locked todo items." , errorDocument . Errors [ 0 ] . Title ) ;
516
+ Assert . Null ( errorDocument . Errors [ 0 ] . Detail ) ;
477
517
}
478
518
479
519
[ Fact ]
@@ -525,10 +565,13 @@ public async Task Cascade_Permission_Error_Updating_ToMany_Relationship()
525
565
526
566
// Assert
527
567
var body = await response . Content . ReadAsStringAsync ( ) ;
568
+ Assert . Equal ( HttpStatusCode . Forbidden , response . StatusCode ) ;
528
569
529
- // were unrelating a persons from a locked todo, so this should be unauthorized
530
- Assert . True ( HttpStatusCode . Forbidden == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
531
-
570
+ var errorDocument = JsonConvert . DeserializeObject < ErrorDocument > ( body ) ;
571
+ Assert . Single ( errorDocument . Errors ) ;
572
+ Assert . Equal ( HttpStatusCode . Forbidden , errorDocument . Errors [ 0 ] . StatusCode ) ;
573
+ Assert . Equal ( "You are not allowed to update fields or relationships of locked todo items." , errorDocument . Errors [ 0 ] . Title ) ;
574
+ Assert . Null ( errorDocument . Errors [ 0 ] . Detail ) ;
532
575
}
533
576
534
577
[ Fact ]
@@ -552,7 +595,13 @@ public async Task Cascade_Permission_Error_Delete_ToMany_Relationship()
552
595
553
596
// Assert
554
597
var body = await response . Content . ReadAsStringAsync ( ) ;
555
- Assert . True ( HttpStatusCode . Forbidden == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
598
+ Assert . Equal ( HttpStatusCode . Forbidden , response . StatusCode ) ;
599
+
600
+ var errorDocument = JsonConvert . DeserializeObject < ErrorDocument > ( body ) ;
601
+ Assert . Single ( errorDocument . Errors ) ;
602
+ Assert . Equal ( HttpStatusCode . Forbidden , errorDocument . Errors [ 0 ] . StatusCode ) ;
603
+ Assert . Equal ( "You are not allowed to update fields or relationships of locked todo items." , errorDocument . Errors [ 0 ] . Title ) ;
604
+ Assert . Null ( errorDocument . Errors [ 0 ] . Detail ) ;
556
605
}
557
606
}
558
607
}
0 commit comments