@@ -351,4 +351,156 @@ def test_rollback_from_error
351351 assert_equal ( :no_content , operation_results . results [ 1 ] . code )
352352 assert_equal ( 404 , operation_results . results [ 2 ] . code )
353353 end
354+
355+ def test_show_operation
356+ op = JSONAPI ::OperationsProcessor . new
357+
358+ operations = [
359+ JSONAPI ::ShowOperation . new ( PlanetResource , { id : '1' } )
360+ ]
361+
362+ request = JSONAPI ::Request . new
363+ request . operations = operations
364+
365+ operation_results = op . process ( request )
366+
367+ assert_kind_of ( JSONAPI ::OperationResults , operation_results )
368+ assert_equal ( operation_results . results . size , 1 )
369+ refute operation_results . has_errors?
370+ end
371+
372+ def test_show_operation_error
373+ op = JSONAPI ::OperationsProcessor . new
374+
375+ operations = [
376+ JSONAPI ::ShowOperation . new ( PlanetResource , { id : '145' } )
377+ ]
378+
379+ request = JSONAPI ::Request . new
380+ request . operations = operations
381+
382+ operation_results = op . process ( request )
383+
384+ assert_kind_of ( JSONAPI ::OperationResults , operation_results )
385+ assert_equal ( operation_results . results . size , 1 )
386+ assert operation_results . has_errors?
387+ end
388+
389+ def test_show_association_operation
390+ op = JSONAPI ::OperationsProcessor . new
391+
392+ operations = [
393+ JSONAPI ::ShowAssociationOperation . new ( PlanetResource , { parent_key : '1' , association_type : :planet_type } )
394+ ]
395+
396+ request = JSONAPI ::Request . new
397+ request . operations = operations
398+
399+ operation_results = op . process ( request )
400+
401+ assert_kind_of ( JSONAPI ::OperationResults , operation_results )
402+ assert_equal ( operation_results . results . size , 1 )
403+ refute operation_results . has_errors?
404+ end
405+
406+ def test_show_association_operation_error
407+ op = JSONAPI ::OperationsProcessor . new
408+
409+ operations = [
410+ JSONAPI ::ShowAssociationOperation . new ( PlanetResource , { parent_key : '145' , association_type : :planet_type } )
411+ ]
412+
413+ request = JSONAPI ::Request . new
414+ request . operations = operations
415+
416+ operation_results = op . process ( request )
417+
418+ assert_kind_of ( JSONAPI ::OperationResults , operation_results )
419+ assert_equal ( operation_results . results . size , 1 )
420+ assert operation_results . has_errors?
421+ end
422+
423+ def test_show_related_resource_operation
424+ op = JSONAPI ::OperationsProcessor . new
425+
426+ operations = [
427+ JSONAPI ::ShowRelatedResourceOperation . new ( PlanetResource ,
428+ {
429+ source_klass : PlanetResource ,
430+ source_id : '1' ,
431+ association_type : :planet_type } )
432+ ]
433+
434+ request = JSONAPI ::Request . new
435+ request . operations = operations
436+
437+ operation_results = op . process ( request )
438+
439+ assert_kind_of ( JSONAPI ::OperationResults , operation_results )
440+ assert_equal ( operation_results . results . size , 1 )
441+ refute operation_results . has_errors?
442+ end
443+
444+ def test_show_related_resource_operation_error
445+ op = JSONAPI ::OperationsProcessor . new
446+
447+ operations = [
448+ JSONAPI ::ShowRelatedResourceOperation . new ( PlanetResource ,
449+ {
450+ source_klass : PlanetResource ,
451+ source_id : '145' ,
452+ association_type : :planet_type } )
453+ ]
454+
455+ request = JSONAPI ::Request . new
456+ request . operations = operations
457+
458+ operation_results = op . process ( request )
459+
460+ assert_kind_of ( JSONAPI ::OperationResults , operation_results )
461+ assert_equal ( operation_results . results . size , 1 )
462+ assert operation_results . has_errors?
463+ end
464+
465+ def test_show_related_resources_operation
466+ op = JSONAPI ::OperationsProcessor . new
467+
468+ operations = [
469+ JSONAPI ::ShowRelatedResourcesOperation . new ( PlanetResource ,
470+ {
471+ source_klass : PlanetResource ,
472+ source_id : '1' ,
473+ association_type : :moons } )
474+ ]
475+
476+ request = JSONAPI ::Request . new
477+ request . operations = operations
478+
479+ operation_results = op . process ( request )
480+
481+ assert_kind_of ( JSONAPI ::OperationResults , operation_results )
482+ assert_equal ( operation_results . results . size , 1 )
483+ refute operation_results . has_errors?
484+ end
485+
486+ def test_show_related_resources_operation_error
487+ op = JSONAPI ::OperationsProcessor . new
488+
489+ operations = [
490+ JSONAPI ::ShowRelatedResourcesOperation . new ( PlanetResource ,
491+ {
492+ source_klass : PlanetResource ,
493+ source_id : '145' ,
494+ association_type : :moons } )
495+ ]
496+
497+ request = JSONAPI ::Request . new
498+ request . operations = operations
499+
500+ operation_results = op . process ( request )
501+
502+ assert_kind_of ( JSONAPI ::OperationResults , operation_results )
503+ assert_equal ( operation_results . results . size , 1 )
504+ assert operation_results . has_errors?
505+ end
354506end
0 commit comments