1
- # Copyright (c) 2024, FusionAuth, All Rights Reserved
1
+ # Copyright (c) 2024-2025 , FusionAuth, All Rights Reserved
2
2
#
3
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
4
# you may not use this file except in compliance with the License.
@@ -33,22 +33,22 @@ def test_application_crud
33
33
id = SecureRandom . uuid
34
34
client = FusionAuth ::FusionAuthClient . new ( @fusionauthApiKey , @fusionauthUrl )
35
35
response = client . create_application ( id , {
36
- :application => {
37
- :name => 'Test application' ,
38
- :roles => [
39
- {
40
- :isDefault => false ,
41
- :name => 'admin' ,
42
- :isSuperRole => true ,
43
- :description => 'Admin role'
44
- } ,
45
- {
46
- :isDefault => true ,
47
- :name => 'user' ,
48
- :description => 'User role'
49
- }
50
- ]
51
- }
36
+ :application => {
37
+ :name => 'Test application' ,
38
+ :roles => [
39
+ {
40
+ :isDefault => false ,
41
+ :name => 'admin' ,
42
+ :isSuperRole => true ,
43
+ :description => 'Admin role'
44
+ } ,
45
+ {
46
+ :isDefault => true ,
47
+ :name => 'user' ,
48
+ :description => 'User role'
49
+ }
50
+ ]
51
+ }
52
52
} )
53
53
handle_response ( response )
54
54
assert_equal 'Test application' , response . success_response . application . name
@@ -57,11 +57,11 @@ def test_application_crud
57
57
58
58
# Create a new role
59
59
role_response = client . create_application_role ( id , nil , {
60
- :role => {
61
- :isDefault => true ,
62
- :name => 'new role' ,
63
- :description => 'New role description'
64
- }
60
+ :role => {
61
+ :isDefault => true ,
62
+ :name => 'new role' ,
63
+ :description => 'New role description'
64
+ }
65
65
} )
66
66
handle_response ( role_response )
67
67
application_role = role_response . success_response
@@ -73,11 +73,11 @@ def test_application_crud
73
73
74
74
# Update the role
75
75
client . update_application_role ( id , application_role . role . id , {
76
- :role => {
77
- :isDefault => false ,
78
- :name => 'new role' ,
79
- :description => 'New role description'
80
- }
76
+ :role => {
77
+ :isDefault => false ,
78
+ :name => 'new role' ,
79
+ :description => 'New role description'
80
+ }
81
81
} )
82
82
handle_response ( response )
83
83
response = client . retrieve_application ( id )
@@ -123,17 +123,17 @@ def test_email_template_crud
123
123
124
124
# Create the email template
125
125
response = client . create_email_template ( id , {
126
- :emailTemplate => {
127
- :defaultFromName => 'Dude' ,
128
- :defaultHtmlTemplate => 'HTML Template' ,
129
- :defaultSubject => 'Subject' ,
130
- :defaultTextTemplate => 'Text Template' ,
131
- :fromEmail => '[email protected] ' ,
132
- :localizedFromNames => {
133
- :fr => 'From fr'
134
- } ,
135
- :name => 'Test Template'
136
- }
126
+ :emailTemplate => {
127
+ :defaultFromName => 'Dude' ,
128
+ :defaultHtmlTemplate => 'HTML Template' ,
129
+ :defaultSubject => 'Subject' ,
130
+ :defaultTextTemplate => 'Text Template' ,
131
+ :fromEmail => '[email protected] ' ,
132
+ :localizedFromNames => {
133
+ :fr => 'From fr'
134
+ } ,
135
+ :name => 'Test Template'
136
+ }
137
137
} )
138
138
handle_response ( response )
139
139
@@ -144,17 +144,17 @@ def test_email_template_crud
144
144
145
145
# Update the email tempalte
146
146
response = client . update_email_template ( id , {
147
- :emailTemplate => {
148
- :defaultFromName => 'Dude' ,
149
- :defaultHtmlTemplate => 'HTML Template' ,
150
- :defaultSubject => 'Subject' ,
151
- :defaultTextTemplate => 'Text Template' ,
152
- :fromEmail => '[email protected] ' ,
153
- :localizedFromNames => {
154
- :fr => 'From fr'
155
- } ,
156
- :name => 'Test Template updated'
157
- }
147
+ :emailTemplate => {
148
+ :defaultFromName => 'Dude' ,
149
+ :defaultHtmlTemplate => 'HTML Template' ,
150
+ :defaultSubject => 'Subject' ,
151
+ :defaultTextTemplate => 'Text Template' ,
152
+ :fromEmail => '[email protected] ' ,
153
+ :localizedFromNames => {
154
+ :fr => 'From fr'
155
+ } ,
156
+ :name => 'Test Template updated'
157
+ }
158
158
} )
159
159
handle_response ( response )
160
160
response = client . retrieve_email_template ( id )
@@ -163,20 +163,20 @@ def test_email_template_crud
163
163
164
164
# Preview it
165
165
response = client . retrieve_email_template_preview (
166
- {
167
- :emailTemplate => {
168
- :defaultFromName => 'Dude' ,
169
- :defaultHtmlTemplate => 'HTML Template' ,
170
- :defaultSubject => 'Subject' ,
171
- :defaultTextTemplate => 'Text Template' ,
172
- :fromEmail => '[email protected] ' ,
173
- :localizedFromNames => {
174
- :fr => 'From fr'
175
- } ,
176
- :name => 'Test Template updated'
177
- } ,
178
- :locale => 'fr'
179
- }
166
+ {
167
+ :emailTemplate => {
168
+ :defaultFromName => 'Dude' ,
169
+ :defaultHtmlTemplate => 'HTML Template' ,
170
+ :defaultSubject => 'Subject' ,
171
+ :defaultTextTemplate => 'Text Template' ,
172
+ :fromEmail => '[email protected] ' ,
173
+ :localizedFromNames => {
174
+ :fr => 'From fr'
175
+ } ,
176
+ :name => 'Test Template updated'
177
+ } ,
178
+ :locale => 'fr'
179
+ }
180
180
)
181
181
handle_response ( response )
182
182
assert_equal 'From fr' , response . success_response . email . from [ 'display' ] # Display is a reserved method in Object in Ruby
@@ -191,15 +191,19 @@ def test_email_template_crud
191
191
def test_user_crud
192
192
id = SecureRandom . uuid
193
193
client = FusionAuth ::FusionAuthClient . new ( @fusionauthApiKey , @fusionauthUrl )
194
-
194
+ # cleanup if we have already run
195
+ response = client . retrieve_user_by_login_id ( '[email protected] ' )
196
+ unless response . status == 404
197
+ client . delete_user ( response . success_response . user . id )
198
+ end
195
199
# Create a user
196
200
response = client . create_user ( id , {
197
- :user => {
198
- :firstName => 'Ruby' ,
199
- :lastName => 'Client' ,
200
-
201
- :password => 'password'
202
- }
201
+ :user => {
202
+ :firstName => 'Ruby' ,
203
+ :lastName => 'Client' ,
204
+
205
+ :password => 'password'
206
+ }
203
207
} )
204
208
handle_response ( response )
205
209
@@ -210,14 +214,33 @@ def test_user_crud
210
214
puts response . status
211
215
assert_equal '[email protected] ' , response . success_response . user . email
212
216
217
+ # Retrieve the user by loginId
218
+ response = client . retrieve_user_by_login_id ( '[email protected] ' )
219
+ handle_response ( response )
220
+ puts response . was_successful
221
+ puts response . status
222
+ assert_equal '[email protected] ' , response . success_response . user . email
223
+
224
+ # Retrieve the user by loginId with explicit login_id_types
225
+ response = client . retrieve_user_by_login_id_with_login_id_types ( '[email protected] ' , [ 'email' ] )
226
+ handle_response ( response )
227
+ puts response . was_successful
228
+ puts response . status
229
+ assert_equal '[email protected] ' , response . success_response . user . email
230
+
231
+ # Retrieve the user by loginId with explicit login_id_types (does not match)
232
+ # TODO: Once issue 1 is released, this should work
233
+ # response = client.retrieve_user_by_login_id_with_login_id_types('[email protected] ', ['phoneNumber'])
234
+ # assert_equal 404, response.status
235
+
213
236
# Update the user
214
237
response = client . update_user ( id , {
215
- :user => {
216
- :firstName => 'Ruby updated' ,
217
- :lastName => 'Client updated' ,
218
-
219
- :password => 'password updated'
220
- }
238
+ :user => {
239
+ :firstName => 'Ruby updated' ,
240
+ :lastName => 'Client updated' ,
241
+
242
+ :password => 'password updated'
243
+ }
221
244
} )
222
245
handle_response ( response )
223
246
assert_equal '[email protected] ' , response . success_response . user . email
@@ -268,50 +291,50 @@ def test_user_registration_crud_and_login
268
291
269
292
# Create an application
270
293
response = client . create_application ( application_id , {
271
- :application => {
272
- :name => 'Test application' ,
273
- :roles => [
274
- {
275
- :isDefault => false ,
276
- :name => 'admin' ,
277
- :isSuperRole => true ,
278
- :description => 'Admin role'
279
- } ,
280
- {
281
- :isDefault => true ,
282
- :name => 'user' ,
283
- :description => 'User role'
284
- }
285
- ]
286
- }
294
+ :application => {
295
+ :name => 'Test application' ,
296
+ :roles => [
297
+ {
298
+ :isDefault => false ,
299
+ :name => 'admin' ,
300
+ :isSuperRole => true ,
301
+ :description => 'Admin role'
302
+ } ,
303
+ {
304
+ :isDefault => true ,
305
+ :name => 'user' ,
306
+ :description => 'User role'
307
+ }
308
+ ]
309
+ }
287
310
} )
288
311
handle_response ( response )
289
312
290
313
# Create a user + registration
291
314
response = client . register ( id , {
292
- :user => {
293
- :firstName => 'Ruby' ,
294
- :lastName => 'Client' ,
295
-
296
- :password => 'password'
315
+ :user => {
316
+ :firstName => 'Ruby' ,
317
+ :lastName => 'Client' ,
318
+
319
+ :password => 'password'
320
+ } ,
321
+ :registration => {
322
+ :applicationId => application_id ,
323
+ :data => {
324
+ :foo => 'bar'
297
325
} ,
298
- :registration => {
299
- :applicationId => application_id ,
300
- :data => {
301
- :foo => 'bar'
302
- } ,
303
- :preferredLanguages => %w( en fr ) ,
304
- :roles => %w( user )
305
- }
326
+ :preferredLanguages => %w( en fr ) ,
327
+ :roles => %w( user )
328
+ }
306
329
} )
307
330
handle_response ( response )
308
331
309
332
# Authenticate the user
310
333
response = client . login ( {
311
-
312
- :password => 'password' ,
313
- :applicationId => application_id
314
- } )
334
+
335
+ :password => 'password' ,
336
+ :applicationId => application_id
337
+ } )
315
338
handle_response ( response )
316
339
assert_equal '[email protected] ' , response . success_response . user . email
317
340
@@ -323,14 +346,14 @@ def test_user_registration_crud_and_login
323
346
324
347
# Update the registration
325
348
response = client . update_registration ( id , {
326
- :registration => {
327
- :applicationId => application_id ,
328
- :data => {
329
- :foo => 'bar updated'
330
- } ,
331
- :preferredLanguages => %w( en fr ) ,
332
- :roles => %w( admin )
333
- }
349
+ :registration => {
350
+ :applicationId => application_id ,
351
+ :data => {
352
+ :foo => 'bar updated'
353
+ } ,
354
+ :preferredLanguages => %w( en fr ) ,
355
+ :roles => %w( admin )
356
+ }
334
357
} )
335
358
handle_response ( response )
336
359
assert_equal 'admin' , response . success_response . registration . roles [ 0 ]
0 commit comments