@@ -793,6 +793,80 @@ describe("Workflow Parser", () => {
793
793
} ,
794
794
} ) ;
795
795
796
+ test ( "should show failResponse with warning when payload doesn't have message field" , async ( ) => {
797
+ const routeFunction = async ( context : WorkflowContext ) => {
798
+ await context . sleep ( "sleeping" , 1 ) ;
799
+ } ;
800
+
801
+ const incorrectErrorResponseBody = JSON . stringify ( {
802
+ nonMessageField : "any-value" ,
803
+ } ) ;
804
+
805
+ let calledFailureFunction = false ;
806
+ const failureFunction : WorkflowServeOptions [ "failureFunction" ] = async ( { failResponse } ) => {
807
+ expect ( failResponse ) . toBe (
808
+ `Couldn't parse 'failResponse' in 'failureFunction', received: '${ incorrectErrorResponseBody } '`
809
+ ) ;
810
+ calledFailureFunction = true ;
811
+ return ;
812
+ } ;
813
+
814
+ const result2 = await handleFailure (
815
+ failureRequest ,
816
+ JSON . stringify ( {
817
+ status : 201 ,
818
+ body : btoa ( incorrectErrorResponseBody ) ,
819
+ url : WORKFLOW_ENDPOINT ,
820
+ } ) ,
821
+ client ,
822
+ initialPayloadParser ,
823
+ routeFunction ,
824
+ failureFunction ,
825
+ { } ,
826
+ 0 ,
827
+ undefined
828
+ ) ;
829
+
830
+ expect ( result2 . isOk ( ) ) . toBeTrue ( ) ;
831
+ expect ( calledFailureFunction ) . toBeTrue ( ) ;
832
+ } ) ;
833
+
834
+ test ( "should show failResponse with warning when payload can't be parsed" , async ( ) => {
835
+ const routeFunction = async ( context : WorkflowContext ) => {
836
+ await context . sleep ( "sleeping" , 1 ) ;
837
+ } ;
838
+
839
+ const nonJSONPayload = "helloWorld" ;
840
+
841
+ let calledFailureFunction = false ;
842
+ const failureFunction : WorkflowServeOptions [ "failureFunction" ] = async ( { failResponse } ) => {
843
+ expect ( failResponse ) . toBe (
844
+ `Couldn't parse 'failResponse' in 'failureFunction', received: '${ nonJSONPayload } '`
845
+ ) ;
846
+ calledFailureFunction = true ;
847
+ return ;
848
+ } ;
849
+
850
+ const result2 = await handleFailure (
851
+ failureRequest ,
852
+ JSON . stringify ( {
853
+ status : 201 ,
854
+ body : btoa ( nonJSONPayload ) ,
855
+ url : WORKFLOW_ENDPOINT ,
856
+ } ) ,
857
+ client ,
858
+ initialPayloadParser ,
859
+ routeFunction ,
860
+ failureFunction ,
861
+ { } ,
862
+ 0 ,
863
+ undefined
864
+ ) ;
865
+
866
+ expect ( result2 . isOk ( ) ) . toBeTrue ( ) ;
867
+ expect ( calledFailureFunction ) . toBeTrue ( ) ;
868
+ } ) ;
869
+
796
870
test ( "should throw WorkflowError if header is set but function is not passed" , async ( ) => {
797
871
let called = false ;
798
872
const routeFunction = async ( context : WorkflowContext ) => {
@@ -875,7 +949,6 @@ describe("Workflow Parser", () => {
875
949
0 ,
876
950
undefined
877
951
) ;
878
- console . log ( result ) ;
879
952
880
953
expect ( result . isOk ( ) ) . toBeTrue ( ) ;
881
954
expect ( result . isOk ( ) && result . value ) . toBe ( "is-failure-callback" ) ;
0 commit comments