mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 06:21:11 +00:00 
			
		
		
		
	chore: add delete old auth token unit test
Also make use of subtests to make reading this test a tad easier.
This commit is contained in:
		
					parent
					
						
							
								5ce1b564dc
							
						
					
				
			
			
				commit
				
					
						d2a6e2362a
					
				
			
		
					 2 changed files with 30 additions and 15 deletions
				
			
		|  | @ -0,0 +1,5 @@ | ||||||
|  | - | ||||||
|  |  id: 1001 | ||||||
|  |  uid: 10 | ||||||
|  |  lookup_key: unique | ||||||
|  |  purpose: user_activation | ||||||
|  | @ -6,6 +6,7 @@ package user | ||||||
| import ( | import ( | ||||||
| 	"testing" | 	"testing" | ||||||
| 
 | 
 | ||||||
|  | 	auth_model "forgejo.org/models/auth" | ||||||
| 	"forgejo.org/models/db" | 	"forgejo.org/models/db" | ||||||
| 	organization_model "forgejo.org/models/organization" | 	organization_model "forgejo.org/models/organization" | ||||||
| 	"forgejo.org/models/unittest" | 	"forgejo.org/models/unittest" | ||||||
|  | @ -123,8 +124,10 @@ func TestAddEmailAddresses(t *testing.T) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestReplaceInactivePrimaryEmail(t *testing.T) { | func TestReplaceInactivePrimaryEmail(t *testing.T) { | ||||||
|  | 	defer unittest.OverrideFixtures("services/user/TestReplaceInactivePrimaryEmail/")() | ||||||
| 	require.NoError(t, unittest.PrepareTestDatabase()) | 	require.NoError(t, unittest.PrepareTestDatabase()) | ||||||
| 
 | 
 | ||||||
|  | 	t.Run("User doesn't exist", func(t *testing.T) { | ||||||
| 		email := &user_model.EmailAddress{ | 		email := &user_model.EmailAddress{ | ||||||
| 			Email: "user9999999@example.com", | 			Email: "user9999999@example.com", | ||||||
| 			UID:   9999999, | 			UID:   9999999, | ||||||
|  | @ -132,16 +135,23 @@ func TestReplaceInactivePrimaryEmail(t *testing.T) { | ||||||
| 		err := ReplaceInactivePrimaryEmail(db.DefaultContext, "user10@example.com", email) | 		err := ReplaceInactivePrimaryEmail(db.DefaultContext, "user10@example.com", email) | ||||||
| 		require.Error(t, err) | 		require.Error(t, err) | ||||||
| 		assert.True(t, user_model.IsErrUserNotExist(err)) | 		assert.True(t, user_model.IsErrUserNotExist(err)) | ||||||
|  | 	}) | ||||||
| 
 | 
 | ||||||
| 	email = &user_model.EmailAddress{ | 	t.Run("Normal", func(t *testing.T) { | ||||||
|  | 		unittest.AssertExistsIf(t, true, &auth_model.AuthorizationToken{UID: 10}) | ||||||
|  | 
 | ||||||
|  | 		email := &user_model.EmailAddress{ | ||||||
| 			Email: "user201@example.com", | 			Email: "user201@example.com", | ||||||
| 			UID:   10, | 			UID:   10, | ||||||
| 		} | 		} | ||||||
| 	err = ReplaceInactivePrimaryEmail(db.DefaultContext, "user10@example.com", email) | 		err := ReplaceInactivePrimaryEmail(db.DefaultContext, "user10@example.com", email) | ||||||
| 		require.NoError(t, err) | 		require.NoError(t, err) | ||||||
| 
 | 
 | ||||||
| 		user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10}) | 		user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10}) | ||||||
| 		assert.Equal(t, "user201@example.com", user.Email) | 		assert.Equal(t, "user201@example.com", user.Email) | ||||||
|  | 
 | ||||||
|  | 		unittest.AssertExistsIf(t, false, &auth_model.AuthorizationToken{UID: 10}) | ||||||
|  | 	}) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestDeleteEmailAddresses(t *testing.T) { | func TestDeleteEmailAddresses(t *testing.T) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue