@@ -337,6 +337,9 @@ describe("context tests", () => {
337
337
method : "POST" ,
338
338
url : `${ MOCK_QSTASH_SERVER_URL } /v2/batch` ,
339
339
token,
340
+ headers : {
341
+ "content-type" : "application/json" ,
342
+ } ,
340
343
body : [
341
344
{
342
345
body : '"request-body"' ,
@@ -439,6 +442,94 @@ describe("context tests", () => {
439
442
} ,
440
443
} ) ;
441
444
} ) ;
445
+ test ( "should send context.call without parsing body if stringifyBody is false" , async ( ) => {
446
+ const context = new WorkflowContext ( {
447
+ qstashClient,
448
+ initialPayload : "my-payload" ,
449
+ steps : [ ] ,
450
+ url : WORKFLOW_ENDPOINT ,
451
+ headers : new Headers ( ) as Headers ,
452
+ workflowRunId : "wfr-id" ,
453
+ } ) ;
454
+ await mockQStashServer ( {
455
+ execute : ( ) => {
456
+ const throws = ( ) =>
457
+ context . call ( "my-step" , {
458
+ url,
459
+ body,
460
+ headers : { "my-header" : "my-value" } ,
461
+ method : "PATCH" ,
462
+ stringifyBody : false ,
463
+ } ) ;
464
+ expect ( throws ) . toThrowError ( "Aborting workflow after executing step 'my-step'." ) ;
465
+ } ,
466
+ responseFields : {
467
+ status : 200 ,
468
+ body : "msgId" ,
469
+ } ,
470
+ receivesRequest : {
471
+ method : "POST" ,
472
+ url : `${ MOCK_QSTASH_SERVER_URL } /v2/batch` ,
473
+ token,
474
+ body : [
475
+ {
476
+ body : "request-body" ,
477
+ destination : url ,
478
+ headers : {
479
+ "upstash-workflow-sdk-version" : "1" ,
480
+ "content-type" : "application/json" ,
481
+ "upstash-callback" : WORKFLOW_ENDPOINT ,
482
+ "upstash-callback-feature-set" : "LazyFetch,InitialBody,WF_DetectTrigger" ,
483
+ "upstash-callback-forward-upstash-workflow-callback" : "true" ,
484
+ "upstash-callback-forward-upstash-workflow-concurrent" : "1" ,
485
+ "upstash-callback-forward-upstash-workflow-contenttype" : "application/json" ,
486
+ "upstash-callback-forward-upstash-workflow-stepid" : "1" ,
487
+ "upstash-callback-forward-upstash-workflow-stepname" : "my-step" ,
488
+ "upstash-callback-forward-upstash-workflow-steptype" : "Call" ,
489
+ "upstash-callback-workflow-calltype" : "fromCallback" ,
490
+ "upstash-callback-workflow-init" : "false" ,
491
+ "upstash-callback-workflow-runid" : "wfr-id" ,
492
+ "upstash-callback-workflow-url" : WORKFLOW_ENDPOINT ,
493
+ "upstash-feature-set" : "WF_NoDelete,InitialBody" ,
494
+ "upstash-forward-my-header" : "my-value" ,
495
+ "upstash-method" : "PATCH" ,
496
+ "upstash-retries" : "0" ,
497
+ "upstash-workflow-calltype" : "toCallback" ,
498
+ "upstash-workflow-init" : "false" ,
499
+ "upstash-workflow-runid" : "wfr-id" ,
500
+ "upstash-workflow-url" : WORKFLOW_ENDPOINT ,
501
+ } ,
502
+ } ,
503
+ ] ,
504
+ } ,
505
+ } ) ;
506
+ } ) ;
507
+
508
+ test ( "should throw error if stringifyBody is false and body is object" , async ( ) => {
509
+ const context = new WorkflowContext ( {
510
+ qstashClient,
511
+ initialPayload : "my-payload" ,
512
+ steps : [ ] ,
513
+ url : WORKFLOW_ENDPOINT ,
514
+ headers : new Headers ( ) as Headers ,
515
+ workflowRunId : "wfr-id" ,
516
+ } ) ;
517
+
518
+ const throws = ( ) =>
519
+ context . call ( "my-step" , {
520
+ url,
521
+ body : { foo : "bar" } ,
522
+ headers : { "my-header" : "my-value" } ,
523
+ method : "PATCH" ,
524
+ // @ts -expect-error testing error case
525
+ stringifyBody : false ,
526
+ } ) ;
527
+ expect ( throws ) . toThrowError (
528
+ new WorkflowError (
529
+ `When stringifyBody is false, body must be a string. Please check the body type of your call step.`
530
+ )
531
+ ) ;
532
+ } ) ;
442
533
} ) ;
443
534
444
535
test ( "cancel should throw abort with cleanup: true" , async ( ) => {
0 commit comments