@@ -108,41 +108,91 @@ describe("provider boundary", () => {
108108 ) . rejects . toMatchObject ( { code : "AFFILIATE_PROVIDER_SCOPE_MISMATCH" } ) ;
109109 }
110110 } ) ;
111- it ( "projects commercial links without exposing provider wallet or beneficiary data" , async ( ) => {
111+ const providerOffer = {
112+ id,
113+ code : "AF-0123456789" ,
114+ url : "https://evil.test" ,
115+ name : "Share" ,
116+ productId : "vm_compute" ,
117+ planId : null ,
118+ commissionBps : 2000 ,
119+ discountBps : 500 ,
120+ durationMonths : 12 ,
121+ status : "active" ,
122+ createdAt : "2026-11-19T00:00:00.000Z" ,
123+ expiresAt : null ,
124+ revokedAt : null ,
125+ user_id : "provider-secret" ,
126+ participant_key : "private" ,
127+ wallet : 1000000 ,
128+ } ;
129+ const dashboardUrl = "https://app.openship.test" ;
130+
131+ it . each ( [ "createOffer" , "revokeOffer" ] as const ) (
132+ "accepts the v2 product and keeps private fields out of %s" ,
133+ async ( operation ) => {
134+ const billing = { referralRequest : vi . fn ( async ( ) => envelope ( providerOffer ) ) } ;
135+ const result = await callReferralProvider ( billing , scope , dashboardUrl , operation , { id } ) ;
136+ expect ( result ) . toMatchObject ( {
137+ productId : "vm_compute" ,
138+ url : "https://app.openship.test/r/AF-0123456789" ,
139+ } ) ;
140+ expect ( result ) . not . toHaveProperty ( "user_id" ) ;
141+ expect ( result ) . not . toHaveProperty ( "wallet" ) ;
142+ expect ( result ) . not . toHaveProperty ( "participant_key" ) ;
143+ } ,
144+ ) ;
145+
146+ it ( "lists v2 offers and rejects other product IDs" , async ( ) => {
112147 const billing = {
113- referralRequest : vi . fn ( async ( ) =>
148+ referralRequest : vi . fn ( async ( ) => envelope ( { total : 1 , items : [ providerOffer ] } ) ) ,
149+ } ;
150+ const result = await callReferralProvider ( billing , scope , dashboardUrl , "offers" ) ;
151+ expect ( result . items ) . toHaveLength ( 1 ) ;
152+ expect ( result . items [ 0 ] ) . toMatchObject ( {
153+ productId : "vm_compute" ,
154+ url : "https://app.openship.test/r/AF-0123456789" ,
155+ } ) ;
156+ expect ( result . items [ 0 ] ) . not . toHaveProperty ( "wallet" ) ;
157+
158+ for ( const productId of [ "workspace_vm" , "unrelated_product" ] ) {
159+ billing . referralRequest . mockResolvedValueOnce (
160+ envelope ( { total : 1 , items : [ { ...providerOffer , productId } ] } ) ,
161+ ) ;
162+ await expect ( callReferralProvider ( billing , scope , dashboardUrl , "offers" ) ) . rejects . toMatchObject ( {
163+ code : "AFFILIATE_PROVIDER_RESPONSE_INVALID" ,
164+ } ) ;
165+ }
166+ } ) ;
167+
168+ it ( "keeps referred customers visible after the provider product rename" , async ( ) => {
169+ const billing = {
170+ referralRequest : async ( ) =>
114171 envelope ( {
115- id,
116- code : "AF-0123456789" ,
117- url : "https://evil.test" ,
118- name : "Share" ,
119- productId : "workspace_vm" ,
120- planId : null ,
121- commissionBps : 2000 ,
122- discountBps : 500 ,
123- durationMonths : 12 ,
124- status : "active" ,
125- createdAt : new Date ( ) . toISOString ( ) ,
126- expiresAt : null ,
127- revokedAt : null ,
128- user_id : "provider-secret" ,
129- participant_key : "private" ,
130- wallet : 1000000 ,
172+ total : 1 ,
173+ items : [ {
174+ id,
175+ offerId : id ,
176+ customer : "Customer" ,
177+ productId : "vm_compute" ,
178+ planId : null ,
179+ status : "active" ,
180+ paidThrough : null ,
181+ autoRenew : true ,
182+ nextRenewalAt : null ,
183+ joinedAt : "2026-11-19T00:00:00.000Z" ,
184+ rewardsUntil : null ,
185+ lastPaymentAt : null ,
186+ paidCycles : 1 ,
187+ earned : 200 ,
188+ currency : "usd" ,
189+ } ] ,
131190 } ) ,
132- ) ,
133191 } ;
134- const result = await callReferralProvider (
135- billing ,
136- scope ,
137- "https://app.openship.test" ,
138- "createOffer" ,
139- { policyId : id , name : "Share" , discountBps : 500 , idempotencyKey : "1234567890123456" } ,
140- ) ;
141- expect ( result . url ) . toBe ( "https://app.openship.test/r/AF-0123456789" ) ;
142- expect ( result ) . not . toHaveProperty ( "user_id" ) ;
143- expect ( result ) . not . toHaveProperty ( "wallet" ) ;
144- expect ( result ) . not . toHaveProperty ( "participant_key" ) ;
192+ const result = await callReferralProvider ( billing , scope , dashboardUrl , "referrals" ) ;
193+ expect ( result . items ) . toMatchObject ( [ { productId : "vm_compute" , earned : 200 } ] ) ;
145194 } ) ;
195+
146196 it ( "fails closed on incomplete monetary totals" , async ( ) => {
147197 await expect (
148198 callReferralProvider (
0 commit comments