Example #1
0
func TestLeastUsedTrackId_NoTeamTracks(t *T) {
	table.LoadFixtures(table.Fixtures{
		"team_tracks": []table.RowFixture{},
		"tracks": []table.RowFixture{
			table.RowFixture{
				"track_id":          1,
				"question_id_order": "1|2|3",
				"start_time":        time.Now().Add(-1 * time.Hour),
				"end_time":          time.Now().Add(1 * time.Hour),
			},
			table.RowFixture{
				"track_id":          2,
				"question_id_order": "3|2|1",
				"start_time":        time.Now().Add(-1 * time.Hour),
				"end_time":          time.Now().Add(1 * time.Hour),
			},
			table.RowFixture{
				"track_id":          3,
				"question_id_order": "2|1|3",
				"start_time":        time.Now().Add(-1 * time.Hour),
				"end_time":          time.Now().Add(1 * time.Hour),
			},
		},
	})

	trackId, err := table.LeastUsedTrackId(time.Now())
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, trackId >= 1 && trackId <= 3, "%d", trackId)
}
Example #2
0
//CreateTeam will store a team and put a team on a track
func CreateTeam(teamName, telephoneNumber string) (u *record.User, t *record.Team, err error) {
	//get an unused phrase
	phrase_id, phrase, err := table.UnusedPhrase()
	if err != nil {
		return
	}

	//get a track
	track_id, err := table.LeastUsedTrackId(time.Now())
	if err != nil {
		return
	}

	//create a team record
	t, err = table.CreateTeam(track_id, teamName)
	if err != nil {
		return
	}

	if err = table.MarkPhraseInUse(t.TeamId, phrase_id); err != nil {
		return
	}

	t.Phrase = phrase

	//store a user
	u, err = table.CreateUser(telephoneNumber, t.TeamId)

	return
}
Example #3
0
func TestLeastUsedTrackId(t *T) {
	beforeTrackTest()
	trackId, err := table.LeastUsedTrackId(time.Now())
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, trackId == 3, "%d", trackId)
}