@@ -10,6 +10,7 @@ import rio, {
1010 REMOVE_ERROR ,
1111 OBJECT_REMOVING ,
1212 OBJECT_REMOVED ,
13+ OBJECT_ERROR ,
1314 REFERENCE_STATUS ,
1415 apiStateMiddleware ,
1516 JSON_API_SOURCE ,
@@ -74,6 +75,14 @@ describe('Delete action creator', () => {
7475 headers : { }
7576 } ,
7677 } ;
78+
79+ const expectedErrorResponseMeta = {
80+ payload : {
81+ data : item ,
82+ } ,
83+ ...expectedResponseMeta ,
84+ } ;
85+
7786 const metaResponse = [ { } , { } , new Response ( null , {
7887 "status" : 200 ,
7988 "headers" : { } ,
@@ -84,7 +93,7 @@ describe('Delete action creator', () => {
8493 expect ( types [ 1 ] . type ) . to . equal ( REMOVE_SUCCESS ) ;
8594 expect ( types [ 1 ] . meta ( ...metaResponse ) ) . to . deep . equal ( expectedResponseMeta ) ;
8695 expect ( types [ 2 ] . type ) . to . equal ( REMOVE_ERROR ) ;
87- expect ( types [ 2 ] . meta ( ...metaResponse ) ) . to . deep . equal ( expectedResponseMeta ) ;
96+ expect ( types [ 2 ] . meta ( ...metaResponse ) ) . to . deep . equal ( expectedErrorResponseMeta ) ;
8897 } ) ;
8998
9099 it ( 'creates a valid action with valid endpoint with filled params' , ( ) => {
@@ -463,4 +472,116 @@ describe('Delete action creator', () => {
463472 } ) ;
464473 } ) . then ( done ) . catch ( done ) ;
465474 } ) ;
475+
476+ it ( 'produces valid storage and collection actions after error' , done => {
477+ const schema = 'schema_test' ;
478+ const item = { id : 1 , type : schema } ;
479+ const expectedPayload = {
480+ data : item ,
481+ } ;
482+
483+ nock ( 'http://api.server.local' )
484+ . delete ( '/apps/1' )
485+ . reply ( 400 , { } , { 'Content-Type' : 'vnd.api+json' } ) ;
486+
487+ const config = {
488+ headers : {
489+ 'Content-Type' : 'application/vnd.api+json' ,
490+ } ,
491+ endpoint : 'http://api.server.local/apps/1' ,
492+ } ;
493+
494+ const schemaConfig = {
495+ schema,
496+ request : config ,
497+ } ;
498+
499+ const expectedMeta = {
500+ source : JSON_API_SOURCE ,
501+ schema,
502+ endpoint : config . endpoint ,
503+ params : { } ,
504+ options : { } ,
505+ } ;
506+
507+ const action = remove ( schemaConfig , item ) ;
508+
509+ const store = mockStore ( { } ) ;
510+ store . dispatch ( action )
511+ . then ( ( ) => {
512+ const performedActions = store . getActions ( ) ;
513+ expect ( performedActions ) . to . have . length ( 4 ) ;
514+
515+ const batchedRemovingActions = performedActions [ 0 ] ;
516+ const actionCollBusyRequest = batchedRemovingActions . payload [ 0 ] ;
517+ expect ( actionCollBusyRequest . type ) . to . equal ( REFERENCE_STATUS ) ;
518+ expect ( actionCollBusyRequest . meta )
519+ . to . deep . equal ( { ...expectedMeta , tag : '*' , timestamp : actionCollBusyRequest . meta . timestamp } ) ;
520+ const expectedCollBusyStatusPayload = {
521+ validationStatus : validationStatus . INVALID ,
522+ busyStatus : busyStatus . BUSY ,
523+ } ;
524+ expect ( actionCollBusyRequest . payload ) . to . deep . equal ( expectedCollBusyStatusPayload ) ;
525+
526+ const actionObjDeleting = batchedRemovingActions . payload [ 1 ] ;
527+ expect ( actionObjDeleting . type ) . to . equal ( OBJECT_REMOVING ) ;
528+ expect ( actionObjDeleting . meta ) . to . deep . equal ( {
529+ ...expectedMeta ,
530+ transformation : { } ,
531+ timestamp : actionObjDeleting . meta . timestamp
532+ } ) ;
533+
534+ expect ( performedActions [ 1 ] . type ) . to . equal ( REMOVE_REQUEST ) ;
535+
536+ const batchedErroredActions = performedActions [ 2 ] ;
537+ const actionObjErrored = batchedErroredActions . payload [ 0 ] ;
538+ expect ( actionObjErrored . type ) . to . equal ( OBJECT_ERROR ) ;
539+ expect ( actionObjErrored . meta ) . to . deep . equal ( {
540+ ...expectedMeta ,
541+ payload : expectedPayload ,
542+ transformation : { } ,
543+ timestamp : actionObjErrored . meta . timestamp ,
544+ response : {
545+ status : 400 ,
546+ headers : {
547+ "content-type" : "vnd.api+json" ,
548+ }
549+ } ,
550+ } ) ;
551+
552+ const actionCollStatus = batchedErroredActions . payload [ 1 ] ;
553+ expect ( actionCollStatus . type ) . to . equal ( REFERENCE_STATUS ) ;
554+ expect ( actionCollStatus . meta ) . to . deep . equal ( {
555+ ...expectedMeta ,
556+ payload : expectedPayload ,
557+ tag : '*' ,
558+ timestamp : actionCollStatus . meta . timestamp ,
559+ response : {
560+ status : 400 ,
561+ headers : {
562+ "content-type" : "vnd.api+json" ,
563+ }
564+ } ,
565+ } ) ;
566+ const expectedCollStatusPayload = {
567+ validationStatus : validationStatus . INVALID ,
568+ busyStatus : busyStatus . IDLE ,
569+ } ;
570+ expect ( actionCollStatus . payload ) . to . deep . equal ( expectedCollStatusPayload ) ;
571+
572+ const errorAction = performedActions [ 3 ] ;
573+ expect ( errorAction . type ) . to . equal ( REMOVE_ERROR ) ;
574+ expect ( errorAction . meta ) . to . deep . equal ( {
575+ ...expectedMeta ,
576+ payload : expectedPayload ,
577+ timestamp : errorAction . meta . timestamp ,
578+ response : {
579+ status : 400 ,
580+ headers : {
581+ "content-type" : "vnd.api+json" ,
582+ }
583+ } ,
584+ } ) ;
585+ } ) . then ( done ) . catch ( done ) ;
586+ } ) ;
466587} ) ;
0 commit comments