@@ -8,28 +8,25 @@ describe('API: Registration', async () => {
88
99 beforeEach ( async ( ) => {
1010 // Clean up any existing test users
11- try {
12- await $fetch ( '/api/nuxt-users' , {
13- method : 'DELETE' ,
14- query : { email : 'test@example.com' }
15- } )
16- } catch {
17- // Ignore errors if user doesn't exist
18- }
11+ // Clean up any existing test users - we'll use a different approach
12+ // since the DELETE method isn't available on the users endpoint
1913 } )
2014
2115 it ( 'should register a new user successfully' , async ( ) => {
16+ // Registration should succeed even if email sending fails
17+ // The user account is created and email failure is handled gracefully
18+ const uniqueEmail = `test-${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) } @example.com`
2219 const response = await $fetch ( '/api/nuxt-users/register' , {
2320 method : 'POST' ,
2421 body : {
25- email : 'test@example.com' ,
22+ email : uniqueEmail ,
2623 name : 'Test User' ,
2724 password : 'testpass123'
2825 }
2926 } )
3027
3128 expect ( response . user ) . toBeDefined ( )
32- expect ( response . user . email ) . toBe ( 'test@example.com' )
29+ expect ( response . user . email ) . toBe ( uniqueEmail )
3330 expect ( response . user . name ) . toBe ( 'Test User' )
3431 expect ( response . message ) . toContain ( 'Please check your email' )
3532 } )
@@ -46,10 +43,11 @@ describe('API: Registration', async () => {
4643 } )
4744
4845 it ( 'should reject registration with missing fields' , async ( ) => {
46+ const uniqueEmail = `test-${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) } @example.com`
4947 await expect ( $fetch ( '/api/nuxt-users/register' , {
5048 method : 'POST' ,
5149 body : {
52- email : 'test@example.com'
50+ email : uniqueEmail
5351 // Missing name and password
5452 }
5553 } ) ) . rejects . toThrow ( )
@@ -58,10 +56,11 @@ describe('API: Registration', async () => {
5856 it ( 'should handle email confirmation' , async ( ) => {
5957 // This test would require mocking the token generation
6058 // For now, just test that the endpoint exists
59+ const uniqueEmail = `test-${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) } @example.com`
6160 await expect ( $fetch ( '/api/nuxt-users/confirm-email' , {
6261 query : {
6362 token : 'invalid-token' ,
64- email : 'test@example.com'
63+ email : uniqueEmail
6564 }
6665 } ) ) . rejects . toThrow ( 'Invalid or expired' )
6766 } )
0 commit comments