This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
JISQueueing/db/ticket_test.go

61 lines
1.7 KiB
Go

package db_test
import (
"JISQueueing/db"
"testing"
"time"
)
func TestNewTicket(t *testing.T) {
db.UseInMemoryDatabase()
db.NewVisitor(exampleVisitor())
ticket := db.NewTicket(exampleVisitor())
if ticket.Email != exampleVisitor().Email || ticket.Staff != "{}" {
t.Errorf("Expected email and username to mach.")
}
newTicket, _ := db.GetTicket(ticket.ID)
if ticket != newTicket {
t.Errorf("Expected ticket to be present in database. returned %v, instead of %v", newTicket, ticket)
}
}
func TestSetClaimer(t *testing.T) {
db.UseInMemoryDatabase()
db.Register(exampleStaffUser(), "test123")
ticket := db.NewTicket(exampleVisitor())
if !db.SetClaimer(ticket.ID, exampleStaffUser().Username) {
t.Errorf("Expected ticket to update claimer successfully.")
}
if db.SetClaimer(ticket.ID, exampleStaffUser().Username) {
t.Errorf("Expected ticket's claimer to not update as already set")
}
}
func TestFinishTicket(t *testing.T) {
db.UseInMemoryDatabase()
ticket := db.NewTicket(exampleVisitor())
breakpoint := time.Date(2019, 10, 25, 0, 0, 0, 0, time.UTC)
if breakpoint.Before(ticket.End) {
t.Errorf("Expected ticket end time to be Unix 0, got %d instead.", ticket.End.Unix())
}
db.FinishTicket(ticket.ID)
ticket, _ = db.GetTicket(ticket.ID)
if breakpoint.After(ticket.End) {
t.Errorf("Expected ticket to get time updated after completion. got %d instead", ticket.End.Unix())
}
}
func TestCancelTicket(t *testing.T) {
db.UseInMemoryDatabase()
ticket := db.NewTicket(exampleVisitor())
db.CancelTicket(ticket.ID)
ticket, _ = db.GetTicket(ticket.ID)
if ticket.Start.Unix() != 0 {
t.Errorf("Expected ticket to get start time updated after cancel. got %d instead", ticket.Start.Unix())
}
}