@@ -16,6 +16,7 @@ import * as accountPref from 'fxa-shared/metrics/glean/web/accountPref';
1616import * as accountBanner from 'fxa-shared/metrics/glean/web/accountBanner' ;
1717import * as deleteAccount from 'fxa-shared/metrics/glean/web/deleteAccount' ;
1818import * as thirdPartyAuth from 'fxa-shared/metrics/glean/web/thirdPartyAuth' ;
19+ import * as thirdPartyAuthSetPassword from 'fxa-shared/metrics/glean/web/thirdPartyAuthSetPassword' ;
1920import { userIdSha256 , userId } from 'fxa-shared/metrics/glean/web/account' ;
2021import {
2122 oauthClientId ,
@@ -687,6 +688,45 @@ describe('lib/glean', () => {
687688 } ) ;
688689 } ) ;
689690
691+ describe ( 'thirdPartyAuthSetPassword' , ( ) => {
692+ // Each event is recorded with a `reason` extra key that distinguishes
693+ // OTP/passwordless flows ('otp') from third-party auth flows
694+ // ('third_party_auth'). Both values are asserted below so the bridge
695+ // between GleanMetrics and the generated event metric stays in sync.
696+ const cases : Array < {
697+ method : 'view' | 'engage' | 'submit' | 'success' ;
698+ eventName : string ;
699+ } > = [
700+ { method : 'view' , eventName : 'third_party_auth_set_password_view' } ,
701+ { method : 'engage' , eventName : 'third_party_auth_set_password_engage' } ,
702+ { method : 'submit' , eventName : 'third_party_auth_set_password_submit' } ,
703+ {
704+ method : 'success' ,
705+ eventName : 'third_party_auth_set_password_success' ,
706+ } ,
707+ ] ;
708+
709+ for ( const { method, eventName } of cases ) {
710+ for ( const reason of [ 'otp' , 'third_party_auth' ] as const ) {
711+ it ( `submits ${ eventName } with reason='${ reason } '` , async ( ) => {
712+ const spy = sandbox . spy (
713+ thirdPartyAuthSetPassword [ method ] ,
714+ 'record'
715+ ) ;
716+ GleanMetrics . thirdPartyAuthSetPassword [ method ] ( {
717+ event : { reason } ,
718+ } ) ;
719+ await GleanMetrics . isDone ( ) ;
720+ sinon . assert . calledOnce ( setEventNameStub ) ;
721+ sinon . assert . calledWith ( setEventNameStub , eventName ) ;
722+ sinon . assert . calledOnce ( setEventReasonStub ) ;
723+ sinon . assert . calledWith ( setEventReasonStub , reason ) ;
724+ sinon . assert . calledWith ( spy , { reason } ) ;
725+ } ) ;
726+ }
727+ }
728+ } ) ;
729+
690730 describe ( 'accountPref' , ( ) => {
691731 it ( 'submits a ping with the account_pref_view event name' , async ( ) => {
692732 GleanMetrics . accountPref . view ( ) ;
@@ -793,16 +833,30 @@ describe('lib/glean', () => {
793833 sinon . assert . called ( spy ) ;
794834 } ) ;
795835
796- it ( 'submits a ping with the account_pref_change_password_submit event name' , async ( ) => {
797- GleanMetrics . accountPref . changePasswordSubmit ( ) ;
836+ it ( 'submits a ping with the account_pref_change_password_submit event name and forwards reason' , async ( ) => {
798837 const spy = sandbox . spy ( accountPref . changePasswordSubmit , 'record' ) ;
838+ GleanMetrics . accountPref . changePasswordSubmit ( {
839+ event : { reason : 'change' } ,
840+ } ) ;
799841 await GleanMetrics . isDone ( ) ;
800842 sinon . assert . calledOnce ( setEventNameStub ) ;
801843 sinon . assert . calledWith (
802844 setEventNameStub ,
803845 'account_pref_change_password_submit'
804846 ) ;
805- sinon . assert . called ( spy ) ;
847+ sinon . assert . calledOnce ( setEventReasonStub ) ;
848+ sinon . assert . calledWith ( setEventReasonStub , 'change' ) ;
849+ sinon . assert . calledWith ( spy , { reason : 'change' } ) ;
850+ } ) ;
851+
852+ it ( 'forwards reason="create" to account_pref_change_password_submit' , async ( ) => {
853+ const spy = sandbox . spy ( accountPref . changePasswordSubmit , 'record' ) ;
854+ GleanMetrics . accountPref . changePasswordSubmit ( {
855+ event : { reason : 'create' } ,
856+ } ) ;
857+ await GleanMetrics . isDone ( ) ;
858+ sinon . assert . calledWith ( setEventReasonStub , 'create' ) ;
859+ sinon . assert . calledWith ( spy , { reason : 'create' } ) ;
806860 } ) ;
807861
808862 it ( 'submits a ping with the account_pref_device_signout event name' , async ( ) => {
0 commit comments