@@ -10,6 +10,8 @@ import { MfaGuard } from './index';
1010import { JwtTokenCache , MfaOtpRequestCache } from '../../../lib/cache' ;
1111import { AuthUiErrors } from '../../../lib/auth-errors/auth-errors' ;
1212import { AppContext } from '../../../models' ;
13+ import { MfaReason } from '../../../lib/types' ;
14+ import GleanMetrics from '../../../lib/glean' ;
1315
1416const mockSessionToken = 'session-xyz' ;
1517const mockOtp = '123456' ;
@@ -64,7 +66,7 @@ describe('MfaGuard', () => {
6466 it ( 'requests OTP and shows modal when JWT missing' , async ( ) => {
6567 renderWithRouter (
6668 < AppContext . Provider value = { mockAppContext ( ) } >
67- < MfaGuard requiredScope = { mockScope } >
69+ < MfaGuard requiredScope = { mockScope } reason = { MfaReason . test } >
6870 < div > secured</ div >
6971 </ MfaGuard >
7072 </ AppContext . Provider >
@@ -88,12 +90,32 @@ describe('MfaGuard', () => {
8890 ) ;
8991 } ) ;
9092
93+ it ( 'emits metrics on success' , async ( ) => {
94+ const submitSuccessSpy = jest . spyOn (
95+ GleanMetrics . accountPref ,
96+ 'mfaGuardSubmitSuccess'
97+ ) ;
98+ renderWithRouter (
99+ < AppContext . Provider value = { mockAppContext ( ) } >
100+ < MfaGuard requiredScope = { mockScope } reason = { MfaReason . test } >
101+ < div > secured</ div >
102+ </ MfaGuard >
103+ </ AppContext . Provider >
104+ ) ;
105+ await submitCode ( ) ;
106+ await waitFor ( ( ) => {
107+ expect ( submitSuccessSpy ) . toHaveBeenCalledWith ( {
108+ event : { reason : MfaReason . test } ,
109+ } ) ;
110+ } ) ;
111+ } ) ;
112+
91113 it ( 'renders children when JWT exists' , ( ) => {
92114 JwtTokenCache . setToken ( mockSessionToken , mockScope , 'jwt-present' ) ;
93115
94116 renderWithRouter (
95117 < AppContext . Provider value = { mockAppContext ( ) } >
96- < MfaGuard requiredScope = { mockScope } >
118+ < MfaGuard requiredScope = { mockScope } reason = { MfaReason . test } >
97119 < div > secured</ div >
98120 </ MfaGuard >
99121 </ AppContext . Provider >
@@ -117,7 +139,7 @@ describe('MfaGuard', () => {
117139
118140 renderWithRouter (
119141 < AppContext . Provider value = { mockAppContext ( ) } >
120- < MfaGuard requiredScope = { mockScope } >
142+ < MfaGuard requiredScope = { mockScope } reason = { MfaReason . test } >
121143 < div > secured</ div >
122144 </ MfaGuard >
123145 </ AppContext . Provider >
@@ -132,7 +154,7 @@ describe('MfaGuard', () => {
132154 it ( 'shows error banner on invalid OTP' , async ( ) => {
133155 renderWithRouter (
134156 < AppContext . Provider value = { mockAppContext ( ) } >
135- < MfaGuard requiredScope = { mockScope } >
157+ < MfaGuard requiredScope = { mockScope } reason = { MfaReason . test } >
136158 < div > secured</ div >
137159 </ MfaGuard >
138160 </ AppContext . Provider >
@@ -149,7 +171,11 @@ describe('MfaGuard', () => {
149171 it ( 'clears error banner on input change' , async ( ) => {
150172 renderWithRouter (
151173 < AppContext . Provider value = { mockAppContext ( ) } >
152- < MfaGuard requiredScope = { mockScope } debounceIntervalMs = { 0 } >
174+ < MfaGuard
175+ requiredScope = { mockScope }
176+ debounceIntervalMs = { 0 }
177+ reason = { MfaReason . test }
178+ >
153179 < div > secured</ div >
154180 </ MfaGuard >
155181 </ AppContext . Provider >
@@ -171,7 +197,11 @@ describe('MfaGuard', () => {
171197 it ( 'shows resend success banner and hides error banner on resend success' , async ( ) => {
172198 renderWithRouter (
173199 < AppContext . Provider value = { mockAppContext ( ) } >
174- < MfaGuard requiredScope = { mockScope } debounceIntervalMs = { 0 } >
200+ < MfaGuard
201+ requiredScope = { mockScope }
202+ debounceIntervalMs = { 0 }
203+ reason = { MfaReason . test }
204+ >
175205 < div > secured</ div >
176206 </ MfaGuard >
177207 </ AppContext . Provider >
@@ -201,7 +231,11 @@ describe('MfaGuard', () => {
201231 it ( 'shows error banner and hide success banner on resend error' , async ( ) => {
202232 renderWithRouter (
203233 < AppContext . Provider value = { mockAppContext ( ) } >
204- < MfaGuard requiredScope = { mockScope } debounceIntervalMs = { 0 } >
234+ < MfaGuard
235+ requiredScope = { mockScope }
236+ debounceIntervalMs = { 0 }
237+ reason = { MfaReason . test }
238+ >
205239 < div > secured</ div >
206240 </ MfaGuard >
207241 </ AppContext . Provider >
@@ -231,7 +265,11 @@ describe('MfaGuard', () => {
231265
232266 renderWithRouter (
233267 < AppContext . Provider value = { mockAppContext ( ) } >
234- < MfaGuard requiredScope = { mockScope } debounceIntervalMs = { 0 } >
268+ < MfaGuard
269+ requiredScope = { mockScope }
270+ debounceIntervalMs = { 0 }
271+ reason = { MfaReason . test }
272+ >
235273 < div > secured</ div >
236274 </ MfaGuard >
237275 </ AppContext . Provider >
@@ -252,6 +290,7 @@ describe('MfaGuard', () => {
252290 requiredScope = { mockScope }
253291 onDismissCallback = { mockOnDismiss }
254292 debounceIntervalMs = { 0 }
293+ reason = { MfaReason . test }
255294 >
256295 < div > secured</ div >
257296 </ MfaGuard >
@@ -266,7 +305,11 @@ describe('MfaGuard', () => {
266305 it ( 'debounces OTP resend requests' , async ( ) => {
267306 renderWithRouter (
268307 < AppContext . Provider value = { mockAppContext ( ) } >
269- < MfaGuard requiredScope = { mockScope } debounceIntervalMs = { 100 } >
308+ < MfaGuard
309+ requiredScope = { mockScope }
310+ debounceIntervalMs = { 100 }
311+ reason = { MfaReason . test }
312+ >
270313 < div > secured</ div >
271314 </ MfaGuard >
272315 </ AppContext . Provider >
0 commit comments