mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Migrate admin functions into app package * More user function refactoring * Move post functions into app package
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package app
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestIsUsernameTaken(t *testing.T) {
|
|
th := Setup().InitBasic()
|
|
user := th.BasicUser
|
|
taken := IsUsernameTaken(user.Username)
|
|
|
|
if !taken {
|
|
t.Logf("the username '%v' should be taken", user.Username)
|
|
t.FailNow()
|
|
}
|
|
|
|
newUsername := "randomUsername"
|
|
taken = IsUsernameTaken(newUsername)
|
|
|
|
if taken {
|
|
t.Logf("the username '%v' should not be taken", newUsername)
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
func TestCheckUserDomain(t *testing.T) {
|
|
th := Setup().InitBasic()
|
|
user := th.BasicUser
|
|
|
|
cases := []struct {
|
|
domains string
|
|
matched bool
|
|
}{
|
|
{"simulator.amazonses.com", true},
|
|
{"gmail.com", false},
|
|
{"", true},
|
|
{"gmail.com simulator.amazonses.com", true},
|
|
}
|
|
for _, c := range cases {
|
|
matched := CheckUserDomain(user, c.domains)
|
|
if matched != c.matched {
|
|
if c.matched {
|
|
t.Logf("'%v' should have matched '%v'", user.Email, c.domains)
|
|
} else {
|
|
t.Logf("'%v' should not have matched '%v'", user.Email, c.domains)
|
|
}
|
|
t.FailNow()
|
|
}
|
|
}
|
|
}
|