@@ -120,6 +120,16 @@ const multiTierSetup = async ({site, member = null}) => {
120120
121121const realLocation = window . location ;
122122
123+ // Helper function to verify OTC-enabled API calls
124+ const expectOTCEnabledSendMagicLinkAPICall = ( ghostApi , email ) => {
125+ expect ( ghostApi . member . sendMagicLink ) . toHaveBeenCalledWith ( {
126+ email,
127+ emailType : 'signin' ,
128+ integrityToken : 'testtoken' ,
129+ includeOTC : true
130+ } ) ;
131+ } ;
132+
123133describe ( 'Signin' , ( ) => {
124134 describe ( 'on single tier site' , ( ) => {
125135 beforeEach ( ( ) => {
@@ -140,6 +150,11 @@ describe('Signin', () => {
140150 site : FixtureSite . singleTier . basic
141151 } ) ;
142152
153+ // Mock sendMagicLink to return otc_ref for OTC flow
154+ ghostApi . member . sendMagicLink = vi . fn ( ( ) => {
155+ return Promise . resolve ( { success : true , otc_ref : 'test-otc-ref-123' } ) ;
156+ } ) ;
157+
143158 expect ( popupFrame ) . toBeInTheDocument ( ) ;
144159 expect ( triggerButtonFrame ) . toBeInTheDocument ( ) ;
145160 expect ( emailInput ) . toBeInTheDocument ( ) ;
@@ -152,41 +167,12 @@ describe('Signin', () => {
152167
153168 fireEvent . click ( submitButton ) ;
154169
155- const magicLink = await within ( popupIframeDocument ) . findByText ( / N o w c h e c k y o u r e m a i l / i) ;
156- expect ( magicLink ) . toBeInTheDocument ( ) ;
157-
158- expect ( ghostApi . member . sendMagicLink ) . toHaveBeenLastCalledWith ( {
159- email : 'jamie@example.com' ,
160- emailType : 'signin' ,
161- integrityToken : 'testtoken'
162- } ) ;
163- } ) ;
164-
165- test ( 'with OTC enabled' , async ( ) => {
166- const { ghostApi, emailInput, submitButton, popupIframeDocument} = await setup ( {
167- site : FixtureSite . singleTier . basic ,
168- labs : { membersSigninOTC : true }
169- } ) ;
170-
171- // Mock sendMagicLink to return otc_ref for OTC flow
172- ghostApi . member . sendMagicLink = vi . fn ( ( ) => {
173- return Promise . resolve ( { success : true , otc_ref : 'test-otc-ref-123' } ) ;
174- } ) ;
175-
176- fireEvent . change ( emailInput , { target : { value : 'jamie@example.com' } } ) ;
177- fireEvent . click ( submitButton ) ;
178-
179170 const magicLink = await within ( popupIframeDocument ) . findByText ( / N o w c h e c k y o u r e m a i l / i) ;
180171 expect ( magicLink ) . toBeInTheDocument ( ) ;
181172 const description = await within ( popupIframeDocument ) . findByText ( / A n e m a i l h a s b e e n s e n t t o j a m i e @ e x a m p l e .c o m / i) ;
182173 expect ( description ) . toBeInTheDocument ( ) ;
183174
184- expect ( ghostApi . member . sendMagicLink ) . toHaveBeenLastCalledWith ( {
185- email : 'jamie@example.com' ,
186- emailType : 'signin' ,
187- integrityToken : 'testtoken' ,
188- includeOTC : true
189- } ) ;
175+ expectOTCEnabledSendMagicLinkAPICall ( ghostApi , 'jamie@example.com' ) ;
190176 } ) ;
191177
192178 test ( 'without name field' , async ( ) => {
@@ -210,11 +196,7 @@ describe('Signin', () => {
210196 const magicLink = await within ( popupIframeDocument ) . findByText ( / N o w c h e c k y o u r e m a i l / i) ;
211197 expect ( magicLink ) . toBeInTheDocument ( ) ;
212198
213- expect ( ghostApi . member . sendMagicLink ) . toHaveBeenLastCalledWith ( {
214- email : 'jamie@example.com' ,
215- emailType : 'signin' ,
216- integrityToken : 'testtoken'
217- } ) ;
199+ expectOTCEnabledSendMagicLinkAPICall ( ghostApi , 'jamie@example.com' ) ;
218200 } ) ;
219201
220202 test ( 'with only free plan' , async ( ) => {
@@ -238,11 +220,7 @@ describe('Signin', () => {
238220 const magicLink = await within ( popupIframeDocument ) . findByText ( / N o w c h e c k y o u r e m a i l / i) ;
239221 expect ( magicLink ) . toBeInTheDocument ( ) ;
240222
241- expect ( ghostApi . member . sendMagicLink ) . toHaveBeenLastCalledWith ( {
242- email : 'jamie@example.com' ,
243- emailType : 'signin' ,
244- integrityToken : 'testtoken'
245- } ) ;
223+ expectOTCEnabledSendMagicLinkAPICall ( ghostApi , 'jamie@example.com' ) ;
246224 } ) ;
247225 } ) ;
248226} ) ;
@@ -282,11 +260,7 @@ describe('Signin', () => {
282260 const magicLink = await within ( popupIframeDocument ) . findByText ( / N o w c h e c k y o u r e m a i l / i) ;
283261 expect ( magicLink ) . toBeInTheDocument ( ) ;
284262
285- expect ( ghostApi . member . sendMagicLink ) . toHaveBeenLastCalledWith ( {
286- email : 'jamie@example.com' ,
287- emailType : 'signin' ,
288- integrityToken : 'testtoken'
289- } ) ;
263+ expectOTCEnabledSendMagicLinkAPICall ( ghostApi , 'jamie@example.com' ) ;
290264 } ) ;
291265
292266 test ( 'without name field' , async ( ) => {
@@ -310,11 +284,7 @@ describe('Signin', () => {
310284 const magicLink = await within ( popupIframeDocument ) . findByText ( / N o w c h e c k y o u r e m a i l / i) ;
311285 expect ( magicLink ) . toBeInTheDocument ( ) ;
312286
313- expect ( ghostApi . member . sendMagicLink ) . toHaveBeenLastCalledWith ( {
314- email : 'jamie@example.com' ,
315- emailType : 'signin' ,
316- integrityToken : 'testtoken'
317- } ) ;
287+ expectOTCEnabledSendMagicLinkAPICall ( ghostApi , 'jamie@example.com' ) ;
318288 } ) ;
319289
320290 test ( 'with only free plan available' , async ( ) => {
@@ -338,11 +308,7 @@ describe('Signin', () => {
338308 const magicLink = await within ( popupIframeDocument ) . findByText ( / N o w c h e c k y o u r e m a i l / i) ;
339309 expect ( magicLink ) . toBeInTheDocument ( ) ;
340310
341- expect ( ghostApi . member . sendMagicLink ) . toHaveBeenLastCalledWith ( {
342- email : 'jamie@example.com' ,
343- emailType : 'signin' ,
344- integrityToken : 'testtoken'
345- } ) ;
311+ expectOTCEnabledSendMagicLinkAPICall ( ghostApi , 'jamie@example.com' ) ;
346312 } ) ;
347313 } ) ;
348314
@@ -447,7 +413,7 @@ describe('OTC Integration Flow', () => {
447413 } ) ;
448414
449415 const utils = appRender (
450- < App api = { ghostApi } labs = { { membersSigninOTC : true } } />
416+ < App api = { ghostApi } labs = { { } } />
451417 ) ;
452418
453419 await utils . findByTitle ( / p o r t a l - t r i g g e r / i) ;
@@ -481,23 +447,14 @@ describe('OTC Integration Flow', () => {
481447 fireEvent . click ( verifyButton ) ;
482448 } ;
483449
484- const expectOTCEnabledApiCall = ( ghostApi , email ) => {
485- expect ( ghostApi . member . sendMagicLink ) . toHaveBeenCalledWith ( {
486- email,
487- emailType : 'signin' ,
488- integrityToken : 'testtoken' ,
489- includeOTC : true
490- } ) ;
491- } ;
492-
493450 test ( 'complete OTC flow from signin to verification' , async ( ) => {
494451 const { ghostApi, popupIframeDocument} = await setupOTCFlow ( {
495452 site : FixtureSite . singleTier . basic
496453 } ) ;
497454
498455 await submitSigninForm ( popupIframeDocument , 'jamie@example.com' ) ;
499456
500- expectOTCEnabledApiCall ( ghostApi , 'jamie@example.com' ) ;
457+ expectOTCEnabledSendMagicLinkAPICall ( ghostApi , 'jamie@example.com' ) ;
501458 expect ( ghostApi . member . sendMagicLink ) . toHaveBeenCalledTimes ( 1 ) ;
502459
503460 submitOTCForm ( popupIframeDocument , '123456' ) ;
@@ -524,7 +481,7 @@ describe('OTC Integration Flow', () => {
524481
525482 await submitSigninForm ( popupIframeDocument , 'jamie@example.com' ) ;
526483
527- expectOTCEnabledApiCall ( ghostApi , 'jamie@example.com' ) ;
484+ expectOTCEnabledSendMagicLinkAPICall ( ghostApi , 'jamie@example.com' ) ;
528485 expect ( ghostApi . member . sendMagicLink ) . toHaveBeenCalledTimes ( 1 ) ;
529486
530487 const otcInput = within ( popupIframeDocument ) . queryByLabelText ( OTC_LABEL_REGEX ) ;
@@ -541,7 +498,7 @@ describe('OTC Integration Flow', () => {
541498
542499 await submitSigninForm ( popupIframeDocument , 'jamie@example.com' ) ;
543500
544- expectOTCEnabledApiCall ( ghostApi , 'jamie@example.com' ) ;
501+ expectOTCEnabledSendMagicLinkAPICall ( ghostApi , 'jamie@example.com' ) ;
545502
546503 const otcInput = within ( popupIframeDocument ) . getByLabelText ( OTC_LABEL_REGEX ) ;
547504
0 commit comments