Esempio n. 1
0
func TestDeactivateActivate(t *T) {
	beforeTrackTest()

	now := time.Date(1986, 7, 2, 0, 0, 0, 0, time.UTC)

	err := table.DeactivateTrack(3, now)
	rdtest.Assert(t, err == nil, err)

	found, err := table.FindTrack(3)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, !found.Active(now))

	err = table.ActivateTrack(3, now)
	rdtest.Assert(t, err == nil, err)

	found, err = table.FindTrack(3)
	rdtest.Assert(t, err == nil, err)
	rdtest.Assert(t, found.Active(now))
}
Esempio n. 2
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)
}
Esempio n. 3
0
func toggleTrackActivation(ctx *_Context) error {

	track, err := table.FindTrack(ctx.urlParams["track_id"].(int64))
	if err != nil {
		return err
	}

	now := time.Now()

	if track.Active(now) {
		err = table.DeactivateTrack(track.TrackId, now)
	} else {
		err = table.ActivateTrack(track.TrackId, now)
	}

	return err
}
Esempio n. 4
0
//advances the team to the next clue
func advanceProgress(c *record.Clue, t *record.Team) error {

	//mark progress as answered
	table.FinishProgressForClueTeam(time.Now(), c.ClueId, t.TeamId)

	//get next clue in track
	track, err := table.FindTrack(t.TrackId)
	if err != nil {
		return err
	}

	//get next clue id
	nextClueId, err := track.NextClue(c.ClueId)
	if err != nil {
		return err
	}

	//create new progress for the next clue id
	return table.StartProgress(nextClueId, t.TeamId)
}
Esempio n. 5
0
//Start progress on a track for a team
func startTrackForTeam(team *record.Team) (*models.Clue, error) {

	track, err := table.FindTrack(team.TrackId)
	if err != nil {
		return nil, err
	}

	//find the clue
	clue, err := table.FindClue(track.QuestionIdOrder[0])
	if err != nil {
		return nil, err
	}

	_, err = table.CreateTeamProgress(team.TeamId, clue.ClueId)
	if err != nil {
		return nil, err
	}

	return models.ClueFromCurrentClue(clue), nil
}