@@ -24,7 +24,10 @@ import {
2424 MOCK_UNBLOCK_CODE ,
2525 MOCK_UNWRAP_BKEY ,
2626 MOCK_UNWRAP_BKEY_V2 ,
27+ MOCK_CLIENT_ID ,
28+ MOCK_REDIRECT_URI ,
2729 mockLoadingSpinnerModule ,
30+ MOCK_SERVICE ,
2831} from '../../mocks' ;
2932import {
3033 mockGqlBeginSigninMutation ,
@@ -45,6 +48,11 @@ import {
4548} from './mocks' ;
4649import { BeginSigninResult , SigninUnblockIntegration } from '../interfaces' ;
4750import { tryFinalizeUpgrade } from '../../../lib/gql-key-stretch-upgrade' ;
51+ import { mockUseFxAStatus } from '../../../lib/hooks/useFxAStatus/mocks' ;
52+ import { ensureCanLinkAcountOrRedirect } from '../utils' ;
53+ import { IntegrationType , OAuthIntegrationData } from '../../../models' ;
54+ import { GenericData } from '../../../lib/model-data' ;
55+ import { Constants } from '../../../lib/constants' ;
4856
4957let integration : SigninUnblockIntegration ;
5058function mockWebIntegration ( ) {
@@ -55,6 +63,28 @@ function mockWebIntegration() {
5563 } ;
5664}
5765
66+ function mockOAuthNativeIntegration ( ) {
67+ integration = {
68+ ...createMockSigninWebSyncIntegration ( ) ,
69+ type : IntegrationType . OAuthNative ,
70+ data : new OAuthIntegrationData (
71+ new GenericData ( {
72+ context : Constants . OAUTH_WEBCHANNEL_CONTEXT ,
73+ client_id : MOCK_CLIENT_ID ,
74+ state : 'mock_state' ,
75+ } )
76+ ) ,
77+ clientInfo : {
78+ clientId : MOCK_CLIENT_ID ,
79+ redirectUri : MOCK_REDIRECT_URI ,
80+ imageUri : undefined ,
81+ serviceName : MOCK_SERVICE ,
82+ trusted : true ,
83+ } ,
84+ isFirefoxMobileClient : ( ) => false ,
85+ } as SigninUnblockIntegration ;
86+ }
87+
5888let flowQueryParams : QueryParams ;
5989function mockQueryFlowParameters ( ) {
6090 flowQueryParams = {
@@ -78,6 +108,11 @@ jest.mock('../../../lib/gql-key-stretch-upgrade', () => {
78108 } ;
79109} ) ;
80110
111+ jest . mock ( '../utils' , ( ) => ( {
112+ ...jest . requireActual ( '../utils' ) ,
113+ ensureCanLinkAcountOrRedirect : jest . fn ( ) ,
114+ } ) ) ;
115+
81116jest . mock ( '../../../models' , ( ) => {
82117 return {
83118 ...jest . requireActual ( '../../../models' ) ,
@@ -139,7 +174,13 @@ describe('signin unblock container', () => {
139174 } ) ;
140175
141176 /** Renders the container with a fake page component */
142- async function render ( mocks : Array < MockedResponse > ) {
177+ async function render (
178+ mocks : Array < MockedResponse > ,
179+ options ?: { useFxAStatusResult ?: ReturnType < typeof mockUseFxAStatus > }
180+ ) {
181+ const useFxAStatusResult =
182+ options ?. useFxAStatusResult || mockUseFxAStatus ( ) ;
183+
143184 renderWithLocalizationProvider (
144185 < MockedProvider mocks = { mocks } addTypename = { false } >
145186 < LocationProvider >
@@ -148,6 +189,7 @@ describe('signin unblock container', () => {
148189 integration,
149190 serviceName : MozServices . Default ,
150191 flowQueryParams,
192+ useFxAStatusResult,
151193 } }
152194 />
153195 </ LocationProvider >
@@ -185,6 +227,8 @@ describe('signin unblock container', () => {
185227 expect ( result ?. data ?. signIn ?. emailVerified ) . toBeDefined ( ) ;
186228 expect ( result ?. data ?. signIn ?. sessionVerified ) . toBeDefined ( ) ;
187229 expect ( result ?. data ?. signIn ?. metricsEnabled ) . toBeDefined ( ) ;
230+ // Should NOT call ensureCanLinkAcountOrRedirect for non-OAuthNative integration
231+ expect ( ensureCanLinkAcountOrRedirect ) . not . toHaveBeenCalled ( ) ;
188232 } ) ;
189233
190234 it ( 'handles signin with with key stretching upgrade' , async ( ) => {
@@ -295,4 +339,53 @@ describe('signin unblock container', () => {
295339 expect ( result ?. error ) . toBeDefined ( ) ;
296340 expect ( result ?. error ?. errno ) . toEqual ( 127 ) ;
297341 } ) ;
342+
343+ describe ( 'with supportsCanLinkAccountUid capability and OAuthNative integration' , ( ) => {
344+ beforeEach ( ( ) => {
345+ mockOAuthNativeIntegration ( ) ;
346+ ( ensureCanLinkAcountOrRedirect as jest . Mock ) . mockResolvedValue ( true ) ;
347+ } ) ;
348+
349+ afterEach ( ( ) => {
350+ ( ensureCanLinkAcountOrRedirect as jest . Mock ) . mockRestore ( ) ;
351+ } ) ;
352+
353+ it ( 'calls ensureCanLinkAcountOrRedirect with UID after successful signin' , async ( ) => {
354+ const useFxAStatusResult = mockUseFxAStatus ( {
355+ supportsCanLinkAccountUid : true ,
356+ } ) ;
357+
358+ await render (
359+ [
360+ mockGqlCredentialStatusMutation ( ) ,
361+ mockGqlBeginSigninMutation (
362+ {
363+ unblockCode : MOCK_UNBLOCK_CODE ,
364+ keys : true ,
365+ } ,
366+ {
367+ authPW : MOCK_AUTH_PW_V2 ,
368+ }
369+ ) ,
370+ ] ,
371+ { useFxAStatusResult }
372+ ) ;
373+
374+ let result : BeginSigninResult | undefined ;
375+ await act ( async ( ) => {
376+ result =
377+ await currentPageProps ?. signinWithUnblockCode ( MOCK_UNBLOCK_CODE ) ;
378+ } ) ;
379+
380+ expect ( result ) . toBeDefined ( ) ;
381+ expect ( result ?. data ) . toBeDefined ( ) ;
382+ expect ( ensureCanLinkAcountOrRedirect ) . toHaveBeenCalledTimes ( 1 ) ;
383+ expect ( ensureCanLinkAcountOrRedirect ) . toHaveBeenCalledWith (
384+ expect . objectContaining ( {
385+ email : MOCK_EMAIL ,
386+ uid : expect . any ( String ) ,
387+ } )
388+ ) ;
389+ } ) ;
390+ } ) ;
298391} ) ;
0 commit comments