@@ -10,36 +10,36 @@ describe('SamlConnectionAPI', () => {
1010 secretKey : 'deadbeef' ,
1111 } ) ;
1212
13+ const mockSamlConnectionResponse = {
14+ object : 'saml_connection' ,
15+ id : 'samlc_123' ,
16+ name : 'Test Connection' ,
17+ provider : 'saml_custom' ,
18+ domain : 'test.example.com' ,
19+ organization_id : 'org_123' ,
20+ created_at : 1672531200000 ,
21+ updated_at : 1672531200000 ,
22+ active : true ,
23+ sync_user_attributes : false ,
24+ allow_subdomains : false ,
25+ allow_idp_initiated : false ,
26+ idp_entity_id : 'entity_123' ,
27+ idp_sso_url : 'https://idp.example.com/sso' ,
28+ idp_certificate : 'cert_data' ,
29+ idp_metadata_url : null ,
30+ idp_metadata : null ,
31+ attribute_mapping : {
32+ user_id : 'userId' ,
33+ email_address : 'email' ,
34+ first_name : 'firstName' ,
35+ last_name : 'lastName' ,
36+ } ,
37+ } ;
38+
1339 describe ( 'getSamlConnectionList' , ( ) => {
1440 it ( 'successfully fetches SAML connections with all parameters' , async ( ) => {
1541 const mockSamlConnectionsResponse = {
16- data : [
17- {
18- object : 'saml_connection' ,
19- id : 'samlc_123' ,
20- name : 'Test Connection' ,
21- provider : 'saml_custom' ,
22- domain : 'test.example.com' ,
23- organization_id : 'org_123' ,
24- created_at : 1672531200000 ,
25- updated_at : 1672531200000 ,
26- active : true ,
27- sync_user_attributes : false ,
28- allow_subdomains : false ,
29- allow_idp_initiated : false ,
30- idp_entity_id : 'entity_123' ,
31- idp_sso_url : 'https://idp.example.com/sso' ,
32- idp_certificate : 'cert_data' ,
33- idp_metadata_url : null ,
34- idp_metadata : null ,
35- attribute_mapping : {
36- user_id : 'userId' ,
37- email_address : 'email' ,
38- first_name : 'firstName' ,
39- last_name : 'lastName' ,
40- } ,
41- } ,
42- ] ,
42+ data : [ mockSamlConnectionResponse ] ,
4343 total_count : 1 ,
4444 } ;
4545
@@ -73,4 +73,115 @@ describe('SamlConnectionAPI', () => {
7373 expect ( response . totalCount ) . toBe ( 1 ) ;
7474 } ) ;
7575 } ) ;
76+
77+ describe ( 'createSamlConnection' , ( ) => {
78+ it ( 'successfully creates a SAML connection' , async ( ) => {
79+ server . use (
80+ http . post (
81+ 'https://api.clerk.test/v1/saml_connections' ,
82+ validateHeaders ( async ( { request } ) => {
83+ const body = await request . json ( ) ;
84+
85+ expect ( body ) . toEqual ( {
86+ name : 'Test Connection' ,
87+ provider : 'saml_custom' ,
88+ domain : 'test.example.com' ,
89+ attribute_mapping : {
90+ user_id : 'userId' ,
91+ email_address : 'email' ,
92+ first_name : 'firstName' ,
93+ last_name : 'lastName' ,
94+ } ,
95+ } ) ;
96+
97+ return HttpResponse . json ( mockSamlConnectionResponse ) ;
98+ } ) ,
99+ ) ,
100+ ) ;
101+
102+ const response = await apiClient . samlConnections . createSamlConnection ( {
103+ name : 'Test Connection' ,
104+ provider : 'saml_custom' ,
105+ domain : 'test.example.com' ,
106+ attributeMapping : {
107+ userId : 'userId' ,
108+ emailAddress : 'email' ,
109+ firstName : 'firstName' ,
110+ lastName : 'lastName' ,
111+ } ,
112+ } ) ;
113+
114+ expect ( response . id ) . toBe ( 'samlc_123' ) ;
115+ expect ( response . name ) . toBe ( 'Test Connection' ) ;
116+ expect ( response . organizationId ) . toBe ( 'org_123' ) ;
117+ } ) ;
118+ } ) ;
119+
120+ describe ( 'updateSamlConnection' , ( ) => {
121+ it ( 'successfully updates a SAML connection' , async ( ) => {
122+ server . use (
123+ http . patch (
124+ 'https://api.clerk.test/v1/saml_connections/samlc_123' ,
125+ validateHeaders ( async ( { request } ) => {
126+ const body = await request . json ( ) ;
127+
128+ expect ( body ) . toEqual ( {
129+ name : 'Test Connection' ,
130+ provider : 'saml_custom' ,
131+ domain : 'test.example.com' ,
132+ organization_id : 'org_123' ,
133+ idp_entity_id : 'entity_123' ,
134+ idp_sso_url : 'https://idp.example.com/sso' ,
135+ idp_certificate : 'cert_data' ,
136+ attribute_mapping : {
137+ user_id : 'userId2' ,
138+ email_address : 'email2' ,
139+ first_name : 'firstName2' ,
140+ last_name : 'lastName2' ,
141+ } ,
142+ } ) ;
143+
144+ return HttpResponse . json ( {
145+ ...mockSamlConnectionResponse ,
146+ idp_entity_id : 'entity_123' ,
147+ idp_sso_url : 'https://idp.example.com/sso' ,
148+ idp_certificate : 'cert_data' ,
149+ attribute_mapping : {
150+ user_id : 'userId2' ,
151+ email_address : 'email2' ,
152+ first_name : 'firstName2' ,
153+ last_name : 'lastName2' ,
154+ } ,
155+ } ) ;
156+ } ) ,
157+ ) ,
158+ ) ;
159+
160+ const response = await apiClient . samlConnections . updateSamlConnection ( 'samlc_123' , {
161+ name : 'Test Connection' ,
162+ provider : 'saml_custom' ,
163+ domain : 'test.example.com' ,
164+ organizationId : 'org_123' ,
165+ idpEntityId : 'entity_123' ,
166+ idpSsoUrl : 'https://idp.example.com/sso' ,
167+ idpCertificate : 'cert_data' ,
168+ attributeMapping : {
169+ userId : 'userId2' ,
170+ emailAddress : 'email2' ,
171+ firstName : 'firstName2' ,
172+ lastName : 'lastName2' ,
173+ } ,
174+ } ) ;
175+
176+ expect ( response . id ) . toBe ( 'samlc_123' ) ;
177+ expect ( response . name ) . toBe ( 'Test Connection' ) ;
178+ expect ( response . organizationId ) . toBe ( 'org_123' ) ;
179+ expect ( response . attributeMapping ) . toEqual ( {
180+ userId : 'userId2' ,
181+ emailAddress : 'email2' ,
182+ firstName : 'firstName2' ,
183+ lastName : 'lastName2' ,
184+ } ) ;
185+ } ) ;
186+ } ) ;
76187} ) ;
0 commit comments