Files
cheesy-arena-lite/model/match_result_test.go
2017-08-27 13:54:24 -07:00

66 lines
1.7 KiB
Go

// Copyright 2014 Team 254. All Rights Reserved.
// Author: pat@patfairbank.com (Patrick Fairbank)
package model
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestGetNonexistentMatchResult(t *testing.T) {
db := setupTestDb(t)
match, err := db.GetMatchResultForMatch(1114)
assert.Nil(t, err)
assert.Nil(t, match)
}
func TestMatchResultCrud(t *testing.T) {
db := setupTestDb(t)
matchResult := BuildTestMatchResult(254, 5)
db.CreateMatchResult(matchResult)
matchResult2, err := db.GetMatchResultForMatch(254)
assert.Nil(t, err)
assert.Equal(t, matchResult, matchResult2)
matchResult.BlueScore.AutoMobility = 12
db.SaveMatchResult(matchResult)
matchResult2, err = db.GetMatchResultForMatch(254)
assert.Nil(t, err)
assert.Equal(t, matchResult, matchResult2)
db.DeleteMatchResult(matchResult)
matchResult2, err = db.GetMatchResultForMatch(254)
assert.Nil(t, err)
assert.Nil(t, matchResult2)
}
func TestTruncateMatchResults(t *testing.T) {
db := setupTestDb(t)
matchResult := BuildTestMatchResult(254, 1)
db.CreateMatchResult(matchResult)
db.TruncateMatchResults()
matchResult2, err := db.GetMatchResultForMatch(254)
assert.Nil(t, err)
assert.Nil(t, matchResult2)
}
func TestGetMatchResultForMatch(t *testing.T) {
db := setupTestDb(t)
matchResult := BuildTestMatchResult(254, 2)
db.CreateMatchResult(matchResult)
matchResult2 := BuildTestMatchResult(254, 5)
db.CreateMatchResult(matchResult2)
matchResult3 := BuildTestMatchResult(254, 4)
db.CreateMatchResult(matchResult3)
// Should return the match result with the highest play number (i.e. the most recent).
matchResult4, err := db.GetMatchResultForMatch(254)
assert.Nil(t, err)
assert.Equal(t, matchResult2, matchResult4)
}