1- import qs from 'qs' ;
21import { mocked } from 'ts-jest/utils' ;
32
43import { MY_ACCOUNT_DOMAINS } from '../../server-paths' ;
54import { MtLinkSdk } from '../..' ;
65import authorize from '../authorize' ;
76import { generateConfigs } from '../../helper' ;
87import storage from '../../storage' ;
8+ import expectUrlToMatchWithPKCE from '../../__tests__/helper/expect-url-to-match' ;
99
1010jest . mock ( '../../storage' ) ;
1111
@@ -57,8 +57,9 @@ describe('api', () => {
5757 authorize ( mtLinkSdk . storedOptions ) ;
5858
5959 expect ( open ) . toBeCalledTimes ( 1 ) ;
60-
61- const query = qs . stringify ( {
60+ expect ( open ) . toBeCalledWith ( expect . any ( String ) , '_self' , 'noreferrer' ) ;
61+ const url = open . mock . calls [ 0 ] [ 0 ]
62+ const query = {
6263 client_id : clientId ,
6364 cobrand_client_id : cobrandClientId ,
6465 response_type : 'code' ,
@@ -68,9 +69,8 @@ describe('api', () => {
6869 locale,
6970 saml_subject_id : samlSubjectId ,
7071 configs : generateConfigs ( )
71- } ) ;
72- const url = `${ MY_ACCOUNT_DOMAINS . production } /oauth/authorize?${ query } ` ;
73- expect ( open ) . toBeCalledWith ( url , '_self' , 'noreferrer' ) ;
72+ } ;
73+ expectUrlToMatchWithPKCE ( url , { baseUrl : MY_ACCOUNT_DOMAINS . production , path : '/oauth/authorize' , query } )
7474 } ) ;
7575
7676 test ( 'with options' , ( ) => {
@@ -92,8 +92,9 @@ describe('api', () => {
9292 } ) ;
9393
9494 expect ( open ) . toBeCalledTimes ( 1 ) ;
95-
96- const query = qs . stringify ( {
95+ expect ( open ) . toBeCalledWith ( expect . any ( String ) , '_self' , 'noreferrer' ) ;
96+ const url = open . mock . calls [ 0 ] [ 0 ]
97+ const query = {
9798 client_id : clientId ,
9899 response_type : 'code' ,
99100 scope : scopes ,
@@ -102,9 +103,8 @@ describe('api', () => {
102103 country,
103104 saml_subject_id : samlSubjectId ,
104105 configs : generateConfigs ( )
105- } ) ;
106- const url = `${ MY_ACCOUNT_DOMAINS . production } /oauth/authorize?${ query } ` ;
107- expect ( open ) . toBeCalledWith ( url , '_self' , 'noreferrer' ) ;
106+ } ;
107+ expectUrlToMatchWithPKCE ( url , { baseUrl : MY_ACCOUNT_DOMAINS . production , path : '/oauth/authorize' , query } )
108108 } ) ;
109109
110110 test ( 'without window' , ( ) => {
0 commit comments