@@ -14,6 +14,7 @@ import {
1414import {
1515 SponsoredAccountStep ,
1616 SponsoredHeldCredentials ,
17+ trackedSponsoredCredentials ,
1718} from '../sponsored-account-step'
1819
1920import type {
@@ -192,6 +193,68 @@ describe('a tracked signup link', () => {
192193 } )
193194} )
194195
196+ describe ( 'a key page link with a {bfcid} slot (COD-965)' , ( ) => {
197+ const TOKEN = 'bfc_1.p.s'
198+ const declared = [
199+ {
200+ env : 'ACME_API_KEY' ,
201+ label : 'Acme API key' ,
202+ getUrl : 'https://acme.example/keys?bfcid={bfcid}' ,
203+ } ,
204+ {
205+ env : 'ACME_ORG' ,
206+ label : 'Acme org id' ,
207+ getUrl : 'https://acme.example/org' ,
208+ } ,
209+ ]
210+
211+ test ( 'takes the signed click id, and the form shows that link' , async ( ) => {
212+ const credentials = trackedSponsoredCredentials ( declared , {
213+ advertiserLink : `https://acme.example/?bfcid=${ TOKEN } ` ,
214+ } )
215+ expect ( credentials ) . toEqual ( [
216+ { ...declared [ 0 ] ! , getUrl : `https://acme.example/keys?bfcid=${ TOKEN } ` } ,
217+ declared [ 1 ] ! ,
218+ ] )
219+ const h = harness ( { credentials } )
220+ void h . step . request ( new AbortController ( ) . signal )
221+ await Promise . resolve ( )
222+ const ask = h . step . asking
223+ expect ( ask ?. kind ) . toBe ( 'credentials' )
224+ if ( ask ?. kind !== 'credentials' ) return
225+ expect ( ask . credentials [ 0 ] ! . getUrl ) . toBe (
226+ `https://acme.example/keys?bfcid=${ TOKEN } ` ,
227+ )
228+ } )
229+
230+ test ( 'without a signed click id the link is dropped, never shown with the slot' , ( ) => {
231+ for ( const advertiserLink of [ null , 'https://acme.example/' , undefined ] ) {
232+ const credentials = trackedSponsoredCredentials ( declared , {
233+ advertiserLink : advertiserLink as string | null ,
234+ } )
235+ expect ( credentials ) . toEqual ( [
236+ { env : 'ACME_API_KEY' , label : 'Acme API key' } ,
237+ declared [ 1 ] ! ,
238+ ] )
239+ expect ( JSON . stringify ( credentials ) ) . not . toContain ( 'bfcid}' )
240+ }
241+ } )
242+
243+ test ( 'an encoded slot is filled too, and an {email} slot is removed' , ( ) => {
244+ const [ credential ] = trackedSponsoredCredentials (
245+ [
246+ {
247+ env : 'ACME_API_KEY' ,
248+ label : 'Acme API key' ,
249+ getUrl : 'https://acme.example/keys?bfcid=%7Bbfcid%7D&email={email}' ,
250+ } ,
251+ ] ,
252+ { advertiserLink : `https://acme.example/?bfcid=${ TOKEN } ` } ,
253+ )
254+ expect ( credential ! . getUrl ) . toBe ( `https://acme.example/keys?bfcid=${ TOKEN } ` )
255+ } )
256+ } )
257+
195258test ( 'no account step answers unavailable' , async ( ) => {
196259 const h = harness ( { credentials : [ ] } )
197260 expect ( await h . step . request ( new AbortController ( ) . signal ) ) . toEqual ( {
0 commit comments