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:
59
api/owner_get_test.go
Normal file
59
api/owner_get_test.go
Normal file
@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOwnerGetByEmailBasics(t *testing.T) {
|
||||
failTestOnError(t, setupTestEnv())
|
||||
|
||||
ownerHex, _ := ownerNew("test@example.com", "Test", "hunter2")
|
||||
|
||||
o, err := ownerGetByEmail("test@example.com")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error on ownerGetByEmail: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if o.OwnerHex != ownerHex {
|
||||
t.Errorf("expected ownerHex=%s got ownerHex=%s", ownerHex, o.OwnerHex)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnerGetByEmailDNE(t *testing.T) {
|
||||
failTestOnError(t, setupTestEnv())
|
||||
|
||||
if _, err := ownerGetByEmail("invalid@example.com"); err == nil {
|
||||
t.Errorf("expected error not found on ownerGetByEmail before creating an account")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnerGetBySessionBasics(t *testing.T) {
|
||||
failTestOnError(t, setupTestEnv())
|
||||
|
||||
ownerHex, _ := ownerNew("test@example.com", "Test", "hunter2")
|
||||
|
||||
session, _ := ownerLogin("test@example.com", "hunter2")
|
||||
|
||||
o, err := ownerGetBySession(session)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error on ownerGetBySession: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if o.OwnerHex != ownerHex {
|
||||
t.Errorf("expected ownerHex=%s got ownerHex=%s", ownerHex, o.OwnerHex)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnerGetBySessionDNE(t *testing.T) {
|
||||
failTestOnError(t, setupTestEnv())
|
||||
|
||||
if _, err := ownerGetBySession("does-not-exist"); err == nil {
|
||||
t.Errorf("expected error not found on ownerGetBySession before creating an account")
|
||||
return
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user