1
1
/*
2
- * Copyright (c) 2019, FusionAuth, All Rights Reserved
2
+ * Copyright (c) 2019-2024 , FusionAuth, All Rights Reserved
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
'use strict' ;
18
18
19
- import { ApplicationRequest , FusionAuthClient , GrantType } from '../index' ;
19
+ import { ApplicationRequest , FusionAuthClient , GrantType , SearchResponse } from '../index' ;
20
20
import * as chai from 'chai' ;
21
21
import ClientResponse from "../src/ClientResponse" ;
22
22
@@ -114,7 +114,7 @@ describe('#FusionAuthClient()', function () {
114
114
}
115
115
} ) ;
116
116
117
- it ( 'Create, Patch and Delete a User' , async ( ) => {
117
+ it ( 'Create, Patch, Search, and Delete a User' , async ( ) => {
118
118
let clientResponse = await client . createUser ( null , {
119
119
user : {
120
120
email : 'nodejs@fusionauth.io' ,
@@ -130,8 +130,10 @@ describe('#FusionAuthClient()', function () {
130
130
chai . expect ( clientResponse . response ) . to . have . property ( 'user' ) ;
131
131
chai . expect ( clientResponse . response . user ) . to . have . property ( 'id' ) ;
132
132
133
+ const userId = clientResponse . response . user . id ;
134
+
133
135
// Patch the user
134
- clientResponse = await client . patchUser ( clientResponse . response . user . id , {
136
+ clientResponse = await client . patchUser ( userId , {
135
137
user : {
136
138
firstName : "Jan"
137
139
}
@@ -142,20 +144,46 @@ describe('#FusionAuthClient()', function () {
142
144
chai . expect ( clientResponse . response ) . to . have . property ( 'user' ) ;
143
145
chai . expect ( clientResponse . response . user . firstName ) . to . equal ( "Jan" ) ;
144
146
145
- clientResponse = await client . deleteUser ( clientResponse . response . user . id ) ;
146
- chai . assert . strictEqual ( clientResponse . statusCode , 200 ) ;
147
- // Browser will return empty, node will return null, account for both scenarios
148
- if ( clientResponse . response === null ) {
149
- chai . assert . isNull ( clientResponse . response ) ;
150
- } else {
151
- chai . assert . isUndefined ( clientResponse . response ) ;
147
+ // create a second user and search them both
148
+ clientResponse = await client . createUser ( null , {
149
+ user : {
150
+ email : 'node2@fusionauth.io' ,
151
+ firstName : 'Joan' ,
152
+ password : 'password'
153
+ } ,
154
+ skipVerification : true ,
155
+ sendSetPasswordEmail : false
156
+ } ) ;
157
+
158
+ const secondUserId = clientResponse . response . user . id ;
159
+ const bothUsers = [ userId , secondUserId ] ;
160
+
161
+ const searchResp : ClientResponse < SearchResponse > = await client . searchUsersByIds ( bothUsers ) ;
162
+ chai . assert . strictEqual ( searchResp . statusCode , 200 ) ;
163
+ chai . assert . strictEqual ( searchResp . response . total , 2 ) ;
164
+ // make sure each user was returned
165
+ bothUsers . forEach ( id => chai . assert . isNotNull ( searchResp . response . users . find ( user => user . id = id ) ) ) ;
166
+
167
+ // delete both users
168
+ for ( const id of bothUsers ) {
169
+ clientResponse = await client . deleteUser ( id ) ;
170
+ chai . assert . strictEqual ( clientResponse . statusCode , 200 ) ;
171
+ // Browser will return empty, node will return null, account for both scenarios
172
+ if ( clientResponse . response === null ) {
173
+ chai . assert . isNull ( clientResponse . response ) ;
174
+ } else {
175
+ chai . assert . isUndefined ( clientResponse . response ) ;
176
+ }
152
177
}
153
178
154
- try {
155
- await client . retrieveUserByEmail ( 'nodejs@fusionauth.io' ) ;
156
- chai . expect . fail ( "The user should have been deleted!" ) ;
157
- } catch ( clientResponse ) {
158
- chai . assert . strictEqual ( clientResponse . statusCode , 404 ) ;
179
+ // check that they are gone
180
+ for ( const email of [ 'nodejs@fusionauth.io' , 'node2@fusionauth.io' ] ) {
181
+ try {
182
+ await client . retrieveUserByEmail ( email ) ;
183
+ chai . expect . fail ( `The user with ${ email } should have been deleted!` ) ;
184
+ } catch ( clientResponse ) {
185
+ chai . assert . strictEqual ( clientResponse . statusCode , 404 ) ;
186
+ }
159
187
}
160
188
} ) ;
161
189
0 commit comments