summaryrefslogtreecommitdiffstats
path: root/models/user_mail_test.go
diff options
context:
space:
mode:
authorguillep2k <18600385+guillep2k@users.noreply.github.com>2020-03-02 15:25:36 -0300
committerGitHub <noreply@github.com>2020-03-02 15:25:36 -0300
commit5e1438ba92fe5b4398ebf468e4ede21c7ef60409 (patch)
tree40096ee69a4ac5df46428a3cf1ae7ee3bee8078e /models/user_mail_test.go
parentb5ecc82d6e22b5701bfadc1ebc430b9c7fef0cc8 (diff)
downloadgitea-5e1438ba92fe5b4398ebf468e4ede21c7ef60409.tar.gz
gitea-5e1438ba92fe5b4398ebf468e4ede21c7ef60409.zip
Admin page for managing user e-mail activation (#10557)
* Implement mail activation admin panel * Add export comments * Fix another export comment * again... * And again! * Apply suggestions by @lunny * Add UI for user activated emails * Make new activation UI work * Fix lint * Prevent admin from self-deactivate; add modal Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/user_mail_test.go')
-rw-r--r--models/user_mail_test.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/models/user_mail_test.go b/models/user_mail_test.go
index 3352194e1f..8237ce6642 100644
--- a/models/user_mail_test.go
+++ b/models/user_mail_test.go
@@ -7,6 +7,8 @@ package models
import (
"testing"
+ "code.gitea.io/gitea/modules/util"
+
"github.com/stretchr/testify/assert"
)
@@ -169,3 +171,67 @@ func TestActivate(t *testing.T) {
assert.True(t, emails[2].IsActivated)
assert.True(t, emails[2].IsPrimary)
}
+
+func TestListEmails(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+
+ // Must find all users and their emails
+ opts := &SearchEmailOptions{}
+ emails, count, err := SearchEmails(opts)
+ assert.NoError(t, err)
+ assert.NotEqual(t, int64(0), count)
+ assert.True(t, count > 5)
+
+ contains := func(match func(s *SearchEmailResult) bool) bool {
+ for _, v := range emails {
+ if match(v) {
+ return true
+ }
+ }
+ return false
+ }
+
+ assert.True(t, contains(func(s *SearchEmailResult) bool { return s.UID == 18 }))
+ // 'user3' is an organization
+ assert.False(t, contains(func(s *SearchEmailResult) bool { return s.UID == 3 }))
+
+ // Must find no records
+ opts = &SearchEmailOptions{Keyword: "NOTFOUND"}
+ emails, count, err = SearchEmails(opts)
+ assert.NoError(t, err)
+ assert.Equal(t, int64(0), count)
+
+ // Must find users 'user2', 'user28', etc.
+ opts = &SearchEmailOptions{Keyword: "user2"}
+ emails, count, err = SearchEmails(opts)
+ assert.NoError(t, err)
+ assert.NotEqual(t, int64(0), count)
+ assert.True(t, contains(func(s *SearchEmailResult) bool { return s.UID == 2 }))
+ assert.True(t, contains(func(s *SearchEmailResult) bool { return s.UID == 27 }))
+
+ // Must find only primary addresses (i.e. from the `user` table)
+ opts = &SearchEmailOptions{IsPrimary: util.OptionalBoolTrue}
+ emails, count, err = SearchEmails(opts)
+ assert.NoError(t, err)
+ assert.True(t, contains(func(s *SearchEmailResult) bool { return s.IsPrimary }))
+ assert.False(t, contains(func(s *SearchEmailResult) bool { return !s.IsPrimary }))
+
+ // Must find only inactive addresses (i.e. not validated)
+ opts = &SearchEmailOptions{IsActivated: util.OptionalBoolFalse}
+ emails, count, err = SearchEmails(opts)
+ assert.NoError(t, err)
+ assert.True(t, contains(func(s *SearchEmailResult) bool { return !s.IsActivated }))
+ assert.False(t, contains(func(s *SearchEmailResult) bool { return s.IsActivated }))
+
+ // Must find more than one page, but retrieve only one
+ opts = &SearchEmailOptions{
+ ListOptions: ListOptions{
+ PageSize: 5,
+ Page: 1,
+ },
+ }
+ emails, count, err = SearchEmails(opts)
+ assert.NoError(t, err)
+ assert.Equal(t, 5, len(emails))
+ assert.True(t, count > int64(len(emails)))
+}