Nuestro burocrata preferido: Sam Lowry https://lowry.sindominio.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

73 lines
1.4 KiB

package db
import (
"testing"
"time"
)
const (
code = "code"
)
func TestAddInvite(t *testing.T) {
db := initTestDB(t)
defer delTestDB(db)
if db.IsInviteValid(code) {
t.Errorf("Got valid invite before adding it")
}
err := db.AddInvite(code, "")
if err != nil {
t.Fatalf("Got an error adding invite: %v", err)
}
if !db.IsInviteValid(code) {
t.Errorf("Got invalid invite after adding it")
}
err = db.DelInvite(code)
if err != nil {
t.Fatalf("Got an error deleting invite: %v", err)
}
if db.IsInviteValid(code) {
t.Errorf("Got valid invite deleting it")
}
}
func TestExpireInvites(t *testing.T) {
db := initTestDB(t)
defer delTestDB(db)
err := db.AddInvite(code, "")
if err != nil {
t.Fatalf("Got an error adding invite: %v", err)
}
if !db.IsInviteValid(code) {
t.Errorf("Got invalid invite after adding it")
}
err = db.ExpireInvites(time.Microsecond)
if err != nil {
t.Fatalf("Got an error expiring invites: %v", err)
}
if db.IsInviteValid(code) {
t.Errorf("Got valid invite after expiring it")
}
}
func TestListUserInvites(t *testing.T) {
db := initTestDB(t)
defer delTestDB(db)
err := db.AddInvite(code, "user")
if err != nil {
t.Fatalf("Got an error adding invite: %v", err)
}
invites, err := db.ListUserInvites("user")
if err != nil {
t.Fatalf("Got an error listing invites: %v", err)
}
if len(invites) != 1 && invites[0] != code {
t.Fatalf("Code not in list of user invites: %v", invites)
}
}