2014-05-26 20:16:36 -07:00
|
|
|
// Copyright 2014 Team 254. All Rights Reserved.
|
|
|
|
|
// Author: pat@patfairbank.com (Patrick Fairbank)
|
|
|
|
|
|
2017-08-23 22:41:56 -07:00
|
|
|
package model
|
2014-05-26 20:16:36 -07:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestGetNonexistentMatchResult(t *testing.T) {
|
2017-08-23 22:41:56 -07:00
|
|
|
db := setupTestDb(t)
|
2014-05-26 20:16:36 -07:00
|
|
|
|
|
|
|
|
match, err := db.GetMatchResultForMatch(1114)
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
assert.Nil(t, match)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestMatchResultCrud(t *testing.T) {
|
2017-08-23 22:41:56 -07:00
|
|
|
db := setupTestDb(t)
|
2014-05-26 20:16:36 -07:00
|
|
|
|
2017-08-23 22:41:56 -07:00
|
|
|
matchResult := BuildTestMatchResult(254, 5)
|
2017-08-05 20:48:17 -07:00
|
|
|
db.CreateMatchResult(matchResult)
|
2014-05-26 20:16:36 -07:00
|
|
|
matchResult2, err := db.GetMatchResultForMatch(254)
|
|
|
|
|
assert.Nil(t, err)
|
2017-08-05 20:48:17 -07:00
|
|
|
assert.Equal(t, matchResult, matchResult2)
|
2014-05-26 20:16:36 -07:00
|
|
|
|
2017-08-05 20:48:17 -07:00
|
|
|
db.SaveMatchResult(matchResult)
|
2014-05-26 20:16:36 -07:00
|
|
|
matchResult2, err = db.GetMatchResultForMatch(254)
|
|
|
|
|
assert.Nil(t, err)
|
2017-08-05 20:48:17 -07:00
|
|
|
assert.Equal(t, matchResult, matchResult2)
|
2014-05-26 20:16:36 -07:00
|
|
|
|
2017-08-05 20:48:17 -07:00
|
|
|
db.DeleteMatchResult(matchResult)
|
2014-05-26 20:16:36 -07:00
|
|
|
matchResult2, err = db.GetMatchResultForMatch(254)
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
assert.Nil(t, matchResult2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTruncateMatchResults(t *testing.T) {
|
2017-08-23 22:41:56 -07:00
|
|
|
db := setupTestDb(t)
|
2014-05-26 20:16:36 -07:00
|
|
|
|
2017-08-23 22:41:56 -07:00
|
|
|
matchResult := BuildTestMatchResult(254, 1)
|
2017-08-05 20:48:17 -07:00
|
|
|
db.CreateMatchResult(matchResult)
|
2014-05-26 20:16:36 -07:00
|
|
|
db.TruncateMatchResults()
|
|
|
|
|
matchResult2, err := db.GetMatchResultForMatch(254)
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
assert.Nil(t, matchResult2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetMatchResultForMatch(t *testing.T) {
|
2017-08-23 22:41:56 -07:00
|
|
|
db := setupTestDb(t)
|
2014-05-26 20:16:36 -07:00
|
|
|
|
2017-08-23 22:41:56 -07:00
|
|
|
matchResult := BuildTestMatchResult(254, 2)
|
2017-08-05 20:48:17 -07:00
|
|
|
db.CreateMatchResult(matchResult)
|
2017-08-23 22:41:56 -07:00
|
|
|
matchResult2 := BuildTestMatchResult(254, 5)
|
2017-08-05 20:48:17 -07:00
|
|
|
db.CreateMatchResult(matchResult2)
|
2017-08-23 22:41:56 -07:00
|
|
|
matchResult3 := BuildTestMatchResult(254, 4)
|
2017-08-05 20:48:17 -07:00
|
|
|
db.CreateMatchResult(matchResult3)
|
2014-05-26 20:16:36 -07:00
|
|
|
|
|
|
|
|
// Should return the match result with the highest play number (i.e. the most recent).
|
|
|
|
|
matchResult4, err := db.GetMatchResultForMatch(254)
|
|
|
|
|
assert.Nil(t, err)
|
2017-08-05 20:48:17 -07:00
|
|
|
assert.Equal(t, matchResult2, matchResult4)
|
2014-05-26 20:16:36 -07:00
|
|
|
}
|