diff options
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) |