diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-06-08 11:52:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-08 11:52:51 +0800 |
commit | b9d611e917d9bd10e0d8be8fc61e057d5936993c (patch) | |
tree | f70159ff5731da4b34312acfff8443dc3be61337 /models/user_mail_test.go | |
parent | 21cde5c439676d4aaa15dfc79505f364cc849ec0 (diff) | |
download | gitea-b9d611e917d9bd10e0d8be8fc61e057d5936993c.tar.gz gitea-b9d611e917d9bd10e0d8be8fc61e057d5936993c.zip |
Always store primary email address into email_address table and also the state (#15956)
* Always store primary email address into email_address table and also the state
* Add lower_email to not convert email to lower as what's added
* Fix fixture
* Fix tests
* Use BeforeInsert to save lower email
* Fix v180 migration
* fix tests
* Fix test
* Remove wrong submited codes
* Fix test
* Fix test
* Fix test
* Add test for v181 migration
* remove change user's email to lower
* Revert change on user's email column
* Fix lower email
* Fix test
* Fix test
Diffstat (limited to 'models/user_mail_test.go')
-rw-r--r-- | models/user_mail_test.go | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/models/user_mail_test.go b/models/user_mail_test.go index 5a223dd040..829a38c18d 100644 --- a/models/user_mail_test.go +++ b/models/user_mail_test.go @@ -17,9 +17,9 @@ func TestGetEmailAddresses(t *testing.T) { emails, _ := GetEmailAddresses(int64(1)) if assert.Len(t, emails, 3) { - assert.False(t, emails[0].IsPrimary) + assert.True(t, emails[0].IsPrimary) assert.True(t, emails[2].IsActivated) - assert.True(t, emails[2].IsPrimary) + assert.False(t, emails[2].IsPrimary) } emails, _ = GetEmailAddresses(int64(2)) @@ -45,13 +45,15 @@ func TestAddEmailAddress(t *testing.T) { assert.NoError(t, AddEmailAddress(&EmailAddress{ Email: "user1234567890@example.com", + LowerEmail: "user1234567890@example.com", IsPrimary: true, IsActivated: true, })) // ErrEmailAlreadyUsed err := AddEmailAddress(&EmailAddress{ - Email: "user1234567890@example.com", + Email: "user1234567890@example.com", + LowerEmail: "user1234567890@example.com", }) assert.Error(t, err) assert.True(t, IsErrEmailAlreadyUsed(err)) @@ -64,10 +66,12 @@ func TestAddEmailAddresses(t *testing.T) { emails := make([]*EmailAddress, 2) emails[0] = &EmailAddress{ Email: "user1234@example.com", + LowerEmail: "user1234@example.com", IsActivated: true, } emails[1] = &EmailAddress{ Email: "user5678@example.com", + LowerEmail: "user5678@example.com", IsActivated: true, } assert.NoError(t, AddEmailAddresses(emails)) @@ -82,20 +86,23 @@ func TestDeleteEmailAddress(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) assert.NoError(t, DeleteEmailAddress(&EmailAddress{ - UID: int64(1), - ID: int64(1), - Email: "user11@example.com", + UID: int64(1), + ID: int64(33), + Email: "user1-2@example.com", + LowerEmail: "user1-2@example.com", })) assert.NoError(t, DeleteEmailAddress(&EmailAddress{ - UID: int64(1), - Email: "user12@example.com", + UID: int64(1), + Email: "user1-3@example.com", + LowerEmail: "user1-3@example.com", })) // Email address does not exist err := DeleteEmailAddress(&EmailAddress{ - UID: int64(1), - Email: "user1234567890@example.com", + UID: int64(1), + Email: "user1234567890@example.com", + LowerEmail: "user1234567890@example.com", }) assert.Error(t, err) } @@ -106,13 +113,15 @@ func TestDeleteEmailAddresses(t *testing.T) { // delete multiple email address emails := make([]*EmailAddress, 2) emails[0] = &EmailAddress{ - UID: int64(2), - ID: int64(3), - Email: "user2@example.com", + UID: int64(2), + ID: int64(3), + Email: "user2@example.com", + LowerEmail: "user2@example.com", } emails[1] = &EmailAddress{ - UID: int64(2), - Email: "user21@example.com", + UID: int64(2), + Email: "user2-2@example.com", + LowerEmail: "user2-2@example.com", } assert.NoError(t, DeleteEmailAddresses(emails)) @@ -129,7 +138,7 @@ func TestMakeEmailPrimary(t *testing.T) { } err := MakeEmailPrimary(email) assert.Error(t, err) - assert.EqualError(t, err, ErrEmailNotExist.Error()) + assert.EqualError(t, err, ErrEmailAddressNotExist{email.Email}.Error()) email = &EmailAddress{ Email: "user11@example.com", @@ -168,15 +177,21 @@ func TestActivate(t *testing.T) { emails, _ := GetEmailAddresses(int64(1)) assert.Len(t, emails, 3) assert.True(t, emails[0].IsActivated) + assert.True(t, emails[0].IsPrimary) + assert.False(t, emails[1].IsPrimary) assert.True(t, emails[2].IsActivated) - assert.True(t, emails[2].IsPrimary) + assert.False(t, emails[2].IsPrimary) } func TestListEmails(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) // Must find all users and their emails - opts := &SearchEmailOptions{} + opts := &SearchEmailOptions{ + ListOptions: ListOptions{ + PageSize: 10000, + }, + } emails, count, err := SearchEmails(opts) assert.NoError(t, err) assert.NotEqual(t, int64(0), count) |