@@ -1024,6 +1024,7 @@ describe("basic usage", function() {
1024
1024
} ) ;
1025
1025
} ) ;
1026
1026
1027
+
1027
1028
it ( 'should allow per action response interceptor that gets full response' , function ( ) {
1028
1029
CreditCard = $resource ( '/CreditCard' , { } , {
1029
1030
query : {
@@ -1082,6 +1083,65 @@ describe("basic usage", function() {
1082
1083
} ) ;
1083
1084
1084
1085
1086
+ describe ( 'success mode' , function ( ) {
1087
+ it ( 'should call the success callback (as 1st argument) on 2xx responses' , function ( ) {
1088
+ var instance , headers , status , statusText ;
1089
+ var successCb = jasmine . createSpy ( 'successCb' ) . and . callFake ( function ( d , h , s , t ) {
1090
+ expect ( d ) . toBe ( instance ) ;
1091
+ expect ( h ( ) ) . toEqual ( jasmine . objectContaining ( headers ) ) ;
1092
+ expect ( s ) . toBe ( status ) ;
1093
+ expect ( t ) . toBe ( statusText ) ;
1094
+ } ) ;
1095
+
1096
+ instance = CreditCard . get ( successCb ) ;
1097
+ headers = { foo : 'bar' } ;
1098
+ status = 200 ;
1099
+ statusText = 'OK' ;
1100
+ $httpBackend . expect ( 'GET' , '/CreditCard' ) . respond ( status , { } , headers , statusText ) ;
1101
+ $httpBackend . flush ( ) ;
1102
+
1103
+ expect ( successCb ) . toHaveBeenCalledOnce ( ) ;
1104
+
1105
+ instance = CreditCard . get ( successCb ) ;
1106
+ headers = { baz : 'qux' } ;
1107
+ status = 299 ;
1108
+ statusText = 'KO' ;
1109
+ $httpBackend . expect ( 'GET' , '/CreditCard' ) . respond ( status , { } , headers , statusText ) ;
1110
+ $httpBackend . flush ( ) ;
1111
+
1112
+ expect ( successCb ) . toHaveBeenCalledTimes ( 2 ) ;
1113
+ } ) ;
1114
+
1115
+
1116
+ it ( 'should call the success callback (as 2nd argument) on 2xx responses' , function ( ) {
1117
+ var instance , headers , status , statusText ;
1118
+ var successCb = jasmine . createSpy ( 'successCb' ) . and . callFake ( function ( d , h , s , t ) {
1119
+ expect ( d ) . toBe ( instance ) ;
1120
+ expect ( h ( ) ) . toEqual ( jasmine . objectContaining ( headers ) ) ;
1121
+ expect ( s ) . toBe ( status ) ;
1122
+ expect ( t ) . toBe ( statusText ) ;
1123
+ } ) ;
1124
+
1125
+ instance = CreditCard . get ( { id : 123 } , successCb ) ;
1126
+ headers = { foo : 'bar' } ;
1127
+ status = 200 ;
1128
+ statusText = 'OK' ;
1129
+ $httpBackend . expect ( 'GET' , '/CreditCard/123' ) . respond ( status , { } , headers , statusText ) ;
1130
+ $httpBackend . flush ( ) ;
1131
+
1132
+ expect ( successCb ) . toHaveBeenCalledOnce ( ) ;
1133
+
1134
+ instance = CreditCard . get ( { id : 456 } , successCb ) ;
1135
+ headers = { baz : 'qux' } ;
1136
+ status = 299 ;
1137
+ statusText = 'KO' ;
1138
+ $httpBackend . expect ( 'GET' , '/CreditCard/456' ) . respond ( status , { } , headers , statusText ) ;
1139
+ $httpBackend . flush ( ) ;
1140
+
1141
+ expect ( successCb ) . toHaveBeenCalledTimes ( 2 ) ;
1142
+ } ) ;
1143
+ } ) ;
1144
+
1085
1145
describe ( 'failure mode' , function ( ) {
1086
1146
var ERROR_CODE = 500 ,
1087
1147
ERROR_RESPONSE = 'Server Error' ,
0 commit comments