@@ -24,8 +24,8 @@ test('signup - a new user', async () => {
24
24
} ) ;
25
25
26
26
test ( 'signup - with existent user' , async ( ) => {
27
- const req = client ( await startServer ( ) ) ;
28
27
expect . assertions ( 1 ) ;
28
+ const req = client ( await startServer ( ) ) ;
29
29
30
30
try {
31
31
await req . request ( `mutation {
@@ -39,8 +39,8 @@ test('signup - with existent user', async () => {
39
39
} ) ;
40
40
41
41
test ( 'signup - with weak password' , async ( ) => {
42
- const req = client ( await startServer ( ) ) ;
43
42
expect . assertions ( 1 ) ;
43
+ const req = client ( await startServer ( ) ) ;
44
44
45
45
try {
46
46
await req . request ( `mutation {
@@ -92,8 +92,8 @@ test('login - non-existent user', async () => {
92
92
} ) ;
93
93
94
94
test ( 'login - wrong password' , async ( ) => {
95
- const req = client ( await startServer ( ) ) ;
96
95
expect . assertions ( 1 ) ;
96
+ const req = client ( await startServer ( ) ) ;
97
97
98
98
try {
99
99
await req . request ( `mutation {
@@ -123,8 +123,8 @@ test('update current user data - correct', async () => {
123
123
} ) ;
124
124
125
125
test ( 'update current user data - wrong old passwd' , async ( ) => {
126
- const req = clientWithAuth ( await startServer ( ) ) ;
127
126
expect . assertions ( 1 ) ;
127
+ const req = clientWithAuth ( await startServer ( ) ) ;
128
128
129
129
try {
130
130
await req . request ( `mutation {
@@ -165,8 +165,8 @@ test('update user password', async () => {
165
165
} ) ;
166
166
167
167
test ( 'trigger password reset - correct' , async ( ) => {
168
- const req = clientWithAuth ( await startServer ( ) ) ;
169
168
expect . assertions ( 6 ) ;
169
+ const req = clientWithAuth ( await startServer ( ) ) ;
170
170
const spy = jest . spyOn ( FakeAdapter . prototype , 'updateUserResetToken' ) ;
171
171
172
172
const result = await req . request ( `mutation {
@@ -220,3 +220,118 @@ test('trigger password reset - correct', async () => {
220
220
221
221
spy . mockRestore ( ) ;
222
222
} ) ;
223
+
224
+ test ( 'invite user - correct' , async ( ) => {
225
+ expect . assertions ( 6 ) ;
226
+ const req = clientWithAuth ( await startServer ( ) ) ;
227
+ const spy = jest . spyOn ( FakeAdapter . prototype , 'createUserByInvite' ) ;
228
+
229
+ const result = await req . request ( `mutation {
230
+ inviteUser(data: {email: "[email protected] "}) {
231
+ id
232
+ }
233
+ }` ) ;
234
+
235
+ expect ( spy ) . toHaveBeenCalled ( ) ;
236
+
237
+ expect ( ( result as any ) . inviteUser ) . toEqual ( {
238
+ id : '3'
239
+ } ) ;
240
+
241
+ const { inviteToken } = await spy . mock . results [ 0 ] . value ;
242
+ // Verify the resetToken is a UUID
243
+ expect ( inviteToken . length ) . toBe ( 36 ) ;
244
+
245
+ const SIGNUP_INVITE = `mutation {
246
+ signupByInvite(data:{name: "Roger", email: "[email protected] ", password: "testtest4", inviteToken: "${ inviteToken } "}) {
247
+ user {
248
+ id
249
+ }
250
+ }
251
+ }` ;
252
+
253
+ const result2 = await req . request ( SIGNUP_INVITE ) ;
254
+
255
+ expect ( ( result2 as any ) . signupByInvite . user ) . toEqual ( {
256
+ id : '3'
257
+ } ) ;
258
+
259
+ const result3 = await req . request ( `mutation {
260
+ login(email: "[email protected] ", password: "testtest4") {
261
+ user {
262
+ id
263
+ }
264
+ }
265
+ }` ) ;
266
+
267
+ expect ( ( result3 as any ) . login . user ) . toEqual ( {
268
+ id : '3'
269
+ } ) ;
270
+
271
+ // Now verify that the inviteToken is now invalid
272
+ try {
273
+ await req . request ( SIGNUP_INVITE ) ;
274
+ } catch ( e ) {
275
+ expect ( String ( e ) ) . toMatch ( / i n v i t e T o k e n i s i n v a l i d / ) ;
276
+ }
277
+
278
+ spy . mockRestore ( ) ;
279
+ } ) ;
280
+
281
+ test ( 'confirm email - correct' , async ( ) => {
282
+ expect . assertions ( 6 ) ;
283
+ const req = clientWithAuth ( await startServer ( ) ) ;
284
+ const spy = jest . spyOn ( FakeAdapter . prototype , 'createUserBySignup' ) ;
285
+
286
+ const result = await req . request ( `mutation {
287
+ signup(data:{name: "Roger", email: "[email protected] ", password: "testtest4"}) {
288
+ user {
289
+ id
290
+ }
291
+ }
292
+ }` ) ;
293
+
294
+ expect ( spy ) . toHaveBeenCalled ( ) ;
295
+
296
+ expect ( ( result as any ) . signup . user ) . toEqual ( {
297
+ id : '3'
298
+ } ) ;
299
+
300
+ const { emailConfirmToken } = await spy . mock . results [ 0 ] . value ;
301
+ // Verify the emailConfirmToken is a UUID
302
+ expect ( emailConfirmToken . length ) . toBe ( 36 ) ;
303
+
304
+ const CONFIRM_EMAIL = `mutation {
305
+ confirmEmail(email: "[email protected] ", emailConfirmToken: "${ emailConfirmToken } ") {
306
+ user {
307
+ id
308
+ }
309
+ }
310
+ }` ;
311
+ const result2 = await req . request ( CONFIRM_EMAIL ) ;
312
+
313
+ expect ( ( result2 as any ) . confirmEmail . user ) . toEqual ( {
314
+ id : '3'
315
+ } ) ;
316
+
317
+ const result3 = await req . request ( `mutation {
318
+ login(email: "[email protected] ", password: "testtest4") {
319
+ user {
320
+ id
321
+ }
322
+ }
323
+ }` ) ;
324
+
325
+ expect ( ( result3 as any ) . login . user ) . toEqual ( {
326
+ id : '3'
327
+ } ) ;
328
+
329
+ // Now verify that the emailConfirmToken is now invalid
330
+ try {
331
+ await req . request ( CONFIRM_EMAIL ) ;
332
+ } catch ( e ) {
333
+ expect ( String ( e ) ) . toMatch ( / e m a i l C o n f i r m T o k e n i s i n v a l i d / ) ;
334
+ }
335
+
336
+ spy . mockRestore ( ) ;
337
+ } ) ;
0 commit comments