@@ -578,6 +578,56 @@ describe("postCheckoutStart request", () => {
578578 expect ( result ) . toEqual ( checkoutStartResponse ) ;
579579 } ) ;
580580
581+ test ( "handles workflow identifier correctly" , async ( ) => {
582+ const backendWithContext = new Backend ( "test_api_key" , undefined , {
583+ workflowIdentifier : "workflow_456" ,
584+ } ) ;
585+
586+ setCheckoutStartResponse (
587+ HttpResponse . json ( checkoutStartResponse , { status : 200 } ) ,
588+ ) ;
589+
590+ await backendWithContext . postCheckoutStart (
591+ "someAppUserId" ,
592+ "monthly" ,
593+ {
594+ offeringIdentifier : "offering_1" ,
595+ targetingContext : null ,
596+ placementIdentifier : null ,
597+ } ,
598+ { id : "base_option" , priceId : "test_price_id" } ,
599+ "test-trace-id" ,
600+ ) ;
601+
602+ expect ( purchaseMethodAPIMock ) . toHaveBeenCalledTimes ( 1 ) ;
603+ const request = purchaseMethodAPIMock . mock . calls [ 0 ] [ 0 ] . request ;
604+ const requestBody = await request . json ( ) ;
605+ expect ( requestBody . presented_workflow_id ) . toBe ( "workflow_456" ) ;
606+ } ) ;
607+
608+ test ( "omits workflow identifier from request when not present" , async ( ) => {
609+ setCheckoutStartResponse (
610+ HttpResponse . json ( checkoutStartResponse , { status : 200 } ) ,
611+ ) ;
612+
613+ await backend . postCheckoutStart (
614+ "someAppUserId" ,
615+ "monthly" ,
616+ {
617+ offeringIdentifier : "offering_1" ,
618+ targetingContext : null ,
619+ placementIdentifier : null ,
620+ } ,
621+ { id : "base_option" , priceId : "test_price_id" } ,
622+ "test-trace-id" ,
623+ ) ;
624+
625+ expect ( purchaseMethodAPIMock ) . toHaveBeenCalledTimes ( 1 ) ;
626+ const request = purchaseMethodAPIMock . mock . calls [ 0 ] [ 0 ] . request ;
627+ const requestBody = await request . json ( ) ;
628+ expect ( requestBody . presented_workflow_id ) . toBeUndefined ( ) ;
629+ } ) ;
630+
581631 test ( "throws an error if the backend returns a server error" , async ( ) => {
582632 setCheckoutStartResponse (
583633 HttpResponse . json ( null , { status : StatusCodes . INTERNAL_SERVER_ERROR } ) ,
@@ -1067,6 +1117,56 @@ describe("postReceipt request", () => {
10671117 expect ( requestBody . presented_placement_identifier ) . toBe ( "home_screen" ) ;
10681118 } ) ;
10691119
1120+ test ( "handles workflow identifier correctly" , async ( ) => {
1121+ const backendWithContext = new Backend ( "test_api_key" , undefined , {
1122+ workflowIdentifier : "workflow_123" ,
1123+ } ) ;
1124+
1125+ setPostReceiptResponse (
1126+ HttpResponse . json ( customerInfoResponse , { status : 200 } ) ,
1127+ ) ;
1128+
1129+ await backendWithContext . postReceipt (
1130+ "someAppUserId" ,
1131+ "monthly" ,
1132+ "EUR" ,
1133+ "test_fetch_token" ,
1134+ {
1135+ offeringIdentifier : "offering_1" ,
1136+ targetingContext : null ,
1137+ placementIdentifier : null ,
1138+ } ,
1139+ "purchase" ,
1140+ ) ;
1141+
1142+ const request = postReceiptAPIMock . mock . calls [ 0 ] [ 0 ] . request ;
1143+ const requestBody = await request . json ( ) ;
1144+ expect ( requestBody . presented_workflow_id ) . toBe ( "workflow_123" ) ;
1145+ } ) ;
1146+
1147+ test ( "omits workflow identifier from postReceipt when not present" , async ( ) => {
1148+ setPostReceiptResponse (
1149+ HttpResponse . json ( customerInfoResponse , { status : 200 } ) ,
1150+ ) ;
1151+
1152+ await backend . postReceipt (
1153+ "someAppUserId" ,
1154+ "monthly" ,
1155+ "EUR" ,
1156+ "test_fetch_token" ,
1157+ {
1158+ offeringIdentifier : "offering_1" ,
1159+ targetingContext : null ,
1160+ placementIdentifier : null ,
1161+ } ,
1162+ "purchase" ,
1163+ ) ;
1164+
1165+ const request = postReceiptAPIMock . mock . calls [ 0 ] [ 0 ] . request ;
1166+ const requestBody = await request . json ( ) ;
1167+ expect ( requestBody . presented_workflow_id ) . toBeUndefined ( ) ;
1168+ } ) ;
1169+
10701170 test ( "throws an error if the backend returns a server error" , async ( ) => {
10711171 setPostReceiptResponse (
10721172 HttpResponse . json ( null , { status : StatusCodes . INTERNAL_SERVER_ERROR } ) ,
0 commit comments