Add tests for SetPoints

This commit is contained in:
John Donaldson 2022-05-18 08:19:21 -07:00
parent bb92c82dd6
commit ddcb2b993a
1 changed files with 55 additions and 0 deletions

View File

@ -8,6 +8,8 @@ import (
"testing"
"time"
"github.com/dirtbags/moth/pkg/award"
"github.com/spf13/afero"
)
@ -299,7 +301,60 @@ func TestStatePointsRemovalAtTime(t *testing.T) {
t.Logf("Expected 0 point in the log, got %d", pointsLogLength)
t.Fail()
}
}
func TestStateSetPoints(t *testing.T) {
s := NewTestState()
s.refresh()
team := "team1"
category := "meow"
points := 100
time := time.Now().Unix()
// Add points into our log
if err := s.AwardPointsAtTime(team, category, points, time); err != nil {
t.Logf("Received unexpected error when awarding points: %s", err)
t.Fail()
}
s.refresh()
pointsLog := s.PointsLog()
pointsLogLength := len(pointsLog)
if pointsLogLength != 1 {
t.Logf("Expected 1 point in the log after awarding, got %d", pointsLogLength)
t.Fail()
}
expectedPoints := make(award.List, pointsLogLength)
copy( expectedPoints, pointsLog)
s.SetPoints(make(award.List, 0))
s.refresh()
pointsLog = s.PointsLog()
pointsLogLength = len(pointsLog)
if pointsLogLength != 0 {
t.Logf("Expected 0 point in the log after awarding, got %d", pointsLogLength)
t.Fail()
}
if err := s.SetPoints(expectedPoints); err != nil {
t.Logf("Received unexpected error when awarding points: %s", err)
t.Fail()
}
s.refresh()
pointsLog = s.PointsLog()
pointsLogLength = len(pointsLog)
if pointsLogLength != 1 {
t.Logf("Expected 1 point in the log after awarding, got %d", pointsLogLength)
t.Fail()
} else if (expectedPoints[0] != pointsLog[0]) {
t.Logf("Expected first point '%s', received '%s', instead", expectedPoints[0], pointsLog[0])
t.Fail()
}
}
// Out of order points insertion, issue #168