@@ -20,7 +20,7 @@ function postJson(port, path, body) {
2020 raw += chunk ;
2121 } ) ;
2222 res . on ( 'end' , ( ) => {
23- resolve ( { statusCode : res . statusCode , body : JSON . parse ( raw ) } ) ;
23+ resolve ( { statusCode : res . statusCode , headers : res . headers , body : JSON . parse ( raw ) } ) ;
2424 } ) ;
2525 }
2626 ) ;
@@ -55,6 +55,7 @@ test('paid-action emits receipt and enforces idempotency', async () => {
5555
5656 const first = await postJson ( port , '/paid-action' , payload ) ;
5757 assert . equal ( first . statusCode , 200 ) ;
58+ assert . equal ( first . headers [ 'cache-control' ] , 'no-store' ) ;
5859 assert . equal ( first . body . duplicate , false ) ;
5960 assert . equal ( first . body . receipt . request_id , 'req_test_1' ) ;
6061 assert . equal ( first . body . receipt . payment_id , 'pay_test_1' ) ;
@@ -63,8 +64,29 @@ test('paid-action emits receipt and enforces idempotency', async () => {
6364
6465 const second = await postJson ( port , '/paid-action' , payload ) ;
6566 assert . equal ( second . statusCode , 200 ) ;
67+ assert . equal ( second . headers [ 'cache-control' ] , 'no-store' ) ;
6668 assert . equal ( second . body . duplicate , true ) ;
6769 assert . equal ( second . body . receipt . receipt_id , first . body . receipt . receipt_id ) ;
6870
6971 await new Promise ( ( resolve , reject ) => server . close ( ( err ) => ( err ? reject ( err ) : resolve ( ) ) ) ) ;
7072} ) ;
73+
74+ test ( 'paid-action payment errors are not cacheable' , async ( ) => {
75+ const server = createServer ( ) ;
76+ await new Promise ( ( resolve ) => server . listen ( 0 , resolve ) ) ;
77+ const port = server . address ( ) . port ;
78+
79+ const res = await postJson ( port , '/paid-action' , {
80+ paid_action_request : {
81+ request_id : 'req_missing_payment' ,
82+ action : 'summarize.text' ,
83+ input : { text : 'Payment is intentionally missing.' } ,
84+ payment : { required : true , plan : 'pro' , max_amount : '0.05' , currency : 'USD' }
85+ }
86+ } ) ;
87+
88+ assert . equal ( res . statusCode , 402 ) ;
89+ assert . equal ( res . headers [ 'cache-control' ] , 'no-store' ) ;
90+
91+ await new Promise ( ( resolve , reject ) => server . close ( ( err ) => ( err ? reject ( err ) : resolve ( ) ) ) ) ;
92+ } ) ;
0 commit comments