@@ -917,81 +917,6 @@ describe('Shopify', () => {
917
917
) ;
918
918
} ) ;
919
919
920
- it ( 'can add a hook to not throw an error when the response has errors' , ( ) => {
921
- const customerDataErrors = [
922
- {
923
- message :
924
- 'This app is not approved to use the email field. See https://partners.shopify.com/1/apps/1/customer_data for more details.' ,
925
- path : [ 'customers' , 'edges' , '0' , 'node' , 'email' ] ,
926
- extensions : {
927
- code : 'ACCESS_DENIED' ,
928
- documentation :
929
- 'https://partners.shopify.com/1/apps/1/customer_data' ,
930
- requiredAccess :
931
- 'Shopify approval is required before using the email field.'
932
- }
933
- } ,
934
- {
935
- message :
936
- 'This app is not approved to use the firstName field. See https://partners.shopify.com/1/apps/1/customer_data for more details.' ,
937
- path : [ 'customers' , 'edges' , '0' , 'node' , 'firstName' ] ,
938
- extensions : {
939
- code : 'ACCESS_DENIED' ,
940
- documentation :
941
- 'https://partners.shopify.com/1/apps/1/customer_data' ,
942
- requiredAccess :
943
- 'Shopify approval is required before using the firstName field.'
944
- }
945
- }
946
- ] ;
947
-
948
- let calledWithErrors = undefined ;
949
-
950
- const shopify = new Shopify ( {
951
- shopName,
952
- accessToken,
953
- hooks : {
954
- afterResponse : [
955
- ( res ) => {
956
- if ( res . body && res . body . errors ) {
957
- calledWithErrors = res . body . errors ;
958
-
959
- res . body . errors = undefined ;
960
- }
961
-
962
- return res ;
963
- }
964
- ]
965
- }
966
- } ) ;
967
-
968
- scope . post ( '/admin/api/graphql.json' ) . reply ( 200 , {
969
- data : {
970
- customers : {
971
- edges : [
972
- {
973
- node : {
974
- id : 'gid://shopify/Customer/1234567890' ,
975
- email : null ,
976
- firstName : null
977
- }
978
- }
979
- ]
980
- }
981
- } ,
982
- errors : customerDataErrors
983
- } ) ;
984
-
985
- return shopify . graphql ( 'query' ) . then ( ( result ) => {
986
- expect ( calledWithErrors ) . to . deep . equal ( customerDataErrors ) ;
987
- expect ( result . customers . edges [ 0 ] . node . id ) . to . equal (
988
- 'gid://shopify/Customer/1234567890'
989
- ) ;
990
- expect ( result . customers . edges [ 0 ] . node . email ) . to . equal ( null ) ;
991
- expect ( result . customers . edges [ 0 ] . node . firstName ) . to . equal ( null ) ;
992
- } ) ;
993
- } ) ;
994
-
995
920
it ( 'uses basic auth as intended' , ( ) => {
996
921
const shopify = new Shopify ( { shopName, apiKey, password } ) ;
997
922
@@ -1313,6 +1238,62 @@ describe('Shopify', () => {
1313
1238
} ) ;
1314
1239
} ) ;
1315
1240
1241
+ it ( 'runs the afterResponse error hook after the user hooks' , ( ) => {
1242
+ function afterResponse ( response ) {
1243
+ afterResponse . errors = response . body . errors ;
1244
+ //
1245
+ // Prevents errors from being thrown.
1246
+ //
1247
+ response . body . errors = undefined ;
1248
+ return response ;
1249
+ }
1250
+
1251
+ const data = {
1252
+ customers : {
1253
+ edges : [
1254
+ {
1255
+ node : {
1256
+ id : 'gid://shopify/Customer/1234567890' ,
1257
+ email : null
1258
+ }
1259
+ }
1260
+ ]
1261
+ }
1262
+ } ;
1263
+
1264
+ const errors = [
1265
+ {
1266
+ message :
1267
+ 'This app is not approved to use the email field. ' +
1268
+ 'See https://partners.shopify.com/1/apps/1/customer_data ' +
1269
+ 'for more details.' ,
1270
+ path : [ 'customers' , 'edges' , '0' , 'node' , 'email' ] ,
1271
+ extensions : {
1272
+ code : 'ACCESS_DENIED' ,
1273
+ documentation :
1274
+ 'https://partners.shopify.com/1/apps/1/customer_data' ,
1275
+ requiredAccess :
1276
+ 'Shopify approval is required before using the email field.'
1277
+ }
1278
+ }
1279
+ ] ;
1280
+
1281
+ scope . post ( '/admin/api/graphql.json' ) . reply ( 200 , { data, errors } ) ;
1282
+
1283
+ const shopify = new Shopify ( {
1284
+ shopName,
1285
+ accessToken,
1286
+ hooks : {
1287
+ afterResponse : [ afterResponse ]
1288
+ }
1289
+ } ) ;
1290
+
1291
+ return shopify . graphql ( 'query' ) . then ( ( result ) => {
1292
+ expect ( afterResponse . errors ) . to . deep . equal ( errors ) ;
1293
+ expect ( result ) . to . deep . equal ( data ) ;
1294
+ } ) ;
1295
+ } ) ;
1296
+
1316
1297
it ( 'calls the beforeRetry hook for retried requests' , ( ) => {
1317
1298
function beforeRetry ( ) {
1318
1299
beforeRetry . called = true ;
0 commit comments