Пример #1
0
func TestCreateDuplicateUser(t *T) {
	beforeUserTest()
	_, err := table.CreateUser("123 123 1234", 1)
	rdtest.Assert(t, err == nil, err)
	_, err = table.CreateUser("123 123 1234", 1)
	rdtest.Assert(t, err == table.DuplicateUser, "%s", err)
}
Пример #2
0
func TestFindUserWithTeam(t *T) {
	beforeUserTest()
	user, team, err := table.FindUserWithTeam(100)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, user.UserId == 100, user)
	rdtest.Assert(t, team.TeamId == 1, team)
}
Пример #3
0
func TestFindClue(t *T) {
	beforeClueTest()
	clue, err := table.FindClue(1)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, clue != nil)
	rdtest.Assert(t, clue.Text == "Text 1")
}
Пример #4
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)
}
Пример #5
0
func TestUnusedPhrase(t *T) {
	beforePhraseTest()
	p_id, p, err := table.UnusedPhrase()
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, p_id == 1, "%s", p)
	rdtest.Assert(t, p == "phrase_1", "%s", p)
}
Пример #6
0
func TestStartProgressForClueTeam(t *T) {
	beforeTeamProgressTest()
	err := table.StartProgress(3, 1)
	rdtest.Assert(t, err == nil, err)
	_, err = table.FindProgressByClueTeam(3, 1)
	rdtest.Assert(t, err == nil, err)
}
Пример #7
0
func TestCreateTeamProgress_PreventDuplicate(t *T) {
	beforeTeamProgressTest()

	p, err := table.CreateTeamProgress(1, 1)
	rdtest.Assert(t, p == nil)
	rdtest.Assert(t, err == table.TeamProgressExists)
}
Пример #8
0
func TestCurrentClueForTeam_NoProgress(t *testing.T) {
	beforeCurrentTest()

	clue, err := clues.CurrentForTeam(2, clues.NoExpectedId)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, clue.ClueId == 1)
}
Пример #9
0
func TestFindOneClue(t *T) {
	beforeClueTest()

	c := new(record.Clue)
	err := table.FindOne(c, "SELECT question_id, text, answer, hint_one, hint_two, description, is_enabled FROM questions where question_id = ?", 1)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, c.ClueId == 1, "%d", c.ClueId)
}
Пример #10
0
func TestFindTeamByPhrase(t *T) {
	beforeTeamTest()

	team, err := table.FindTeamByPhrase("phrase 1000")
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, team.TeamId == 100)
	rdtest.Assert(t, team.Phrase == "phrase 1000")
}
Пример #11
0
func TestFindHintsByClueIdLessThanIdx(t *T) {
	beforeHintTest()

	hints, err := table.FindHintsByClueIdLessThanIdx(1, 0)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, len(hints) == 1, "1 != %d", len(hints))
	rdtest.Assert(t, hints[0].Idx == 0, "0 != %d", hints[0].Idx)
}
Пример #12
0
func TestFindAllClues(t *T) {
	beforeClueTest()
	clues, err := table.FindAllClues()
	rdtest.Assert(t, err == nil, err)
	rdtest.Equal(t, len(clues), 2)
	rdtest.Assert(t, clues[0].ClueId == 1)
	rdtest.Assert(t, clues[1].ClueId == 2)
}
Пример #13
0
func TestCreateTeam(t *T) {
	beforeTeamTest()
	user, team, err := biz.CreateTeam("Best Team", "1231231234")
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, user.UserId > 0, "user not saved")
	rdtest.Assert(t, team.TeamId > 0, "team not saved")
	rdtest.Assert(t, team.Phrase == "phrase_1", "wrong phrase")
	rdtest.Assert(t, team.TrackId == 1, "wrong track")
}
Пример #14
0
func TestCreateUser(t *T) {
	beforeUserTest()
	u, err := table.CreateUser("123 123 1234", 1)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, u.UserId > 0, "no user id")
	rdtest.Assert(t, u.Telephone == "1231231234", "wrong telephone")
	rdtest.Assert(t, u.TeamId == 1, "wrong team id")
	rdtest.Assert(t, !u.DidAcceptWaiver, "should not have accepted waiver")
}
Пример #15
0
func TestIncrementHintsTakenForClueTeam(t *T) {
	beforeTeamProgressTest()

	err := table.IncrementHintsTakenForClueTeam(1, 1)
	rdtest.Assert(t, err == nil, err)
	currentClue, err := table.FindClueWithProgressForTeam(1)
	rdtest.Assert(t, err == nil)
	rdtest.Assert(t, currentClue.HintCnt == 1)
}
Пример #16
0
func TestFindHintsByClueId(t *T) {
	beforeHintTest()

	hints, err := table.FindHintsByClueId(1)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, len(hints) == 2, "2 != %d", len(hints))
	rdtest.Assert(t, hints[0].Idx == 0, "0 != %d", hints[0].Idx)
	rdtest.Assert(t, hints[1].Idx == 1, "1 != %d", hints[1].Idx)
}
Пример #17
0
func TestFindCurrentTracks(t *T) {
	beforeTrackTest()
	tracks, err := table.FindCurrentTracks(time.Now())
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, len(tracks) == 3, "%d", len(tracks))
	rdtest.Assert(t, tracks[0].TrackId == 1)
	rdtest.Assert(t, tracks[1].TrackId == 2)
	rdtest.Assert(t, tracks[2].TrackId == 3)
}
Пример #18
0
func TestCreateTeam(t *T) {
	beforeTeamTest()

	team, err := table.CreateTeam(1, "The Team")
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, team.TeamId > 0, "no id set")
	rdtest.Assert(t, team.Name == "The Team", "wrong team name")
	rdtest.Assert(t, team.TrackId == 1, "wrong track id")
}
Пример #19
0
func TestCurrentClueForTeam_ClueDisabled(t *testing.T) {
	beforeCurrentTest()

	log.Println("before")
	clue, err := clues.CurrentForTeam(1, 2)

	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, clue.ClueId == 3)
	rdtest.Assert(t, clue.AdvancementReason == clues.DisabledAdvancement, "Actual (%s)", clue.AdvancementReason)
}
Пример #20
0
func TestGetTrackIdForTelephone(t *T) {
	beforeTrackTest()
	trackId, err := table.GetTrackForTelephone("1231231234")
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, trackId == 1, err)

	trackId, err = table.GetTrackForTelephone("3213213214")
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, trackId == 1, err)
}
Пример #21
0
func TestFindAllTracks(t *T) {
	beforeTrackTest()

	tracks, err := table.FindAllTracks()
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, len(tracks) == 3, "3 != %d", len(tracks))
	rdtest.Assert(t, tracks[0].TrackId == 1)
	rdtest.Assert(t, tracks[1].TrackId == 2)
	rdtest.Assert(t, tracks[2].TrackId == 3)
}
Пример #22
0
func TestFindTrack(t *T) {
	beforeTrackTest()

	track, err := table.FindTrack(1)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, len(track.QuestionIdOrder) == 3, len(track.QuestionIdOrder))
	rdtest.Assert(t, track.QuestionIdOrder[0] == 1, track)
	rdtest.Assert(t, track.QuestionIdOrder[1] == 2, track)
	rdtest.Assert(t, track.QuestionIdOrder[2] == 3, track)
}
Пример #23
0
func TestFindCurrentClues(t *testing.T) {
	beforeClueTest()

	clues, err := biz.FindCurrentClues(clueTestNow)

	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, len(clues) == 4)
	rdtest.Assert(t, clues[0].ClueId == 1)
	rdtest.Assert(t, clues[1].ClueId == 2)
}
Пример #24
0
func TestUpdateTeamStartTime(t *T) {
	beforeTeamTest()
	startTime := time.Date(2016, 7, 2, 7, 7, 0, 0, time.UTC)
	err := table.UpdateTeamStartTime(100, startTime)
	rdtest.Assert(t, err == nil, err)
	team, err := table.FindTeam(100)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, team.StartTime.Valid)
	rdtest.Assert(t, team.StartTime.Time.Equal(startTime), team.StartTime)
}
Пример #25
0
func TestAnswerCorrectVariation(t *testing.T) {
	beforeAnswerTest()

	err := clues.Answer(1, 1, "   1ba   ")
	rdtest.Assert(t, err == nil, err)

	p, err := table.FindClueWithProgressForTeam(1)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, p.Clue.ClueId == 2)
}
Пример #26
0
func TestFindAllProgresses(t *T) {
	beforeTeamProgressTest()

	now := time.Date(2016, 06, 15, 0, 0, 0, 0, time.UTC)
	summaries, err := table.FindAllProgressSummaries(now)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, len(summaries) == 3, "Summaries: %d", len(summaries))
	rdtest.Assert(t, summaries[0].Team.TeamId == 20)
	rdtest.Assert(t, summaries[1].Team.TeamId == 21)
	rdtest.Assert(t, summaries[2].Team.TeamId == 22)
}
Пример #27
0
func TestFinishProgressForClueTeam(t *T) {
	beforeTeamProgressTest()

	now := time.Now()

	err := table.FinishProgressForClueTeam(now, 1, 1)
	rdtest.Assert(t, err == nil, err)

	p, err := table.FindProgressByClueTeam(1, 1)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(
		t,
		int64(math.Abs(float64(p.AnswerTime.Time.Unix()-now.Unix()))) <= 1,
		"%d != %d", p.AnswerTime.Time.Unix(), now.Unix())
}
Пример #28
0
func TestFindWithCurrentClueForTeam(t *T) {
	beforeTeamProgressTest()

	currentClue, err := table.FindClueWithProgressForTeam(20)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, currentClue.Clue.ClueId == 3, "ClueId: %d", currentClue.Clue.ClueId)
	rdtest.Assert(t, currentClue.TeamId == 20, "TeamId: %d", currentClue.TeamId)
	rdtest.Assert(t, currentClue.HintCnt == 1, "Hint Count: %d", currentClue.HintCnt)
	rdtest.Assert(t, currentClue.HintCnt == 1, "Hint Count: %d", currentClue.HintCnt)
	rdtest.Assert(t, currentClue.Clue.HintOne == "hint 3")
	rdtest.Assert(t, currentClue.Clue.HintTwo == "hint b3")
}
Пример #29
0
func TestCurrentClueForTeam_NoMoreHints(t *testing.T) {
	beforeCurrentTest()

	clue, err := clues.CurrentForTeam(2, 1)

	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, clue.ClueId == 1)
	rdtest.Assert(t, len(clue.Hints) == 2, "Actual (%d)", len(clue.Hints))
	rdtest.Assert(t, clue.Hints[0] == "Hint 1A")
	rdtest.Assert(t, clue.Hints[1] == "Hint 1B")
	rdtest.Assert(t, !clue.MoreHintsExist)
}
Пример #30
0
func TestPipeSeparatedList(t *T) {
	p := new(record.PipeSeparatedList)
	err := p.Scan("1|2|3")
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, (*p)[0] == 1)
	rdtest.Assert(t, (*p)[1] == 2)
	rdtest.Assert(t, (*p)[2] == 3)

	val, err := p.Value()
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, val == "1|2|3")
}