@@ -73,4 +73,150 @@ describe('SamlConnectionAPI', () => {
73
73
expect ( response . totalCount ) . toBe ( 1 ) ;
74
74
} ) ;
75
75
} ) ;
76
+
77
+ describe ( 'createSamlConnection' , ( ) => {
78
+ it ( 'successfully creates a SAML connection' , async ( ) => {
79
+ const mockSamlConnectionResponse = {
80
+ object : 'saml_connection' ,
81
+ id : 'samlc_123' ,
82
+ name : 'Test Connection' ,
83
+ provider : 'saml_custom' ,
84
+ domain : 'test.example.com' ,
85
+ organization_id : 'org_123' ,
86
+ created_at : 1672531200000 ,
87
+ updated_at : 1672531200000 ,
88
+ active : true ,
89
+ sync_user_attributes : false ,
90
+ allow_subdomains : false ,
91
+ allow_idp_initiated : false ,
92
+ idp_entity_id : 'entity_123' ,
93
+ idp_sso_url : 'https://idp.example.com/sso' ,
94
+ idp_certificate : 'cert_data' ,
95
+ idp_metadata_url : null ,
96
+ idp_metadata : null ,
97
+ attribute_mapping : {
98
+ user_id : 'userId' ,
99
+ email_address : 'email' ,
100
+ first_name : 'firstName' ,
101
+ last_name : 'lastName' ,
102
+ } ,
103
+ } ;
104
+
105
+ server . use (
106
+ http . post (
107
+ 'https://api.clerk.test/v1/saml_connections' ,
108
+ validateHeaders ( async ( { request } ) => {
109
+ const body = await request . json ( ) ;
110
+
111
+ console . log ( body ) ;
112
+ expect ( body ) . toEqual ( {
113
+ name : 'Test Connection' ,
114
+ provider : 'saml_custom' ,
115
+ domain : 'test.example.com' ,
116
+ attribute_mapping : {
117
+ user_id : 'userId' ,
118
+ email_address : 'email' ,
119
+ first_name : 'firstName' ,
120
+ last_name : 'lastName' ,
121
+ } ,
122
+ } ) ;
123
+ return HttpResponse . json ( mockSamlConnectionResponse ) ;
124
+ } ) ,
125
+ ) ,
126
+ ) ;
127
+
128
+ const response = await apiClient . samlConnections . createSamlConnection ( {
129
+ name : 'Test Connection' ,
130
+ provider : 'saml_custom' ,
131
+ domain : 'test.example.com' ,
132
+ attributeMapping : {
133
+ user_id : 'userId' ,
134
+ email_address : 'email' ,
135
+ first_name : 'firstName' ,
136
+ last_name : 'lastName' ,
137
+ } ,
138
+ } ) ;
139
+
140
+ expect ( response . id ) . toBe ( 'samlc_123' ) ;
141
+ expect ( response . name ) . toBe ( 'Test Connection' ) ;
142
+ expect ( response . organizationId ) . toBe ( 'org_123' ) ;
143
+ } ) ;
144
+ } ) ;
145
+
146
+ describe ( 'updateSamlConnection' , ( ) => {
147
+ it ( 'successfully updates a SAML connection' , async ( ) => {
148
+ const mockSamlConnectionResponse = {
149
+ object : 'saml_connection' ,
150
+ id : 'samlc_123' ,
151
+ name : 'Test Connection' ,
152
+ provider : 'saml_custom' ,
153
+ domain : 'test.example.com' ,
154
+ organization_id : 'org_123' ,
155
+ created_at : 1672531200000 ,
156
+ updated_at : 1672531200000 ,
157
+ active : true ,
158
+ sync_user_attributes : false ,
159
+ allow_subdomains : false ,
160
+ allow_idp_initiated : false ,
161
+ idp_entity_id : 'entity_123' ,
162
+ idp_sso_url : 'https://idp.example.com/sso' ,
163
+ idp_certificate : 'cert_data' ,
164
+ idp_metadata_url : null ,
165
+ idp_metadata : null ,
166
+ attribute_mapping : {
167
+ user_id : 'userId' ,
168
+ email_address : 'email' ,
169
+ first_name : 'firstName' ,
170
+ last_name : 'lastName' ,
171
+ } ,
172
+ } ;
173
+
174
+ server . use (
175
+ http . patch (
176
+ 'https://api.clerk.test/v1/saml_connections/samlc_123' ,
177
+ validateHeaders ( async ( { request } ) => {
178
+ const body = await request . json ( ) ;
179
+
180
+ console . log ( body ) ;
181
+ expect ( body ) . toEqual ( {
182
+ name : 'Test Connection' ,
183
+ provider : 'saml_custom' ,
184
+ domain : 'test.example.com' ,
185
+ organization_id : 'org_123' ,
186
+ idp_entity_id : 'entity_123' ,
187
+ idp_sso_url : 'https://idp.example.com/sso' ,
188
+ idp_certificate : 'cert_data' ,
189
+ attribute_mapping : {
190
+ user_id : 'userId' ,
191
+ email_address : 'email' ,
192
+ first_name : 'firstName' ,
193
+ last_name : 'lastName' ,
194
+ } ,
195
+ } ) ;
196
+ return HttpResponse . json ( mockSamlConnectionResponse ) ;
197
+ } ) ,
198
+ ) ,
199
+ ) ;
200
+
201
+ const response = await apiClient . samlConnections . updateSamlConnection ( 'samlc_123' , {
202
+ name : 'Test Connection' ,
203
+ provider : 'saml_custom' ,
204
+ domain : 'test.example.com' ,
205
+ organizationId : 'org_123' ,
206
+ idpEntityId : 'entity_123' ,
207
+ idpSsoUrl : 'https://idp.example.com/sso' ,
208
+ idpCertificate : 'cert_data' ,
209
+ attributeMapping : {
210
+ user_id : 'userId' ,
211
+ email_address : 'email' ,
212
+ first_name : 'firstName' ,
213
+ last_name : 'lastName' ,
214
+ } ,
215
+ } ) ;
216
+
217
+ expect ( response . id ) . toBe ( 'samlc_123' ) ;
218
+ expect ( response . name ) . toBe ( 'Test Connection' ) ;
219
+ expect ( response . organizationId ) . toBe ( 'org_123' ) ;
220
+ } ) ;
221
+ } ) ;
76
222
} ) ;
0 commit comments