mirror of
https://gitlab.com/commento/commento.git
synced 2025-06-29 22:56:37 -04:00
api: Add go files
I know this is a huge commit, but I can't be bothered to check this in part by part.
This commit is contained in:
61
api/domain_moderator_test.go
Normal file
61
api/domain_moderator_test.go
Normal file
@ -0,0 +1,61 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDomainModeratorListBasics(t *testing.T) {
|
||||
failTestOnError(t, setupTestEnv())
|
||||
|
||||
domainModeratorNew("example.com", "test@example.com")
|
||||
domainModeratorNew("example.com", "test2@example.com")
|
||||
|
||||
mods, err := domainModeratorList("example.com")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error listing domain moderators: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(mods) != 2 {
|
||||
t.Errorf("expected number of domain moderators to be 2 got %d", len(mods))
|
||||
return
|
||||
}
|
||||
|
||||
if mods[0].Email != "test@example.com" {
|
||||
t.Errorf("expected first domain to be test@example.com got %s", mods[0].Email)
|
||||
return
|
||||
}
|
||||
|
||||
if mods[1].Email != "test2@example.com" {
|
||||
t.Errorf("expected first domain to be test2@example.com got %s", mods[0].Email)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsDomainModeratorBasics(t *testing.T) {
|
||||
failTestOnError(t, setupTestEnv())
|
||||
|
||||
domainModeratorNew("example.com", "test@example.com")
|
||||
|
||||
isMod, err := isDomainModerator("example.com", "test@example.com")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error checking if email is a moderator: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !isMod {
|
||||
t.Errorf("expected test@example.com to be a moderator got isMod=false")
|
||||
return
|
||||
}
|
||||
|
||||
isMod, err = isDomainModerator("example.com", "test2@example.com")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error checking if email is a moderator: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if isMod {
|
||||
t.Errorf("expected test2@example.com to not be a moderator got isMod=true")
|
||||
return
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user