@@ -42,6 +42,88 @@ describe('User', () => {
4242 } ) ;
4343 } ) ;
4444
45+ it ( 'creates an external account with enterprise connection id' , async ( ) => {
46+ const externalAccountJSON = {
47+ object : 'external_account' ,
48+ provider : 'saml_okta' ,
49+ verification : {
50+ external_verification_redirect_url : 'https://www.example.com' ,
51+ } ,
52+ } ;
53+
54+ // @ts -ignore
55+ BaseResource . _fetch = vi . fn ( ) . mockReturnValue ( Promise . resolve ( { response : externalAccountJSON } ) ) ;
56+
57+ const user = new User ( {
58+ email_addresses : [ ] ,
59+ phone_numbers : [ ] ,
60+ web3_wallets : [ ] ,
61+ external_accounts : [ ] ,
62+ } as unknown as UserJSON ) ;
63+
64+ await user . createExternalAccount ( {
65+ enterpriseConnectionId : 'ec_123' ,
66+ redirectUrl : 'https://www.example.com' ,
67+ } ) ;
68+
69+ // @ts -ignore
70+ expect ( BaseResource . _fetch ) . toHaveBeenCalledWith ( {
71+ method : 'POST' ,
72+ path : '/me/external_accounts' ,
73+ body : {
74+ strategy : undefined ,
75+ redirect_url : 'https://www.example.com' ,
76+ additional_scope : undefined ,
77+ enterprise_connection_id : 'ec_123' ,
78+ } ,
79+ } ) ;
80+ } ) ;
81+
82+ it ( 'fetches enterprise connections' , async ( ) => {
83+ const enterpriseConnectionsJSON = [
84+ {
85+ id : 'ec_123' ,
86+ object : 'enterprise_account_connection' ,
87+ name : 'Acme Corp SSO' ,
88+ active : true ,
89+ allow_organization_account_linking : true ,
90+ domain : 'acme.com' ,
91+ protocol : 'saml' ,
92+ provider : 'saml_okta' ,
93+ logo_public_url : null ,
94+ sync_user_attributes : true ,
95+ allow_subdomains : false ,
96+ allow_idp_initiated : false ,
97+ disable_additional_identifications : false ,
98+ enterprise_connection_id : 'ec_123' ,
99+ created_at : 1234567890 ,
100+ updated_at : 1234567890 ,
101+ } ,
102+ ] ;
103+
104+ // @ts -ignore
105+ BaseResource . _fetch = vi . fn ( ) . mockReturnValue ( Promise . resolve ( { response : enterpriseConnectionsJSON } ) ) ;
106+
107+ const user = new User ( {
108+ email_addresses : [ ] ,
109+ phone_numbers : [ ] ,
110+ web3_wallets : [ ] ,
111+ external_accounts : [ ] ,
112+ } as unknown as UserJSON ) ;
113+
114+ const connections = await user . getEnterpriseConnections ( ) ;
115+
116+ // @ts -ignore
117+ expect ( BaseResource . _fetch ) . toHaveBeenCalledWith ( {
118+ method : 'GET' ,
119+ path : '/me/enterprise_connections' ,
120+ } ) ;
121+
122+ expect ( connections ) . toHaveLength ( 1 ) ;
123+ expect ( connections [ 0 ] . name ) . toBe ( 'Acme Corp SSO' ) ;
124+ expect ( connections [ 0 ] . allowOrganizationAccountLinking ) . toBe ( true ) ;
125+ } ) ;
126+
45127 it ( 'creates a web3 wallet' , async ( ) => {
46128 const targetWeb3Wallet = '0x0000000000000000000000000000000000000000' ;
47129 const web3WalletJSON = {
0 commit comments