Exemple #1
0
func TestGetFirstNonExpiredChallenge(t *testing.T) {
	dao := dao.NewLobbyDAO()
	api := NewLobbyAPI(dao)

	challenger := util.UUID()
	challenged := util.UUID()

	api.JoinPlayer(challenger)
	api.JoinPlayer(challenged)

	var firstOne *model.Challenge
	{
		challenge := model.NewChallenge()
		challenge.ChallengeID = util.UUID()
		challenge.ChallengerPlayer = challenger
		challenge.ChallengedPlayer = challenged
		challenge.ChallengeTs = 100

		dao.CreateChallenge(challenge)

	}
	{
		challenge := model.NewChallenge()
		challenge.ChallengeID = util.UUID()
		challenge.ChallengerPlayer = challenger
		challenge.ChallengedPlayer = challenged
		challenge.ChallengeTs = util.Now()

		dao.CreateChallenge(challenge)
		firstOne = challenge
	}
	{
		challenge := model.NewChallenge()
		challenge.ChallengeID = util.UUID()
		challenge.ChallengerPlayer = challenger
		challenge.ChallengedPlayer = challenged
		challenge.ChallengeTs = util.Now()

		dao.CreateChallenge(challenge)

	}
	{
		challenge := model.NewChallenge()
		challenge.ChallengeID = util.UUID()
		challenge.ChallengerPlayer = challenger
		challenge.ChallengedPlayer = challenged
		challenge.ChallengeTs = 100

		dao.CreateChallenge(challenge)
	}

	resolvedChallenge, failure := api.GetChallengeFor(challenged)

	assert.NotNil(t, resolvedChallenge)
	assert.Nil(t, failure)
	assert.Equal(t, firstOne.ChallengeID, resolvedChallenge.ChallengeID)
}
Exemple #2
0
func TestGetExpiredChallenge(t *testing.T) {
	dao := dao.NewLobbyDAO()
	api := NewLobbyAPI(dao)

	challenger := util.UUID()
	challenged := util.UUID()

	api.JoinPlayer(challenger)
	api.JoinPlayer(challenged)

	challenge := model.NewChallenge()
	challenge.ChallengeID = util.UUID()
	challenge.ChallengerPlayer = challenger
	challenge.ChallengedPlayer = challenged
	challenge.ChallengeTs = 100

	dao.CreateChallenge(challenge)

	resolvedChallenge, failure := api.GetChallengeFor(challenged)
	assert.Nil(t, failure)
	assert.Nil(t, resolvedChallenge)
}